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: current state

how looks width of 33.33% enter image description here

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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -