有时候一个简单Bug的出现,每每是因为一点知识小细节;但每每这点小细节看似简单,其背后却很有韵味。
看起来相对比较简单,分析下结构:css
// <span className="check" /> .check{ position: relative; display: inline-block; width: 16px; height: 15px; margin: 0 10px; &::after{ content: ""; position: absolute; left:0; width: 100%; height: 50%; border: 2px solid #000; border-radius: 1px; border-top: none; border-right: none; background: transparent; transform: rotate(-45deg); } }
// 部分代码,做用就是循环生成列表 <ul className="detail" > { storeTypeInfoMap[type].map(item => ( <li> {item} <span className="check" /> </li>)) } </ul> // css .detail { font-size: 12px; color: $c-gray; li { display: flex; justify-content: space-between; align-items: center; text-align: left; line-height: 3em; padding-right: 10px; .check{ position: relative; display: inline-block; width: 16px; height: 15px; margin: 0 10px; &::after{ content: ""; position: absolute; left:0; width: 100%; height: 50%; border: 2px solid #000; border-radius: 1px; border-top: none; border-right: none; background: transparent; transform: rotate(-45deg); } } } }
list-style-type: disc;
,仍是没用?问题在于display ?:segmentfault
display:list-item
啊;list-style
属性是由于,浏览器对li的默认display:list-item
,就像内敛元素display默认为inline
;<ul className="detail" > { storeTypeInfoMap[type].map(item => ( <li> <p className="detail-item"> {item} <span className="check" /> </p> </li>)) } </ul>
两个解决方案:浏览器
list-style-position
属性,设置为inside将图标放进li中就好(用这个把):display: inline-flex
看看:display:inline-XXX
inline-block
标签设置宽度(根据内容自动,固然能够设置宽度%给图标腾出位置,但这样处理后期更改宽度相对麻烦),以致于当内容不足以一行容下时,p宽度就别撑到父容器的宽度,便换行;那么有什么办法解决呢(联系下处理inline—block布局问题的方式)?ide
font-size: 0
font-size
能够控制其大小;white-space: nowrap
white-space: pre-wrap
试试list-style-position: outside;
而后容器ul设置margin啰)学无止境,积累点滴;把小简单变成大简单。