CSS - width not honored on span tag

后端 未结 5 1494
青春惊慌失措
青春惊慌失措 2021-02-06 23:26

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_c         


        
相关标签:
5条回答
  • 2021-02-06 23:36

    To make this work simply add

    display: block;
    

    To the style.

    0 讨论(0)
  • 2021-02-06 23:36

    Display block and optionally float left helped me.

    display: block;
    float: left;
    
    0 讨论(0)
  • 2021-02-06 23:47

    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

    display:block;
    

    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:

    display:inline-block;
    
    0 讨论(0)
  • 2021-02-06 23:49

    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.

    0 讨论(0)
  • 2021-02-06 23:53

    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.

    0 讨论(0)
提交回复
热议问题