I want to display a checkbox, followed by some text that wraps around below itself. The HTML without any CSS looks as follows:
<input type="checkbox" checked="checked" />
<div>Long text description here</div>
I want it to display similar to:
X Long Text
Description
Here
It currently wraps around like this
X Long Text
Description Here
This is easy to do with tables, but I need it to be in CSS for other reasons. I thought a combination of display: inline-block / float: right / clear / spans instead of DIVs would work, but I've had no luck so far.
While using the property display: inline-block will wrap the element to prevent the text inside from extending beyond its parent. Lastly, using the property display: block will put the element on its own line and fill its parent.
The display: inline-block Value Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.
As a result, the elements can sit next to each other. The major difference between display: inline; and display: inline-block; is that, display: inline-block; also allows us to set the width and height of the element. We can prevent inline-block divs from wrapping by adding suitable Bootstrap classes.
break-word: This is the actual CSS syntax that tells the browser to wrap a long text over to a new line. normal: It breaks each word at the normal points of separation within a DOM.
Wrap the checkbox and label in a container div (or li - i do forms with lists often) and apply
<div class="checkbox">
<input type="checkbox" id="agree" />
<label for="agree">I agree with checkbox</label>
</div>
.checkbox input {
float:left;
display:block;
margin:3px 3px 0 0;
padding:0;
width:13px;
height:13px;
}
.checkbox label {
float:left;
display:block;
width:auto;
}
Try this:
input { float: left; }
div { margin-left: 40px; }
Tune the margin-left
to how much space you want. The float: left
on the checkbox basically takes it out of the block layout so it doesn't push down the text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With