html - Probelm with padding within in a div -
i can't figure out: have div centered on screen width of 60%. inside div have 3 more divs float left width of 33% , have gray bg color. divs filled text , 1 image per div. each div should take 1/3 space inside "maindiv". works fine give 3 "contentdivs" padding text gets seperated bit third div wanders below others. want margin around 3 divs there gap between divs. works if give divs width of 31%. shrink browser though, third 1 pops below others again.
how looks now:
how looks width of 33.33%
how can fix this? mean set divs relative width setting size in %. divs should shrink shrink browser window. tried surround divs other divs , messed around margins , paddings wont work.
any appreciated :)
most it’s box model’s fault. paddings, margins , borders can added in different ways. add box-sizing:border-box
container , elements. brings intended do, , width:33.3333%
wil work out expected.
adding margin still breaks item? there’s great thing called calc()
. assumed have margin
of 8px
, that’s few pixels much. calc()
, can subtract additional margin this:
.item{ width:calc(33.3333vw - 8px); }
note there must whitespace around minus. try , include margin.
Comments
Post a Comment