Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Span Float Left

Tags:

css

css-float

So I have a div and two spans:

<div class="A">
    <span class="B"></span>
    <span class="C"></span>
    <span class="clear"></span>
</div>

Assume that B and C has sufficient contents. The CSS snippet is:

.A { position: absolute; } /* I need this to be absolute */
.B, .C { float: left; }
.clear { clear: both; }

But I keep getting the layout of the right image, while I want it to be like layout of first image (refer to image below) enter image description here

Please help me. And it would be better if you kindly explain a bit why do they happen and why is my code not working like I expected. How is float actually working. Thanks.

like image 349
Reinardus Surya Pradhitya Avatar asked Dec 28 '22 00:12

Reinardus Surya Pradhitya


1 Answers

Your classes in the html are capitals but not in the CSS?

EDIT:

.A { position: absolute; border: 1px solid blue; } 
.B, .C { float: left; border: 1px solid red; width: 100px; height: 20px; }
.C { height: 100px; }
.clear { clear: both; }
<div class="A">
    <span class="B"></span>
    <span class="C"></span>
    <span class="clear"></span>
</div>

Demo on JSFiddle

like image 170
Lee Avatar answered Jan 12 '23 00:01

Lee