I have repeatedly run into this problem and did not find a solution yet.
Example 1: http://jsfiddle.net/0f5u0w6e/1/
What it Looks like:
What it should look like:
In this example the divs should behave like lines, but it is more than that: I want the divs or spans to be bounding boxes for all their Contents. (Then it is also impossible that part of their contents pushes parts of another divs content.)
Example 2: http://jsfiddle.net/gd7Losru/1/
I want the inner (red) span to make the outer (blue) div have a height such that it contains it. (again: bounding box).
copies of the code if jsFiddle goes offline: Example 1:
<div style="width: 200px;">
<div>
Title Title Title
<span class="button"
style="float: right; padding: 10px;">
button</span>
</div>
<div>
Config:
<input type="text" />
</div>
</div>
Example 2:
<div style="background-color: blue;">
<span style="padding: 10px; background-color:red; "></span>
</div>
So, you can always nest divs within divs, and attach unique classes or id attributes to them so you don't get confused. The span tag is an inline element that you use to make a smaller part of content stand out with CSS or JavaScript.
It is suitable to make use of these elements whenever style considerations or other functionality requires the use of a container of some kind, but no other HTML element is appropriate to represent the meaning of the content contained. Div and span elements are simply containers that apply no meaning whatsoever to the content.
This tutorial will teach you how to nest HTML elements in order to apply multiple HTML tags to a single piece of content. HTML elements can be nested, meaning that one element can be placed inside another element. Nesting allows you to apply multiple HTML tags to a single piece of content.
Using the <span> Element The span element is an inline element by default. This sets it apart from the div and section elements. The span element is often used to wrap a specific piece of content, normally text, to give it an additional "hook" that can be styled later.
Just clear the float on the second inner div:
<div style="width: 200px;">
<div>
Title Title Title
<span class="button"
style="float: right; padding: 10px;">
button</span>
</div>
<div style="clear: both;">
Config:
<input type="text" />
</div>
</div>
JSFiddle
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