From the course: CSS Toolkit: Tips and Techniques for Layout and Styling

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Centering psuedo-elements with absolute positioning

Centering psuedo-elements with absolute positioning - CSS Tutorial

From the course: CSS Toolkit: Tips and Techniques for Layout and Styling

Centering psuedo-elements with absolute positioning

- [Instructor] You may come across a scenario where you want to add a decorative element to a container, and you want it absolutely positioned either horizontally or vertically or both. You can do this using pseudo-elements, but the solution isn't as simple as you might think. In this instance, I have this gray container and this pink shape. The container itself has a position of relative, and then I'm using this before pseudo-element to absolutely position this shape. In this case, I'm using clip path to create a sort of bookmark looking shape, but you could use an image or some other content here. So I want to center this pink bookmark horizontally along the top of this container. So the first thing, and this is the easy part, we just need to say top is zero, or if we want to use logical properties, we'd say inset block, which is our vertical axis, and start zero. And that does the same thing. So far, so good. Next, I want to attempt to center this on the inline axis. So let me say,…

Contents