This is my very first project here and I am happy I did it. I made use of CSS transform property for the first time to center the element. Sincerely, I do not really know why it had that effect. I'd be happy to get some helpful feedback on that. Thank You :)
José Manuel Esperanza
@JoseAngaraAll comments
- @WineshugaSubmitted about 2 years ago@JoseAngaraPosted about 2 years ago
Hi, when you used
left: 50%
you moved#main-container
50% length of<body>
to the right, so it is not centered because all#main-container
is to the right of<body>
.In order to solve that you used
transform: translate(-50%, 0%)
, it moves#main-container
50% of its width to the right, so now half of it is to the left of<body>
and half of it to the right of<body>
To check more about the positioning properties check here: https://developer.mozilla.org/en-US/docs/Web/CSS/position For translate function check here: https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate
Also,
margin: 0 auto
does not work in absolute positioned elements.Marked as helpful0 - @Dhei-vidSubmitted over 2 years ago
◦ Positioning the elements at the center was a bit tasking. ◦ I am not sure I got the positioning spot on. ◦ Is there a better way to position elements?
@JoseAngaraPosted over 2 years agoHi, to align elements you can use Flexbox, in this case you can use
body { display: flex; flex-direction: column; align- items: center; justify-content: center; }
Of couse, there are more ways to do this, like using Grid, flex containers or transformations.
1 - @CodeVeeSubmitted over 2 years ago
- The color under learn more. Need ideas. Thanks
@JoseAngaraPosted over 2 years agoHi, I used the
after
psedo-element for that purpose. This is my code:.text-container__link::after { content: ""; position: absolute; height: 10px; width: 100%; border-radius: 5px; bottom: -2px; left: 0px; z-index: -1; opacity: 0.25; transition: opacity 0.25s ease-in; } .text-container__link:hover::after { opacity: 1; }
I put the background color in a modifier.
Marked as helpful1