Set percentage width for span element

你。 提交于 2019-12-23 07:27:51

问题


A straight forward question.. is it possible to set the width in percentage for a span tag in CSS? for example:

<span style="width: 50%">...</span> 

etc..

In my project I'm currently using divs but ofcourse after each div tag a line break gets inserted (which I don't want). So the most obvious solution to that is then to use span tags instead of div. But then I'm not able to define the width for the span tags.. Atleast not in a percentage kind of way.

Thanks in advance for any help!


回答1:


Define the element as an inline block and you can control the width and height like a block element while keeping it inline with surrounding content.

#element {
  display: inline-block;
  width: 50%;
}



回答2:


inline elements cannot have dimensions. do them to do so, and still remain inline, add:

display: inline-block


来源:https://stackoverflow.com/questions/10085557/set-percentage-width-for-span-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!