[英]css flexbox grid with hover on flexbox cells (nested) does and does not work
The :hover behaviour in this example is making me doubt my sanity as everything in the code seems ok and works as expected, except the hovering of the white cells in the large matrix. 此示例中的:hover行为使我怀疑我的理智,因为代码中的所有内容似乎都正常且可以正常工作, 除了将白细胞 悬停在大型矩阵中之外。
The generic structure has 2 flexbox div
rows where: 通用结构具有2个flexbox div
行,其中:
div
3by3 matrixes (2 puzzles each with 9 cells) 第一行有2个小的flexbox div
3by3矩阵(2个拼图,每个拼图有9个单元格) div
3by3 matrix of nine flexbox ul
3by3 matrixes (9 puzzles each with 9 cells ) 第二行包含1个大型flexbox div
3by3矩阵,其中9个flexbox ul
3by3矩阵(9个拼图,每个拼图有9个单元格) div
, ul
and li
) are flexbox containers 所有标签( div
, ul
和li
)都是flexbox容器 The layouts have been copied from real Sudoku puzzles for this question (sorry, i don't have the solutions). 布局是从真正的Sudoku拼图中复制的,以解决此问题(对不起,我没有解决方案)。
To reproduce the problem 重现问题
CornflowerBlue.
悬停时,每个单元格会CornflowerBlue.
彩色的CornflowerBlue.
CornflowerBlue
instead of each of the 9 cells individually. 将鼠标悬停在大型矩阵的白色单元格上, 只有完整的拼图才会变成彩色的CornflowerBlue
而不是分别是9个单元格中的每一个。 The Question 问题
Please tell me, have I stumbled over some CSS bug (probably not) or is the solution (which?) staring me in the face and do I just not see my mistake? 请告诉我,我是否偶然发现了一些CSS错误(可能不是),或者解决方案(哪个?)正盯着我,我只是看不到我的错误?
The Code (A bit long, but fully commented and with a few nifty responsiveness tricks...) 代码 (有点长,但是经过充分注释,并带有一些漂亮的响应技巧...)
/*****************************/ /* MINIMAL REQUIRED [STABLE] */ /*****************************/ /* [MANDATORY] for '.fbl-cell' to work */ html,body { box-sizing: border-box } ::before,:after, * { box-sizing: inherit } /* remove default markup */ ul { margin: 0; padding: 0 } li { list-style-type: none } /**************************************/ /* easy RESPONSIVE|FONT|NESS [STABLE] */ /**************************************/ /* Math: y=mx+b for points p1(320,14) p2(1280,20) => 14>20 */ html { font-size: calc(0.00625 * 100vmin + 12px) } /* device dependend (not W/H), so use VMIN */ [lang="ar"] { font-size: calc(0.00625 * 100vmin + 15px) } /* 17>23 (Arabic looks a bit small at 14>20) */ body { font-size: 1rem; line-height: 1.5; margin: 0 } /* HTML default 16px/1.3/10px (or so) */ /***************************************/ /* GRID RESTRAINTS and MARKUP [STABLE] */ /***************************************/ /* main container */ .sudoku-row { display: flex; flex-flow: row wrap; justify-content: center; padding: .5rem; max-width: 100vmin; margin: 3rem auto; } /* cell container (default size) */ .sudoku-row>.sudoku { height: 10rem; width : 10rem; margin: .5rem; font-size: calc(0.00625 * 100vmin + 18px); /* responsive: (320,20)(1280,26) */ } .sudoku.fullsize { /* large size override */ height: 75vmin; width : 75vmin; margin: 0 auto; font-size: calc(0.025 * 100vmin + 6px); /* responsive: (320,14)(1280,38) */ } /* hover */ .sudoku,.sudoku.fullsize>* { border: 1px solid black; } [fbl-cell]>:hover,.sudoku li:hover { background: CornflowerBlue; cursor: pointer; } /* coloring/styling */ body { background-color: #f0f0f0; } .sudoku-row>.sudoku { background: #fff; } .sudoku>:nth-child(even) { background-color: #eee; } .sudoku li { border: 1px solid hsla(0,0%,0%,.15); } /*********************************************/ /* FLEXBOX and PATCH GRID STRUCTURE [STABLE] */ /*********************************************/ /* Both parent end child are flexbox containers */ [fbl-cell],[fbl-cell]>* { display: flex; flex-wrap: wrap; } [fbl-cell] { align-content: flex-start; } [fbl-cell]>* { /* cell immediate child elements */ flex: 1; /* allow grow (and shrink, which is HTML default as is 'flex-basis: auto') */ overflow: hidden; /* [MANDATORY] */ /* [DEMO] center content hor/vert inside cell */ justify-content: center; align-items: center; } [fbl-cell="3x3"]>* { /* 3by3 matrix equally divided over parent space */ flex-basis: 33.33333%; max-width : 33.33333%; /* 'width' won't work */ height : 33.33333%; max-height: 33.33333%; }
<div class="sudoku-row"> <ul fbl-cell="3x3" class="sudoku"><li> <li>9<li> <li>4<li><li>1<li> <li> <li>3</ul> <ul fbl-cell="3x3" class="sudoku"><li>2<li> <li>5<li> <li><li> <li> <li> <li> </ul> </div> <div class="sudoku-row"> <div fbl-cell="3x3" class="sudoku fullsize"> <ul fbl-cell="3x3"><li> <li>9<li> <li>4<li><li>1<li> <li> <li>3</ul> <ul fbl-cell="3x3"><li>2<li> <li>5<li> <li><li> <li> <li> <li> </ul> <ul fbl-cell="3x3"><li> <li>1<li> <li>3<li><li>9<li>6<li> <li> </ul> <ul fbl-cell="3x3"><li> <li> <li>3<li> <li><li> <li>9<li> <li> </ul> <ul fbl-cell="3x3"><li>4<li> <li>8<li> <li><li> <li>6<li> <li>1</ul> <ul fbl-cell="3x3"><li> <li> <li>5<li> <li><li> <li> <li> <li>7</ul> <ul fbl-cell="3x3"><li> <li> <li>9<li>6<li><li>7<li> <li>3<li> </ul> <ul fbl-cell="3x3"><li> <li> <li> <li> <li><li> <li>7<li> <li>9</ul> <ul fbl-cell="3x3"><li>1<li> <li> <li>4<li><li>2<li> <li>8<li> </ul> </div> </div>
Change the hover
rule/selector to 将hover
规则/选择器更改为
[fbl-cell]>li:hover,.sudoku > ul li:hover {
background: CornflowerBlue;
cursor: pointer;
}
/*****************************/ /* MINIMAL REQUIRED [STABLE] */ /*****************************/ /* [MANDATORY] for '.fbl-cell' to work */ html,body { box-sizing: border-box } ::before,:after, * { box-sizing: inherit } /* remove default markup */ ul { margin: 0; padding: 0 } li { list-style-type: none } /**************************************/ /* easy RESPONSIVE|FONT|NESS [STABLE] */ /**************************************/ /* Math: y=mx+b for points p1(320,14) p2(1280,20) => 14>20 */ html { font-size: calc(0.00625 * 100vmin + 12px) } /* device dependend (not W/H), so use VMIN */ [lang="ar"] { font-size: calc(0.00625 * 100vmin + 15px) } /* 17>23 (Arabic looks a bit small at 14>20) */ body { font-size: 1rem; line-height: 1.5; margin: 0 } /* HTML default 16px/1.3/10px (or so) */ /***************************************/ /* GRID RESTRAINTS and MARKUP [STABLE] */ /***************************************/ /* main container */ .sudoku-row { display: flex; flex-flow: row wrap; justify-content: center; padding: .5rem; max-width: 100vmin; margin: 3rem auto; } /* cell container (default size) */ .sudoku-row>.sudoku { height: 10rem; width : 10rem; margin: .5rem; font-size: calc(0.00625 * 100vmin + 18px); /* responsive: (320,20)(1280,26) */ } .sudoku.fullsize { /* large size override */ height: 75vmin; width : 75vmin; margin: 0 auto; font-size: calc(0.025 * 100vmin + 6px); /* responsive: (320,14)(1280,38) */ } /* hover */ .sudoku,.sudoku.fullsize>* { border: 1px solid black; } [fbl-cell]>li:hover,.sudoku > ul li:hover { background: CornflowerBlue; cursor: pointer; } /* coloring/styling */ body { background-color: #f0f0f0; } .sudoku-row>.sudoku { background: #fff; } .sudoku>:nth-child(even) { background-color: #eee; } .sudoku li { border: 1px solid hsla(0,0%,0%,.15); } /*********************************************/ /* FLEXBOX and PATCH GRID STRUCTURE [STABLE] */ /*********************************************/ /* Both parent end child are flexbox containers */ [fbl-cell],[fbl-cell]>* { display: flex; flex-wrap: wrap; } [fbl-cell] { align-content: flex-start; } [fbl-cell]>* { /* cell immediate child elements */ flex: 1; /* allow grow (and shrink, which is HTML default as is 'flex-basis: auto') */ overflow: hidden; /* [MANDATORY] */ /* [DEMO] center content hor/vert inside cell */ justify-content: center; align-items: center; } [fbl-cell="3x3"]>* { /* 3by3 matrix equally divided over parent space */ flex-basis: 33.33333%; max-width : 33.33333%; /* 'width' won't work */ height : 33.33333%; max-height: 33.33333%; }
<div class="sudoku-row"> <ul fbl-cell="3x3" class="sudoku"><li> <li>9<li> <li>4<li><li>1<li> <li> <li>3</ul> <ul fbl-cell="3x3" class="sudoku"><li>2<li> <li>5<li> <li><li> <li> <li> <li> </ul> </div> <div class="sudoku-row"> <div fbl-cell="3x3" class="sudoku fullsize"> <ul fbl-cell="3x3"><li> <li>9<li> <li>4<li><li>1<li> <li> <li>3</ul> <ul fbl-cell="3x3"><li>2<li> <li>5<li> <li><li> <li> <li> <li> </ul> <ul fbl-cell="3x3"><li> <li>1<li> <li>3<li><li>9<li>6<li> <li> </ul> <ul fbl-cell="3x3"><li> <li> <li>3<li> <li><li> <li>9<li> <li> </ul> <ul fbl-cell="3x3"><li>4<li> <li>8<li> <li><li> <li>6<li> <li>1</ul> <ul fbl-cell="3x3"><li> <li> <li>5<li> <li><li> <li> <li> <li>7</ul> <ul fbl-cell="3x3"><li> <li> <li>9<li>6<li><li>7<li> <li>3<li> </ul> <ul fbl-cell="3x3"><li> <li> <li> <li> <li><li> <li>7<li> <li>9</ul> <ul fbl-cell="3x3"><li>1<li> <li> <li>4<li><li>2<li> <li>8<li> </ul> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.