I'm using the float style to remove white spaces and I want to center it, but another white space appears after my div#bar
This is my html:
<div id="foo">
<div id="bar">
<div class="divo divo1">test1</div>
<div class="divo divo2">test2</div>
<div class="divo divo3">test3</div>
<div class="divo divo4">test4</div>
</div>
</div>
and css:
#foo {
width: 100%;
background: #999;
text-align: center;
}
#bar {
display: inline-block;
}
.divo {
display: block;
float: left;
}
http://jsfiddle.net/Kodam/ay3ywtqa/
Note: I don't want to use negative margin or font-size 0 styles.
Here's the deal: a series of inline-block elements formatted like you normally format HTML will have spaces in between them. We often want the elements to butt up against each other. In the case of navigation, that means it avoids the awkward little unclickable gaps.
The trim() function removes whitespace and other predefined characters from both sides of a string.
A commonly used entity in HTML is the non-breaking space: A non-breaking space is a space that will not break into a new line. Two words separated by a non-breaking space will stick together (not break into a new line). This is handy when breaking the words might be disruptive.
Since #bar is an inline element, it has space reserved for descender text elements (e.g. j, y, g). You could float that left, but that would collapse it, so I'd recommend setting the vertical alignment to top:
#bar {
display: inline-block;
vertical-align:top;
}
jsFiddle example
try this :
#foo {
width: 100%;
background: #999;
font-size:0;
text-align: center;
}
#bar {
display: inline-block;
font-size:13px;
}
set parent font-size to 0, then set the needed font-size to the children.
jsFiddle : http://jsfiddle.net/ay3ywtqa/3/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With