【问题标题】:How to line up an icon with a stacked heading and subtext?如何排列带有堆叠标题和潜台词的图标?
【发布时间】:2021-10-27 15:19:39
【问题描述】:

我一直在努力将图像图标(不是字体图标)与标题和文本对齐。

我找到了一些很好的例子来说明如何做到这一点,但不是用标题,如果是这样,它使用了我试图避免的 fontawesome 图标。

.soccer-icon {
  width: 50px;
}

.icon-header {
  font-size: 18px;
  line-height: 32px;
  display: block !important;
  padding-right: 20px
}

.icon-area {
  display: flex;
  align-items: center;
}
<div class="icon-area">
  <p>
    <img class="soccer-icon" src="https://cdn1.iconfinder.com/data/icons/sports-balls-4/32/balls_filled_outline-01-512.png" />
  </p>
  <h3 class="icon-header">Paper Ballot Inspection</h3>
  <p>A full count of the ballots, including scanning and visual inspection of all ballots.</p>
</div>

【问题讨论】:

  • 我运行了您提供的内容,他们排成一列。您是否更想将文本与图像的中间对齐?
  • @Brandon 他希望文本堆叠。不是并排

标签: html css icons html-heading


【解决方案1】:

给你,

https://jsfiddle.net/2ro6dqay/

我已将两个标题放在单独的 &lt;div&gt; 中,然后设置它们的样式

【讨论】:

    【解决方案2】:

    您可以将&lt;h3&gt; 和&lt;p&gt; 元素包装在父&lt;div&gt; 中,并使其成为flexbox 列布局,以便文本垂直堆叠。然后,从该容器中的 h3 和段落元素中删除默认边距,以便它们更紧密地组合在一起。

    使用您在.icon-area 上的现有align-items: center 声明,这似乎创造了您想要的风格。

    .soccer-icon {
      width: 50px;
    }
    
    .icon-header {
        font-size: 18px;
        line-height: 32px;
        display: block;
        padding-right: 20px
    }
    
    .icon-area {
     display: flex;
     align-items: center;
     max-width: 80ch; /* for demo */
    }
    
    .column {
     display: flex;
     flex-direction: column;
    }
    
    .column h3,
    .column p,
    .icon-area p {
      margin: 0;
    }
    <div class="icon-area"><p>
       <img class="soccer-icon" src="https://cdn1.iconfinder.com/data/icons/sports-balls-4/32/balls_filled_outline-01-512.png" />
       </p>
       <div class="column">
          <h3 class="icon-header">Paper Ballot Inspection</h3>
           <p>A full count of the ballots, including scanning and visual inspection of all ballots. Some more text to occupy two lines.</p>
       </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-04
      • 2011-02-21
      • 2019-03-29
      • 1970-01-01
      • 2013-03-15
      • 2014-07-18
      相关资源
      最近更新 更多