Selector for an element alone in a row? [duplicate]

一世执手 提交于 2020-01-02 07:41:10

问题


We have flex container with 2 child elements.

When we resize window, and one of flex item wraps, we have each element on its own row.

Is it any selector like :when-alone-in-row?

.flex-parent {flex-flow: row wrap}
    .flex-child
    .flex-child

回答1:


No, there is no selector similar to :when-alone-in-row.

However, when you want to select the first and last elements from a group of siblings (which would be the case here since you're dealing with only two flex items), you can use the :first-child and :last-child pseudo classes.

Of course, the styles applied by these selectors will work even when both items are on the same line, unless they're applied in a media query.




回答2:


If it always collapses at the same screen size you could use media queries to adjust the styles when they are on their own row.

If not, it might be worth also using media queries for the collapsing, so you can better control your rows / columns.



来源:https://stackoverflow.com/questions/39704735/selector-for-an-element-alone-in-a-row

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