How to make an inline element appear on new line, or block element not occupy the whole line?

前端 未结 4 1699
不知归路
不知归路 2020-12-25 09:42

I can\'t figure out how to do this with CSS. If I just use a
tag, it works flawlessly, but I\'m trying to avoid doing that for obvious reasons.

相关标签:
4条回答
  • 2020-12-25 09:57

    I think floats may work best for you here, if you dont want the element to occupy the whole line, float it left should work.

    .feature_wrapper span {
        float: left;
        clear: left;
        display:inline
    }
    

    EDIT: now browsers have better support you can make use of the do inline-block.

    .feature_wrapper span {
        display:inline-block;
        *display:inline; *zoom:1;
    }
    

    Depending on the text-align this will appear as through its inline while also acting like a block element.

    0 讨论(0)
  • 2020-12-25 10:03

    Even though the question is quite fuzzy and the HTML snippet is quite limited, I suppose

    .feature_desc {
        display: block;
    }
    .feature_desc:before {
        content: "";
        display: block;
    }
    

    might give you want you want to achieve without the <br/> element. Though it would help to see your CSS applied to these elements.

    NOTE. The example above doesn't work in IE7 though.

    0 讨论(0)
  • 2020-12-25 10:05

    You can give it a property display block; so it will behave like a div and have its own line

    CSS:

    .feature_desc {
       display: block;
       ....
    }
    
    0 讨论(0)
  • 2020-12-25 10:05

    For the block element not occupy the whole line, set it's width to something small and the white-space:nowrap

    label
    {
        width:10px;
        display:block;
        white-space:nowrap;
    }
    
    0 讨论(0)
提交回复
热议问题