Why does ::first-letter stop working as soon as I add display: flex or inline-flex?

梦想与她 提交于 2020-01-04 05:53:13

问题


I've implemented some ::first-letter styles for my p elements. However, when I add display: inline-flex to make them inline, all the ::first-letter styles stop working.

How can I make the elements inline while keeping the ::first-letter styles?

 p:first-of-type::first-letter {
    font-size: 25px;
    font-weight: bold;
 }

 p:nth-of-type(2)::first-letter {
    font-size: 25px;
    font-weight: bold;
 }

  p:nth-of-type(3)::first-letter {
    font-size: 25px;
    font-weight: bold;
 }

/* inline container */
p {                               
    display: inline-flex;
    width: 33%;
}

回答1:


A flex container (that is, an element with display: flex or display: inline-flex) cannot contain a ::first-letter pseudo-element, since a flex container contains flex items, not formatted lines. That's why making your p elements flex containers disables all your ::first-letter rules.

This appears to be the classic case of using display: flex/inline-flex when you're not trying to create a flex layout within each element. For inline (or horizontal) layout of block containers, use display: inline-block, display: table-cell, or floats, instead.



来源:https://stackoverflow.com/questions/43215710/why-does-first-letter-stop-working-as-soon-as-i-add-display-flex-or-inline-fl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!