在表格行中将”long span”和”i”显示在同一行。

huangapple go评论58阅读模式
英文:

Display long span and i on the same line in a table row

问题

我有以下问题,图标通常应该有足够的空间与文本放在同一行:

在表格行中将”long span”和”i”显示在同一行。

但它没有,我不确定要使用哪个css:

<tr>
  <td>22/06/2021 15:20:52</td>
  <td>
   <span> 
    苹果是红色的。
    <i class="fa fa-pencil padding-left-3" />
   </span>
  </td>

如果文本较小,则图标会很好地显示在同一行,但如果文本较大,则会移到下一行。

可以用什么来解决这个问题?

英文:

I have the following issue, the icon normally should have enough space to go on the same line as the text:

在表格行中将”long span”和”i”显示在同一行。

But it doesn't and I'm not sure what css to use for it:

<tr>
  <td>22/06/2021 15:20:52</td>
  <td>
   <span> 
    The apple is red.
    <i class="fa fa-pencil padding-left-3" />
   </span>
  </td>

If the text is smaller, the icon is displayed nicely on the same line, but if the text is bigger then it just shifts to the next line.

What can be used for it?

答案1

得分: 1

  html 文件:

    <tr>
          <td>22/06/2021 15:20:52</td>
          <td>
           <span class="text"> 
            苹果是红色的。
            <i class="fa fa-pencil padding-left-3" />
           </span>
          </td>
css 文件:

    .text{
      显示: 弹性;
      对齐项目: 居中;
    }
英文:

html file:

<tr>
      <td>22/06/2021 15:20:52</td>
      <td>
       <span class="text"> 
        The apple is red.
        <i class="fa fa-pencil padding-left-3" />
       </span>
      </td>

css file:

.text{
  display: flex;
  align-items: center;
}

答案2

得分: 1

如果您有足够的空间来放置图标元素,那么它将正常工作。确保调整旁边的另外两个元素的paddingmargin

或者您可以简单地应用CSS。

span {
  display: flex;
  align-items: center; /* 可选 */
  justify-content: center; /* 可选 */
}

尽管该元素是内联元素,但flex属性会默认将其子元素排列成一行,直到您明确设置了属性

flex-direction: column;

确保在执行此操作时,它将更改代码中的所有span元素。我建议更好地使用CSS中的类选择器ID选择器。希望这对您有所帮助。

英文:

if you have enough room for the icon element then it will work fine. Make sure adjusting some padding and margin of other two elements beside.

Or you can simply apply the CSS.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

span{
  display: flex;
  align-items: center; /* optional */
  justify-content: center; /* optional */
}

<!-- end snippet -->

Though the element is inline element, The flex property will arrange its children in a row default. until explicitly you set the property

flex-direction: column;

Make sure when you do this it will change all the span element in your code. I suggest better use class selector or id selector in css. I hope this will help.

huangapple
  • 本文由 发表于 2023年2月24日 16:27:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554179.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定