Tutorial :CSS - width not honored on span tag


I have a issue with one of my spans. Please consider the following styles:

.form_container .col1che  {  float: left;   width: 4%;   text-align: left;      }    .form_container .col2che  {  float: left;   width: 80%;   text-align:left;  }    .form_container .col3che  {  float: right;   width: 13%;   text-align:right;  }  

These 3 spans in my code:

<div class="row"><!-- start: "row" -->       <span class="col1che">                    <?php  //some db feeds    ?>               </span>       <span class="col2che">            <?php  //some db feeds    ?>       </span>       <span class="col3che">            <?php  //some db feeds    ?>       </span>       <div class="clear"></div>  </div><!-- end: "row" -->  

The problem occurs when there is no data to be displayed in "COL1CHE" (or maybe even in any of them although I'm not sure) when there is no data this span "collapses" and its width is not honored. This happens in Firefox, in IE it doesn't "collapse".

I included a "clear" class to see if this helps but to no avail.

Any ideas?


display: block will not help you here because when float is activated, the elements is automatically switched to block mode, whatever its initial mode, so your width should work.

The problem may be with the empty <span> tag which might not be rendered because of some obscure rule I cannot remember. You should try preventing your span from being empty, maybe by adding a &nbsp; if the content is empty.


Span is an inline element and you can therefore not set a width. To set a width you must first set it to a block element with


After that you can set a width. Since span is a native inline element, you can use inline-block too and it will even work in IE:



Width is not honored because span is an inline element. To fix this, add:

display: inline-block;  

Depending on your situation, display: inline-block may be better than display: block because any content after the span won't be forced onto a new line.


To make this work simply add

display: block;  

To the style.


Display block and optionally float left helped me.

display: block;  float: left;  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »