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 - 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
-
-
-
-
The vw unit and the classic scrollbar problem4m 41s
-
(Locked)
Consistent sizing with box-sizing: border-box2m 23s
-
(Locked)
Using logical box properties vs. top, right, bottom, left4m 9s
-
(Locked)
Changing writing mode3m 51s
-
(Locked)
Align elements horizontally and vertically in any container4m 32s
-
(Locked)
Centering psuedo-elements with absolute positioning4m 11s
-
(Locked)
Maintaining aspect ratio in containers and images2m 32s
-
(Locked)
Using float and clear in modern CSS2m 27s
-
(Locked)
Wrap text around custom shapes with shape-outside2m 23s
-
-
-
-
-