Reputation: 23
I have 2 divs side by side. In each div is another div. i then put my text inside both inner divs. The boxes and text look great in wide screen desktop view, but once you get to 1024 and below, the text starts going outside the divs.
I would like the divs to expand and collapse as needed to contain the text and leave the proper spacing between the border and text. I dont want to use overflow hidden as i need all the text to show.
<style>
.hometext {
box-sizing: border-box;
}
.hometext {
margin: 0;
}
/* Create two equal columns that floats next to each other */
.hometext {
float: left;
width: 50%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
.hometextinner {
border:1px solid #999;
padding-top:10px;
padding-left:20px;
padding-right:20px;
height:100%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */
@media (max-width: 600px) {
.hometext {
width: 100%;
}
.hometextinner {
border:1px solid #999;
padding-top:10px;
padding-left:20px;
padding-right:20px;
height:100%;
}
}
</style>
<body>
<div class="row">
<div class="hometext">
<div class="hometextinner"><h2>Column 1</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p></div>
</div>
<div class="hometext">
<div class="hometextinner"><h2>Column 2</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p></div>
</div>
</div>
</body>
Upvotes: 0
Views: 2458
Reputation:
Use flexbox, if you want equal height.
.row {
display: flex;
}
.row>.hometext {
flex: 1;
padding: 20px;
border: 1px solid;
}
@media screen and (max-width: 600px) {
.row {
flex-direction: column;
}
}
<body>
<div class="row">
<div class="hometext">
<div class="hometextinner">
<h2>Column 1</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from
a line in section 1.10.32.</p>
</div>
</div>
<div class="hometext">
<div class="hometextinner">
<h2>Column 2</h2>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked
up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus
Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from
a line in section 1.10.32.</p>
</div>
</div>
</div>
</body>
Hint
One advantage is that you don't have to deal with float
and clear
.
Upvotes: 3