Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

margin-top affects inner and out elements but margin- left is not affection .why? [duplicate]

Tags:

html

css

If I add margin-top: 50px; to #box then #container is also getting margin-top, but If I add #margin-left: 50px to #box then why isn't #container getting margin-left?

Fiddle

HTML:

<body>
  <div id="container">
    <div id="box">box</div>
  </div>
</body>

CSS:

#container {
    width: 500px;
    height: 500px;
    background-color: gray;
    margin-top: 30px;
    margin-left: 30px;
}
#box {
    width: 100px;
    height: 100px;
    background-color: orange;
    margin-top: 10px;
}
like image 566
user3689427 Avatar asked Jan 23 '26 07:01

user3689427


1 Answers

You can do what you want by adding possition:fixed to the container like here.

like image 111
Florin Pop Avatar answered Jan 25 '26 23:01

Florin Pop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!