Add a z-index
to the element on hover.
Additionally, the element also has to be positioned in order for the z-index
property to work. Therefore add position:relative
too.
9.9.1 Specifying the stack level: the 'z-index' property
z-index: Applies to: positioned elements
Each box has a position in three dimensions. In addition to their horizontal and vertical positions, boxes lie along a "z-axis" and are formatted one on top of the other. Z-axis positions are particularly relevant when boxes overlap visually. This section discusses how boxes may be positioned along the z-axis.
Updated Codepen - it works now.
.tile:hover, .tile2:hover {
z-index: 1;
position: relative;
}
To address your second issue, the elements are appearing on a new line because their widths do not add up, as it is 1px
off due to the border.
33.3%
+ 33.3%
+ 33.3%
+ 1px
!= 100%
You have a few different options:
If you choose to use box-sizing
, you need appropriate vendors/prexes if you want support across all browsers. I would use something like:
.tile2 {
width: 33.3%;
border-left: 1px solid #ddd;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
Updated Codepen using box-sizing
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…