简体   繁体   English

带显示的跨度标记:内联呈现为display:block

[英]Span tag with display:inline rendering as display:block

I have a span tag like this 我有这样的span标签

<td>
<s:textfield name="trnfr" id="trnfr"/>
<span id="trnfrm" style="width:10px;display:inline;">
  &nbsp;
  <a onClick="showCal('trnfrm')"><img src="./images/cal.gif" border="0"
  alt='<s:text name="Co.Cal" />' /> </a>
</span>
</td>

It should render as 它应该呈现为

在此输入图像描述

but it is rendering like this 但它是这样呈现的

在此输入图像描述

when i viewed the source in the browser it is being rendered like this 当我在浏览器中查看源代码时,它就像这样呈现

在此输入图像描述

Dont know whats going wrong. 不知道什么是错的。

Note: I got the correct image by changing display:block to display:inline dynamically in the browser. 注意:我通过更改display:block to display获得了正确的图像:在浏览器中动态内联。

You aren't able to easily override in your CSS because the element is being set to display:block inline (within your HTML), likely by the framework you are using (hard to say without further detail). 您无法在CSS中轻松覆盖,因为该元素被设置为display:block inline(在您的HTML中),可能是您正在使用的框架(很难说没有进一步的细节)。

As such you will either need to prevent this from being set, remove it (ie using JS) or override it in your CSS. 因此,您需要阻止设置,删除它(即使用JS)或在CSS中覆盖它。

To override in your CSS, you will need to use !important , eg: 要在CSS中覆盖,您需要使用!important ,例如:

#trnfrm{
  display:inline!important;
}

That said, note that the use of !important is not recommended . 也就是说,请注意不建议使用!important Ideally you should look to fix the root cause. 理想情况下,您应该寻找修复根本原因。

When an !important rule is used on a style declaration, this declaration overrides any other declaration made in the CSS, wherever it is in the declaration list. 当在样式声明上使用!important规则时,此声明将覆盖CSS中的任何其他声明,无论它在声明列表中的何处。 Although, !important has nothing to do with specificity. 虽然, !important与特异性无关。 Using !important is bad practice because it makes debugging hard since you break the natural cascading in your stylesheets. 使用!important是不好的做法,因为它会破坏样式表中的自然级联,从而使调试变得困难。

Inserting anchor tag and img tag inside span tag is not an ideal way of coding. 在span标记内插入锚标记和img标记不是一种理想的编码方式。 Wrap them inside a div tag which is a block element and style for the class "trnfr" and div should be display:inline-block". 将它们包装在div标签内,div标签是“trnfr”类的块元素和样式,div应该是display:inline-block“。

This is CSS issue for sure. 这肯定是CSS问题。 Please provide some more data. 请提供更多数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM