Reputation:
I am trying to display a panel that displays information in a tabular fashion as,
My pluker code is here. Now, i use display:table-row
to put NAME
label and value My Venue
in one place. When i give 50% width to the table-cell
display, it breaks into next line as,
I am able to fix it by making the width as 49% for table-cell
display.
I am curious why does 50%
width break it into a different line, since table
display doesn't have any margin.
Upvotes: 0
Views: 27
Reputation: 832
Use a responsive grid system like this jsfiddle
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF TWO */
.span_2_of_2 {
width: 100%;
}
.span_1_of_2 {
width: 49.2%;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
@media only screen and (max-width: 480px) {
.col {
margin: 1% 0 1% 0%;
}
}
@media only screen and (max-width: 480px) {
.span_2_of_2, .span_1_of_2 { width: 100%; }
}
<div class="section group">
<div class="col span_1_of_2">
My Name
</div>
<div class="col span_1_of_2">
My Venue
</div>
</div>
Upvotes: 0
Reputation: 240649
There's whitespace between the two spans. That whitespace is rendered as a space, the space has a nonzero width. After 50% plus the width of a space, there isn't room for another 50%, so the second span wraps. If you butt the </span><span>
right against each other with no whitespace in between, the wrapping goes away. There are other ways to deal with the problem, including adjusting the font-size to 0 so that the space will have zero width, or using other methods for layout.
Upvotes: 1