HTML Make a three section Content box - html

I am trying to make a box with a header and two vertical lines in the content section to make box with three sections. I am still a beginner in HTML and have accomplished making the box but cannot figure out how to make the vertical lines. This is what I am trying to make:
All I need to make the two vertical lines inside the box and fill each of the three sections with content. If anyone could help me out or show the right direction I would appreciate it. Sorry for the horrible photo I had to remove some stuff from the screenshot.

This works:
#container{
width:100%;
height:100px;
border:1px solid black;
}
#header{
width:100%;
background:grey;
height:20px;
}
.fourth{
width:25%;
height:100px;
float:left;
}
.half{
width:50%;
height:100px;
border-left:1px solid grey;
border-right:1px solid grey;
float:left;
}
<div id="container">
<div id="header"><div>
<div class="fourth"></div>
<div class="half"></div>
<div class="fourth"></div>
</div>

See the following Pen: http://codepen.io/rkieru/pen/JKyYpx
.line-navbar li {
display: inline-block;
border-right: 1px solid #ccc;
margin: 5px 0;
}
.line-navbar li:last-of-type {
border-right: none;
}
It is an example of a navigational menu with a similar vertical line treatment, but the CSS should apply easily to your content box design. The only caveat would be ensuring that they are applied to the box with the greatest height, or otherwise ensuring that the content boxes are all the same height.

Don't listen to people telling you to use a table. You can do this with flexbox. Here's an example:
.header {
background-color: LightGrey;
}
.column-container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.column {
padding: 10px;
border-left: 1px solid black;
}
.column:first-child {
border-left: none;
}
<div class="header">
This is header text.
</div>
<div class="column-container">
<div class="column">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ornare, sem sit amet ornare consequat, nunc turpis accumsan urna, ac hendrerit orci sapien eu purus. Proin blandit finibus eros, ut egestas urna aliquam eget. Integer hendrerit metus sed ligula lobortis, et scelerisque libero congue. Nunc facilisis tincidunt dictum. Nam aliquet ullamcorper nisl, ac congue leo pellentesque eget. Vestibulum dui massa, pretium at ex id, aliquet mattis ligula. Aenean ut porta elit. Donec pulvinar a augue non bibendum. Morbi pellentesque erat ut leo tincidunt condimentum.
</div>
<div class="column">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ornare, sem sit amet ornare consequat, nunc turpis accumsan urna, ac hendrerit orci sapien eu purus. Proin blandit finibus eros, ut egestas urna aliquam eget. Integer hendrerit metus sed ligula lobortis, et scelerisque libero congue. Nunc facilisis tincidunt dictum. Nam aliquet ullamcorper nisl, ac congue leo pellentesque eget. Vestibulum dui massa, pretium at ex id, aliquet mattis ligula. Aenean ut porta elit. Donec pulvinar a augue non bibendum. Morbi pellentesque erat ut leo tincidunt condimentum.
</div>
<div class="column">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ornare, sem sit amet ornare consequat, nunc turpis accumsan urna, ac hendrerit orci sapien eu purus. Proin blandit finibus eros, ut egestas urna aliquam eget. Integer hendrerit metus sed ligula lobortis, et scelerisque libero congue. Nunc facilisis tincidunt dictum. Nam aliquet ullamcorper nisl, ac congue leo pellentesque eget. Vestibulum dui massa, pretium at ex id, aliquet mattis ligula. Aenean ut porta elit. Donec pulvinar a augue non bibendum. Morbi pellentesque erat ut leo tincidunt condimentum.
</div>
</div>

By the picture I think what you are looking for is HTML Table.
Example:
<table border="1" width="100%">
<tr>
<th colspan="3">Headline</th>
</tr>
<tr>
<td>Content...</td>
<td>Content...</td>
<td>Content...</td>
</tr>
</table>
You can use CSS to style the box.
PD: Next time show some code, this way we can have a better understanding of what you are trying to do.

Related

Prevent text from expanding wrapper [duplicate]

