且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在图标后对齐多行文本

更新时间:2023-12-04 12:26:22

你可以用 display: table;display: table-cell; 来做到这一点>

div{宽度:400px;边框:1px纯黑色;显示:表;填充:10px;}一,跨度{显示:表格单元格;垂直对齐:顶部;}

<a href="">图标:</a><span>这是我的格斗歌.收回我的生命之歌.证明我没事的歌.我的电源打开了从现在开始,我会变得坚强</span>

In a table with indentation (tree data), i need to align second line with the first line.

Notice, text "Tail" doesn't align with "Long"

Created a similar example here

div{
  width:400px;
}

<div>
  <a href="">ICon:</a>
  <span>This is my fight song. Take back my life song. Prove I'm alright song. My power's turned on
Starting right now I'll be strong</span>    
</div>

You can do this with display: table; and display: table-cell;

div{
  width:400px;
  border: 1px solid black;
  display: table;
  padding: 10px;
}

a, span {
  display: table-cell;
  vertical-align: top;
}

<div>
  <a href="">ICon:</a>
  <span>This is my fight song. Take back my life song. Prove I'm alright song. My power's turned on
Starting right now I'll be strong</span>    
</div>