Why Cant I Have 2 Iframes Side By Side With Total Width 100%?
Solution 2:
To answer your actual question of why:
Even without the borders, you still have a space between the two iframes. 25% + 75% + four borders + the size of the space is going to be more than 100%, so the second one has to wrap to a new line.
The simplest way to do this nowadays, and the way least likely to wreak havoc or fall apart on you, is to use flexbox, which is a pretty flexible way of stuffing some number of boxes in a row or column:
http://jsfiddle.net/mwg3j17d/10/
<iframe id="top_frame" src=""></iframe>
<div id="middle-row">
<iframe id="left_frame" src=""></iframe>
<iframe id="right_frame" src=""></iframe>
</div>
<iframe id="bottom_frame" src=""></iframe>
iframe {
box-sizing: border-box;
}
#middle-row {
display: flex;
}
Browser support is pretty good, though it's not gonna work on IE6.
Solution 3:
Your iframes have a 2px border on them by default which is not included in the width of the box. You can remove this border with css using border: 0px
, or include it in the width calculation using `box-sizing: border-box;' as Rob Scott mentioned. This will allow you to have their widths add to 100%. can place them side by side, by floating one left.
CSS:
#top_frame {
width: 100%;
}
#left_frame {
float: left;
width: 25%;
}
#right_frame {
width: 75%;
}
#bottom_frame {
width: 100%;
}
iframe {
box-sizing: border-box;
}
Solution 4:
A few changes to your HTML and CSS will allow you to do this by using table display
styles with some divs.
http://jsfiddle.net/mwg3j17d/6/
<body><iframeid="top_frame"src=""></iframe><divclass="cols"><divclass="col-left"><iframeid="left_frame"src=""></iframe></div><divclass="col-right"><iframeid="right_frame"src=""></iframe></div></div><iframeid="bottom_frame"src=""></iframe></body>
#top_frame {
width: 100%;
}
#left_frame {
width: 100%;
}
#right_frame {
width: 100%;
}
#bottom_frame {
width: 100%;
}
.cols {
display: table-row;
}
.col-left, .col-right {
display: table-cell;
}
.col-left {
width: 25%;
}
.col-right {
width: 75%;
}
You could also do it with a table itself.
Post a Comment for "Why Cant I Have 2 Iframes Side By Side With Total Width 100%?"