This question already has answers here:
Make wrapper take maximum width of child image? [duplicate]
(2 answers)
Closed 4 years ago.
I have a DIV-wrapper (centered) that contain a picture and a paragraph:
What I want to do is to make the width of the wrapper flexible, so that it can fit the width of the picture. I have achieved this with display:table; (I also tried inline-block, and also width:fit-content; [the last of which oddly enough didn't work]).
The text also fits perfectly in there, but...! As soon as the text becomes longer than the width of the picture, the wrapper expands to fit the text rather than fitting the picture (and breaking the text).
Is there any solution to this problem?
.image_wrapper {
display:table;
margin:25px auto 25px auto; /* centering wrapper on page */
text-align:center;
border: 1px solid red;
}
.image_wrapper img {
height: auto;
max-width:99%;
border: 3px solid #31558e;
}
.image_wrapper p {
color:#84bddb;
font-size: 13.3px;
line-height: 15px;
text-align: left;
margin-left:0px;
}
<div class="image_wrapper">
<img src="pic.jpg">
<br>
<p>Some text</p>
</div>
.wrapper {
border: 1px solid red;
display: table;
width: 1%;
margin: 0 auto;
}
.caption {
text-align: center;
}
<div class="wrapper">
<img src="http://via.placeholder.com/200/300">
<p class="caption">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ornare dictum ligula quis dictum. Nam dictum, eros sit amet imperdiet aliquet, ligula nisl blandit lectus, quis malesuada nunc ipsum ac magna. Vestibulum in magna eu sem suscipit molestie.
Maecenas a ligula molestie, volutpat turpis et, venenatis massa. Nam aliquam auctor lectus ac lacinia. Nam consequat lacus porta odio hendrerit mollis. Etiam at congue est, eu fermentum erat. Praesent vestibulum malesuada ante. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
</div>
You can take the approach without jQuery using the figure/figcaption combination BUT, this only works if you have one figure/figcaption element on the page.
Set the height of the figure to be 100% and set the width of the fig caption to be the width of your image. This will contain all your text in the figure element and allow the height to expand to the length of your text.
figure {
display: table;
margin: 25px auto 25px auto;
/* centering wrapper on page */
text-align: center;
border: 1px solid red;
height: 100%;
}
figcaption {
color: #84bddb;
font-size: 13.3px;
line-height: 15px;
text-align: left;
margin-left: 0px;
width: 100px;
}
<figure>
<img src="http://via.placeholder.com/100x150" width="100">
<br>
<figcaption>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut nulla consequat, ullamcorper erat vitae, dictum leo. Phasellus semper, ante eget semper eleifend, tortor tortor facilisis quam, vitae convallis neque nunc non justo. Maecenas rhoncus
ligula id velit consectetur, sed malesuada tellus pharetra. Nulla ac dolor at ex sodales tincidunt vitae gravida turpis. Etiam erat nunc, aliquet a ullamcorper eget, commodo et orci. In id urna sagittis ante viverra venenatis. Ut laoreet ligula vel
orci placerat, at fringilla odio euismod. Etiam euismod eget ligula at dapibus. Sed vel bibendum nibh.</figcaption>
</figure>
I would suggest using some jQuery to take care of calculating the width as well as the case of multiple div's with images of different sizes.
$(document).ready(function() {
$(".image_wrapper img").each(function(index, value) {
var width = $(this).width();
$(this).parent().children(".image_wrapper > p").css("width", width);
})
});
.image_wrapper {
display:table;
margin:25px auto 25px auto; /* centering wrapper on page */
text-align:center;
border: 1px solid red;
}
.image_wrapper img {
height: auto;
max-width:99%;
border: 3px solid #31558e;
}
.image_wrapper p {
color:#84bddb;
font-size: 13.3px;
line-height: 15px;
text-align: left;
margin-left:0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image_wrapper">
<img src="http://via.placeholder.com/100x150">
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut nulla consequat, ullamcorper erat vitae, dictum leo. Phasellus semper, ante eget semper eleifend, tortor tortor facilisis quam, vitae convallis neque nunc non justo. Maecenas rhoncus
ligula id velit consectetur, sed malesuada tellus pharetra. Nulla ac dolor at ex sodales tincidunt vitae gravida turpis. Etiam erat nunc, aliquet a ullamcorper eget, commodo et orci. In id urna sagittis ante viverra venenatis. Ut laoreet ligula vel
orci placerat, at fringilla odio euismod. Etiam euismod eget ligula at dapibus. Sed vel bibendum nibh.</p>
</div>
<div class="image_wrapper">
<img src="http://via.placeholder.com/150x150">
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut nulla consequat, ullamcorper erat vitae, dictum leo. Phasellus semper, ante eget semper eleifend, tortor tortor facilisis quam, vitae convallis neque nunc non justo. Maecenas rhoncus
ligula id velit consectetur, sed malesuada tellus pharetra. Nulla ac dolor at ex sodales tincidunt vitae gravida turpis. Etiam erat nunc, aliquet a ullamcorper eget, commodo et orci. In id urna sagittis ante viverra venenatis. Ut laoreet ligula vel
orci placerat, at fringilla odio euismod. Etiam euismod eget ligula at dapibus. Sed vel bibendum nibh.</p>
</div>
Also, you don't need to write custom div's with classes if you use the figure/figcaption combintation.
$(document).ready(function() {
$(".myFigure img").each(function(index, value) {
var width = $(this).width();
$(this).parent().children(".myFigure > .myCaption").css("width", width);
})
});
figure {
display: table;
margin: 25px auto 25px auto;
/* centering wrapper on page */
text-align: center;
border: 1px solid red;
height: 100%;
}
figcaption {
color: #84bddb;
font-size: 13.3px;
line-height: 15px;
text-align: left;
margin-left: 0px;
/*width: 100px;*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<figure class="myFigure">
<img src="http://via.placeholder.com/100x150" width="100">
<br>
<figcaption class="myCaption">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut nulla consequat, ullamcorper erat vitae, dictum leo. Phasellus semper, ante eget semper eleifend, tortor tortor facilisis quam, vitae convallis neque nunc non justo. Maecenas rhoncus
ligula id velit consectetur, sed malesuada tellus pharetra. Nulla ac dolor at ex sodales tincidunt vitae gravida turpis. Etiam erat nunc, aliquet a ullamcorper eget, commodo et orci. In id urna sagittis ante viverra venenatis. Ut laoreet ligula vel
orci placerat, at fringilla odio euismod. Etiam euismod eget ligula at dapibus. Sed vel bibendum nibh.</figcaption>
</figure>
<figure class="myFigure">
<img src="http://via.placeholder.com/150x150">
<br>
<figcaption class="myCaption">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ut nulla consequat, ullamcorper erat vitae, dictum leo. Phasellus semper, ante eget semper eleifend, tortor tortor facilisis quam, vitae convallis neque nunc non justo. Maecenas rhoncus
ligula id velit consectetur, sed malesuada tellus pharetra. Nulla ac dolor at ex sodales tincidunt vitae gravida turpis. Etiam erat nunc, aliquet a ullamcorper eget, commodo et orci. In id urna sagittis ante viverra venenatis. Ut laoreet ligula vel
orci placerat, at fringilla odio euismod. Etiam euismod eget ligula at dapibus. Sed vel bibendum nibh.</figcaption>
</figure>

Pre code blocks stretch the content beyond screen width in a centered flex container

Here's a simple flex based blog layout:
<div class='Page'>
<div class='Container'>
<div class='Content'>
<h1>Hello</h1>
<p>Cras ac mauris purus. Phasellus at ligula condimentum, pretium nisi eget, aliquet enim. Sed at massa velit. Cras ac mi dolor. Nullam id felis sit amet neque tempus sodales. In ultricies et turpis in faucibus. Morbi fringilla metus pellentesque, varius enim a, dapibus ex. Sed aliquet urna nisi, eu fermentum diam pretium quis. Curabitur vel cursus turpis. Sed a varius leo, in viverra arcu. Donec porttitor, dolor vel laoreet iaculis, magna arcu tempus ex, at porttitor tellus nunc ultricies felis. Quisque congue sapien in quam tempor, non dapibus felis dignissim. Pellentesque ex eros, dignissim eget tortor non, aliquet ullamcorper nisi. Sed interdum non eros quis fringilla. Morbi condimentum tellus at blandit dignissim. Aenean metus elit, interdum et suscipit quis, ullamcorper sit amet risus.</p>
<pre>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sapien magna, lacinia sit amet quam sed, dignissim tincidunt neque. Duis sed sapien hendrerit, consectetur neque quis, tempor nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent fringilla enim odio, sit amet venenatis ex commodo in. Pellentesque in enim in libero vulputate fermentum. Suspendisse elementum felis neque, in rhoncus diam hendrerit eget. Cras tempor porta bibendum. Fusce eget tellus a enim euismod lobortis in vitae nibh. Duis ornare turpis non ex consectetur, sit amet malesuada elit feugiat.</pre>
</div>
</div>
</div>
With this CSS
.Page {
border: 1px solid blue;
}
.Container {
display: flex;
flex-direction: column;
align-items: center;
}
.Content {
border: 1px solid red;
padding: 10px;
max-width: 700px;
min-width: 0;
}
pre {
overflow: auto;
background: #f2f2f2;
border: 1px solid #ccc;
border-radius: 4px;
padding: 20px;
}
Working example: https://codepen.io/anon/pen/xdeyrY
When the browser width is >700px, the red Container is centered and the pre code block has an overflow scrollbar. But as soon as you resize the browser < 700px, the pre code block stretches the container to the full 700px and the content gets cut off.
Why is the width of the container not limited by the browser/screen width in this case?
If you remove align-items: center; everything works as expected. If you set white-space: normal on pre, it also works as expected. But neither of those is an option.
The only workaround I came up with is to add this media query:
#media only screen and (max-width: 700px) {
.Container {
align-items: initial;
}
}
This does the trick, but seems a bit like a hack. Is this some flexbox bug/edge case, or am I missing some min-width: 0 trick here? It seems like using flex + align-items:center + max-width + pre just doesn't work well together..
In addition to Michael_B's answer, if you need the flex column direction for i.e. multiple .Content elements, you can also simply set width: 100% on the .Content.
To adjust the width to your padding/border you can either use box-sizing: border-box;, which I did, or CSS Calc (width: calc(100% - 22px);)
Also, for the reason Michael gave, I removed the min-width: 0 as it has no effect
Updated codepen
Stack snippet
.Page {
border: 1px solid blue;
}
.Container {
display: flex;
flex-direction: column;
align-items: center;
}
.Content {
border: 1px solid red;
padding: 10px;
max-width: 700px;
width: 100%;
box-sizing: border-box;
}
pre {
overflow: auto;
background: #f2f2f2;
border: 1px solid #ccc;
border-radius: 4px;
padding: 20px;
}
<div class='Page'>
<div class='Container'>
<div class='Content'>
<h1>Hello</h1>
<p>Cras ac mauris purus. Phasellus at ligula condimentum, pretium nisi eget, aliquet enim. Sed at massa velit. Cras ac mi dolor. Nullam id felis sit amet neque tempus sodales. In ultricies et turpis in faucibus. Morbi fringilla metus pellentesque, varius enim a, dapibus ex. Sed aliquet urna nisi, eu fermentum diam pretium quis. Curabitur vel cursus turpis. Sed a varius leo, in viverra arcu. Donec porttitor, dolor vel laoreet iaculis, magna arcu tempus ex, at porttitor tellus nunc ultricies felis. Quisque congue sapien in quam tempor, non dapibus felis dignissim. Pellentesque ex eros, dignissim eget tortor non, aliquet ullamcorper nisi. Sed interdum non eros quis fringilla. Morbi condimentum tellus at blandit dignissim. Aenean metus elit, interdum et suscipit quis, ullamcorper sit amet risus.</p>
<pre>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse sapien magna, lacinia sit amet quam sed, dignissim tincidunt neque. Duis sed sapien hendrerit, consectetur neque quis, tempor nisl. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent fringilla enim odio, sit amet venenatis ex commodo in. Pellentesque in enim in libero vulputate fermentum. Suspendisse elementum felis neque, in rhoncus diam hendrerit eget. Cras tempor porta bibendum. Fusce eget tellus a enim euismod lobortis in vitae nibh. Duis ornare turpis non ex consectetur, sit amet malesuada elit feugiat.</pre>
</div>
</div>
</div>
It is indeed a min-width: 0 problem.
It's applied in your code, but the set-up is not quite right.
The min-width and min-height overrides work only in the direction of the main axis.
This means that the min-width: 0 override works only in flex-direction: row.
Similarly, the min-height: 0 fix applies only in flex-direction: column.
Your flex container is flex-direction: column. Your flex item has min-width: 0. Therefore, the override is having no effect.
Switch your container to row-direction. Since you're not applying flex properties to the content of the flex item, the switch won't change anything, except allow your <pre> tag to shrink.
You will also need to switch align-items: center to justify-content: center.
revised demo
More details here: Why doesn't flex item shrink past content size?

CSS markup to have one fixed div with a scrollable adjacent div

I have some basic markup like this:
<body>
<div id="static-container">
<p id="do-not-move">Example.</p>
</div>
<div id="scroll-container"></div>
</body>
Basically, I want the static-container to remain fixed, and never move. The scroll-container will have content added to it and will be scrollable, but it should always be physically below the static-container, and scrolling should never overlap into static-container, I can put position: fixed in the static-container but the scroll-container still manages to scroll into it.
body,html {height:100vh;}
body {
display: flex;
flex-direction: column;
margin: 0;
}
#static-container {
background: black;
color: white;
}
#scroll-container {
flex-grow: 1;
overflow-y: scroll;
}
<div id="static-container">
<p id="do-not-move">Example.</p>
</div>
<div id="scroll-container"><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p><p>foo</p></div>
Make the static-container div position fixed and some height.
Give some height to scroll-div and scroll-y: scroll
HTML:
<div id="static-container">
<p id="do-not-move">Example.</p>
</div>
<div id="scroll-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ut ipsum rutrum, commodo felis ac, mattis justo. Vivamus feugiat urna ac est efficitur blandit. Maecenas vestibulum turpis ante, nec pharetra enim rutrum vitae. Fusce pharetra felis fringilla tincidunt porta. Praesent porttitor posuere erat eu viverra.
</p>
<p>
Aliquam lacus nisl, dictum non ultricies eget, malesuada et nisi. Maecenas felis turpis, blandit at leo id, efficitur pellentesque velit. Morbi sapien augue, sagittis eget dictum a, bibendum ut dui. Morbi vulputate tempor tortor, id blandit lorem vulputate id. In blandit nibh sit amet ante vestibulum volutpat.
</p>
<p>
Nam quis nisi magna. Sed lacinia id quam eget gravida. Donec vitae luctus leo. Sed efficitur sapien eu elit tincidunt, eu vehicula felis rutrum. Interdum et malesuada fames ac ante ipsum primis in faucibus.
</p>
</div>
CSS:
#static-container{background-color:#333;color:#FFF;height:30px; padding:10px 0; postion:fixed; top:0; text-align:center; width:500px}
#scroll-container{background-color:#ccc;height:200px; position:relative; overflow-y:scroll; padding:0 10px; width:480px}
JS Fiddle

float:right with correct semantics

I have the following html/css:
#wrapper {
width: 400px;
background-color: red;
}
#text {
margin-right: 50px;
}
#subcontent {
float: right;
width: 50px;
}
<div id="wrapper">
<div id="subcontent">
<img src="http://lorempicsum.com/futurama/50/50/1" width="50">
</div>
<div id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis leo sapien. Nunc convallis elit purus, non fringilla quam lobortis at. Integer pharetra auctor luctus. In congue dolor a pretium facilisis. Donec et risus lacinia augue pellentesque mollis
eget a urna. Sed dapibus est enim, id iaculis arcu ultrices sit amet. Donec quis dolor risus. Suspendisse a nunc a enim mattis finibus eget vitae diam. Phasellus dictum commodo metus, ut rutrum dolor pretium a. Aliquam at sem vel tortor mollis tristique.
Proin neque dolor, pellentesque ut euismod id, finibus sed lacus. Mauris varius tempor diam, at varius risus. Etiam dictum metus et augue bibendum commodo. Vestibulum imperdiet elit vitae bibendum finibus. Maecenas mollis dui ex, id suscipit mauris
cursus vitae. Vivamus nec faucibus elit.</div>
</div>
This is achieving the desired effect of making the text stay left and the sub content stay right, without having to specify a width for the text (for responsive behaviour). However, semantically this is incorrect as I have had to place <div id="subcontent"/> before <div id="text"/> in the html, even though the text should appear before the sub content (assuming reading rtl). I can live with this to get the job done but unfortunately when the screen size is very small I need to make <div id="text"/> full width and let the sub content flow naturally afterwards. This currently means the sub content is at the top and I need it to be at the bottom.
How can I change the css so that when the html is ordered
<div id="text"/>
<div id="subcontent"/>
the sub content will float right without being pushed down by the text?
I need to support IE9+
Float is a pain.
Try to use flex and media queries for a responsive design :
Note: since you mention rtl reading, I strongly advise you to have a look on the flex-direction property (MDN)
#wrapper {
display: flex;
width: 400px;
background-color: red;
/* this is the default behavior - you can skip it */
flex-direction: row;
}
#text {
}
#subcontent {
width: 50px;
}
#media (max-width: 400px) {
#wrapper {
flex-direction: column;
}
}
<div id="wrapper">
<div id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis leo sapien. Nunc convallis elit purus, non fringilla quam lobortis at. Integer pharetra auctor luctus. In congue dolor a pretium facilisis. Donec et risus lacinia augue pellentesque mollis
eget a urna. Sed dapibus est enim, id iaculis arcu ultrices sit amet. Donec quis dolor risus. Suspendisse a nunc a enim mattis finibus eget vitae diam. Phasellus dictum commodo metus, ut rutrum dolor pretium a. Aliquam at sem vel tortor mollis tristique.
Proin neque dolor, pellentesque ut euismod id, finibus sed lacus. Mauris varius tempor diam, at varius risus. Etiam dictum metus et augue bibendum commodo. Vestibulum imperdiet elit vitae bibendum finibus. Maecenas mollis dui ex, id suscipit mauris
cursus vitae. Vivamus nec faucibus elit.</div>
<div id="subcontent">
<img src="http://lorempicsum.com/futurama/50/50/1" width="50">
</div>
</div>
Something like this?
#wrapper {
width: 400px;
background-color: red;
position: relative;
}
#text {
margin-right: 50px;
}
#subcontent {
position: absolute;
top: 0;
right: 0;
width: 50px;
}
<div id="wrapper">
<div id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis leo sapien. Nunc convallis elit purus, non fringilla quam lobortis at. Integer pharetra auctor luctus. In congue dolor a pretium facilisis. Donec et risus lacinia augue pellentesque mollis
eget a urna. Sed dapibus est enim, id iaculis arcu ultrices sit amet. Donec quis dolor risus. Suspendisse a nunc a enim mattis finibus eget vitae diam. Phasellus dictum commodo metus, ut rutrum dolor pretium a. Aliquam at sem vel tortor mollis tristique.
Proin neque dolor, pellentesque ut euismod id, finibus sed lacus. Mauris varius tempor diam, at varius risus. Etiam dictum metus et augue bibendum commodo. Vestibulum imperdiet elit vitae bibendum finibus. Maecenas mollis dui ex, id suscipit mauris
cursus vitae. Vivamus nec faucibus elit.</div>
<div id="subcontent">
<img src="http://moviesalbum.com/wp-content/themes/sunny/timthumb.php?src=http://moviesalbum.com/wp-content/uploads/2013/05/Koala-300x225.jpg&h=120&w=120&zc=1&q=90" width="50">
</div>
</div>
Cool. If I understand your question correctly, you are trying to change the order of the HTML, yet have the output still look the same?
If this is the case, you need to give #text AND #subcontent a float:left; add a clearing div and use a calc width on your text to make sure that the image will always fit in whilst the text can be responsively sized.
Here's a fiddle: https://jsfiddle.net/hk9ntyd2/1/
And here's the code:
#wrapper {
width: 400px;
background-color: red;
}
#text {
width: calc(100% - 50px);
float: left;
}
.clear {
clear: both;
}
#subcontent {
float: left;
width: 50px;
}
<div id="wrapper">
<div id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. In quis leo sapien. Nunc convallis elit purus, non fringilla quam lobortis at. Integer pharetra auctor luctus. In congue dolor a pretium facilisis. Donec et risus lacinia augue pellentesque mollis
eget a urna. Sed dapibus est enim, id iaculis arcu ultrices sit amet. Donec quis dolor risus. Suspendisse a nunc a enim mattis finibus eget vitae diam. Phasellus dictum commodo metus, ut rutrum dolor pretium a. Aliquam at sem vel tortor mollis tristique.
Proin neque dolor, pellentesque ut euismod id, finibus sed lacus. Mauris varius tempor diam, at varius risus. Etiam dictum metus et augue bibendum commodo. Vestibulum imperdiet elit vitae bibendum finibus. Maecenas mollis dui ex, id suscipit mauris
cursus vitae. Vivamus nec faucibus elit.</div>
<div id="subcontent">
<img src="http://moviesalbum.com/wp-content/themes/sunny/timthumb.php?src=http://moviesalbum.com/wp-content/uploads/2013/05/Koala-300x225.jpg&h=120&w=120&zc=1&q=90" width="50">
</div>
<div class="clear"></div>
</div>
The margin-left:50px; solution should have worked fine, I personally find that the calc solution is a little neater, but feel free to use margin instead :)

