+ 6
Can't remove the margin
My div is positioned a little right from the left surface, why's this happening and how to avoid this? https://code.sololearn.com/WmIXDsEI5J0u/?ref=app
21 Respostas
+ 9
Maybe it's because of body margin, set margin: 0; in CSS for body selector.
+ 8
Rishi What I usually will do is add the following if I am trying to line everything from the top and left side..
I added this to your #box and it fit in the corner exactly. Not sure if that was what you were seeking.
margin-left:-7px;
margin-top:-7px;
I also just did this and it moved the box all the way to the left as well
body{
margin-left:.37px;
padding:0px; }
+ 6
#box{
width:400px;
height:50px;
background-color:black;
z-index: 1;
}
body{
padding:0px;
margin:0px;
}
+ 5
Ipang yeah it works! I didn't think of it cuz i thought the margin is outside the area, so it must be the padding that's causing this. Can you explain how margin is affecting this?
+ 4
You're right, margin is the outer distance between an element's border and its parent border.
Imagine we have two envelopes, put big envelop on a table, then stack the smaller one on top of the bigger one. The part of bigger envelope that's uncovered is margin in context of the smaller envelop.
(Edit)
In relation to the code, body is the big envelop, and #box is the smaller envelop.
+ 3
Yeah Krishna Singh and Israel Promise it works! Tnx :)
+ 3
Set margin: 0px; in body section inside css file
+ 2
I just added "margin:0px" to your code and I think it removed it...
So add margin:0 after the padding
+ 2
you can reset the margin at the top of your css:
*{
margin: 0;
padding: 0;
}
+ 2
+ 2
Try changing the background margin and padding property vaalues
+ 2
Just change the #box margin to auto and apply box-sizing : border-box; in body
That's easy...
+ 2
Richard Kamski it's okay, thank you for trying to help😊
I already got a lot of answers so I probably know this already.
+ 1
Because your div have width 400 px
Try this:
*{margin:0;
Padding:0;}
#box{width:100%;}
+ 1
Hey, I saw your post, this is the way to do it right
https://code.sololearn.com/WsRGcOtT1TSO/?ref=app
ask any questions!
+ 1
Richard Kamski the code you shared is not loading. I think maybe the there's an error in the link
+ 1
I accidentally deleted the code from my code section
I didn't know that would also delete the code from my comment😂
+ 1
I can redo it if you still want some help