CSS - span 标签不支持宽度

发布于 2024-07-27 16:51:51 字数 947 浏览 2 评论 0原文

我的其中一个跨度有问题。 请考虑以下样式:

.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;
}

我的代码中的这 3 个跨度:

<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" -->

当“COL1CHE”(或者甚至可能在其中任何一个,但我不确定)中没有数据显示时,当此跨度没有数据时,就会出现问题“崩溃”并且其宽度不受尊重。 这种情况发生在 Firefox 中,但在 IE 中它不会“崩溃”。

我加入了一个“清晰”的课程来看看这是否有帮助,但没有效果。

有任何想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

七堇年 2024-08-03 16:51:51

Span 是一个内联元素,因此您无法设置宽度。 要设置宽度,必须首先将其设置为块元素,然后

display:block;

才能设置宽度。 由于span是一个原生的内联元素,你也可以使用inline-block,它甚至可以在IE中工作:

display:inline-block;

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;
┼── 2024-08-03 16:51:51

不支持宽度,因为 span 是内联元素。 要解决此问题,请添加:

display: inline-block;

根据您的情况,display: inline-block 可能比 display: block 更好,因为跨度之后的任何内容都不会被强制到新队。

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.

橙味迷妹 2024-08-03 16:51:51

display: block 不会在这里为您提供帮助,因为当激活浮动时,元素会自动切换到块模式,无论其初始模式如何,因此您的宽度应该起作用。

问题可能出在空的 标记上,由于我不记得一些模糊的规则,该标记可能无法呈现。 您应该尝试防止您的范围为空,如果内容为空,可以添加  

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   if the content is empty.

装纯掩盖桑 2024-08-03 16:51:51

要使这项工作正常进行,只需添加

display: block;

到样式即可。

To make this work simply add

display: block;

To the style.

如果没有你 2024-08-03 16:51:51

显示 block 和可选的浮动 left 帮助了我。

display: block;
float: left;

Display block and optionally float left helped me.

display: block;
float: left;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文