CSS: Don't display child element if it doesn't completely fit in container

I have mocked up a simple version of the problem here:
.container {
width: 200px;
height: 400px;
background-color: salmon;
overflow: hidden;
}
.item {
padding: 20px;
border: 1px solid black;
}
<div class="container">
<div class="item">Headline</div>
<div class="item">Subheading</div>
<div class="item">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec hendrerit gravida pulvinar. Donec porttitor congue sapien. Quisque euismod eleifend tortor. Etiam ultrices vitae lectus nec pellentesque. Nunc aliquam fringilla est, ac euismod ante mollis vel. Suspendisse eget lorem ut sem laoreet semper sed eget leo. Aliquam sagittis in est a eleifend. Nunc at justo non metus fermentum vestibulum in rutrum dolor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur convallis, sapien in pharetra imperdiet, nisi quam posuere justo, a condimentum nisi tellus ac arcu. Mauris eu felis mi. In aliquet blandit euismod. Praesent quam quam, ultrices vel ipsum viverra, fringilla vehicula urna.</div>
</div>
Basically I want the third child not to display if it doesn't completely fit inside the parent container.
I've tried using inline-blocks but it doesn't seem to wrap.
I'd rather not use JavaScript to sort this but all suggestions welcomed.
As you said all suggestions are welcome, i have a jquery solution: FIDDLE
$(function(){
var x= 400-parseInt( $('.item').first().height()+$('.item').first().next().height());
if($('.item').last().height()>x)
{
$('.item').last().hide()
}
})