简体   繁体   中英

Span tag with display:inline rendering as display:block

I have a span tag like this

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

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).

As such you will either need to prevent this from being set, remove it (ie using JS) or override it in your CSS.

To override in your CSS, you will need to use !important , eg:

#trnfrm{
  display:inline!important;
}

That said, note that the use of !important is not recommended . 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. Although, !important has nothing to do with specificity. Using !important is bad practice because it makes debugging hard since you break the natural cascading in your stylesheets.

Inserting anchor tag and img tag inside span tag is not an ideal way of coding. Wrap them inside a div tag which is a block element and style for the class "trnfr" and div should be display:inline-block".

This is CSS issue for sure. Please provide some more data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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