Reputation: 11
I have to Div. One in right and one in the left of the right Div. The right Div has fixed size (300px). But the left Div has no width and contain some texts. When the text of left Div increase, the width of parent Div of it also increase automatically and finally receive to full screen but the text of it overflowing! I want to break the text to bottom. I don't want to set a fix width for parent Div of it. Also I don't want to use width:calc(100%-300px) for parent Div of text to fix it width. I use white-space:pre-line but it doesn't work! How can I flex the Div that contain text without overflowing the text from it? Thanks. Here is some example codes:
.div-1 {
float: right;
width: 300px;
}
.div-2 {
float: right;
}
<div class='div-1'>
</div>
<div class='div-2'>
<h3>Some text here...</h3>
</div>
Upvotes: 0
Views: 7863
Reputation: 226
You can wrap both divs
into a container and set it's display to flex
. Also, add flex
property to the .div-2
and set it to 1.
.div-1 {
width: 200px;
}
.div-2 {
flex: 1;
}
.container {
display: flex;
width: 100%;
}
<div class="container">
<div class='div-2'>
<h3>Text</h3>
</div>
<div class='div-1'>
</div>
</div>
If you want your content to be floating right, set the container width and float properties accordingly.
Upvotes: 0
Reputation: 8751
you can use white-space CSS style
h3 {
white-space: break-spaces;
}
break-spaces
value is identical to the value of pre-wrap
, except that:
Upvotes: 4
Reputation: 335
you can use br
where u want to end your first line or you can give max-width
to the parent div so it will not be a fixed width.
Upvotes: 0