html - 元素左侧的边距文本如何?
问题描述
里面有span
带图标的块:
<span><i></i>Text</span>
图标有 CSS:
i {
display: inline-block;
width: 20px;
height: 20px;
}
如果text
很长,它将换行到 icon 下的下一行i
。
如何用左边距换行文本:图标的宽度
我现在有这个:
Icon - Text he
re
但是我需要:
Icon - Text he
re
解决方案
绝对定位
span {
position: relative;
padding-left: 25px;
width: 200px;
display: inline-block;
border: 1px solid red;
margin: 1em;
}
i {
position: absolute;
left: 0;
width: 20px;
height: 20px;
background: pink;
}
<span><i>I</i>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Delectus, quam.</span>
推荐阅读
- android - 如何在 moxy Presenter android 中获取上下文
- gradle - client-dependencies-gradle 暴露依赖关系在哪里?
- ruby-on-rails - gem Ransack 自定义搜索仅年份而不是完整日期
- amazon-web-services - aws cloudfront 上的间歇性 404。
- python-3.x - 如何动态响应 Cherrypy 中的 PIL 图像(Python3)?
- android - CalcGP.semester 必须是“数字”类型,得到“字符串”(“1”)
- excel - 如何在 Excel 2010 上结合 Power Query 和 Power Pivot 处理不适合 RAM 的巨大 csv 文件
- java - 由于 Netty 中的 ByteBuffers 导致的内存泄漏
- java - 如何使协变消费者工作?
- python - 从 pandas.dataframe 查询数据时 df[:,'column_name'] 和 df['column_name'] 有什么区别