+ 1
Why when I write margin-left:50%; my block does not aligned to center?
I want to align registration form to center, but it doesn't work when i write div{margin-left:50%;}.
3 Respostas
+ 4
margin acts from the top left of the element not from the center of the element. setting it to 50% means that your giving it am offset of 50% from its top left corner.
if you know the height and width of the element then you can do something like this align it to the center of the screen.
position: absolute;
top: 50%;
left: 50%;
margin-left: -half_width;
margin-top: -half_height;
if you want to only horizontally align it to center, you can do this:
(width should not be 100%)
margin: 0 auto;
+ 2
Try this
Form{
Margin: 0 auto;
Width:50%;
}
Hope it helps
+ 2
forget about trying to align that way as it is archaic and error prone
try this
form{
position:relative;
margin:auto;
}
it would also be in your best interest to learn about grid and flexbox. Once learnt your code will never look the same.