< span>的CSS宽度标签 [英] CSS width of a <span> tag

查看:161
本文介绍了< span>的CSS宽度标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的模块标题中使用< span> 标记,

I use <span> tags in my module titles, e.g.

< span> Categories< / span>。

我在css中指定了span的背景颜色/图片,宽度和高度。

I specify the span's background color/image, width and height in css.

但是span的宽度取决于其内容/文本。

But the span's width depends on its content/text.

所以,如果我做< span>< / span> ,在css只有一个背景图片/颜色,

So, if I do <span></span>, with just a background image/color in css, nothing appears.

当然,我想要一些东西出现。

Of course, I want something to appear.

如何解决?

推荐答案

您可以显式地将display属性设置为block,因此它的行为类似于块级元素,但在这种情况下, div。

You could explicitly set the display property to "block" so it behaves like a block level element, but in that case you should probably just use a div instead.

<span style="display:block; background-color:red; width:100px;"></span>

这篇关于&lt; span&gt;的CSS宽度标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