Reputation: 15
I have a honeycomb css design and i am struggling to get the background image to span across all hexagons. At the moment the image repeats in each hexagon. I think there is a conflict between the css transforms and the fixed background.
Here is my codepen link : https://codepen.io/andymikellides/pen/OJzgWON
Here is my code:
<ul id="hexGrid" class="pb-5">
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
<li class="hex">
<a class="hexIn" href="#">
<h4>test</h4>
<p>inner content</p>
</a>
</li>
</ul>
#hexGrid {
overflow: hidden;
width: 90%;
margin: 0 auto;
padding:0.707% 0;
}
#hexGrid:after {
content: "";
display: block;
clear: both;
}
.hex {
position: relative;
list-style-type: none;
float: left;
overflow: hidden;
visibility: hidden;
-webkit-transform: rotate(-60deg) skewY(30deg);
-ms-transform: rotate(-60deg) skewY(30deg);
transform: rotate(-60deg) skewY(30deg);
}
.hex * {
position: absolute;
visibility: visible;
}
.hexIn {
display:block;
width: 100%;
height: 100%;
text-align: center;
color: #fff;
overflow: hidden;
-webkit-transform: skewY(-30deg) rotate(60deg);
-ms-transform: skewY(-30deg) rotate(60deg);
transform: skewY(-30deg) rotate(60deg);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background: url("https://i.picsum.photos/id/539/200/300.jpg?hmac=anJssHN1m53jBatiVAldD8gSdk_3w_5WHOCNCFvGFkk") no-repeat center center fixed;
background-size: cover;
background-attachment: fixed;
}
/* HEX CONTENT */
.hex h4 {
width: 100%;
display: flex;
height: 100%;
align-items: center;
justify-content: center;
color: white;
margin: 0px;
}
.hex p {
width: 100%;
display: flex;
top: 0px;
font-size: 13px;
line-height: 1.2;
padding: 10px;
height: 100%;
align-items: center;
background-color: rgb(137, 179, 137);
color: white;
-webkit-transition: top .4s ease-out, bottom .4s ease-out, .4s padding .4s ease-out;
transition: top .4s ease-out, bottom .4s ease-out, .4s padding .4s ease-out;
}
.hex p {
padding-top: 50%;
top: 110%;
padding-bottom: 50%;
}
/* HOVER EFFECT */
.hexIn:hover p {
width: 100%;
display: flex;
top: 0px;
padding: 10px;
height: 100%;
align-items: center;
}
@media (min-width:1201px) {
.hex {
width: 19.2%; /* = (100-4) / 5 */
padding-bottom: 22.170%; /* = width / sin(60deg) */
}
.hex:nth-child(9n+6),
.hex:nth-child(9n+7),
.hex:nth-child(9n+8),
.hex:nth-child(9n+9) {
margin-top: -4.676%;
margin-bottom: -4.676%;
-webkit-transform: translateX(50%) rotate(-60deg) skewY(30deg);
-ms-transform: translateX(50%) rotate(-60deg) skewY(30deg);
transform: translateX(50%) rotate(-60deg) skewY(30deg);
}
.hex:nth-child(9n+6):last-child,
.hex:nth-child(9n+7):last-child,
.hex:nth-child(9n+8):last-child,
.hex:nth-child(9n+9):last-child {
margin-bottom: 0;
}
.hex:nth-child(9n+6) {
margin-left: 0.5%;
clear: left;
}
.hex:nth-child(9n+10) {
clear: left;
}
.hex:nth-child(9n+2),
.hex:nth-child(9n+ 7) {
margin-left: 1%;
margin-right: 1%;
}
.hex:nth-child(9n+3),
.hex:nth-child(9n+4),
.hex:nth-child(9n+8) {
margin-right: 1%;
}
}
@media (max-width: 1200px) and (min-width:901px) {
.hex {
width: 24.25%; /* = (100-3) / 4 */
padding-bottom: 28.001%; /* = width / sin(60deg) */
}
.hex:nth-child(7n+5),
.hex:nth-child(7n+6),
.hex:nth-child(7n+7) {
margin-top: -6.134%;
margin-bottom: -6.134%;
-webkit-transform: translateX(50%) rotate(-60deg) skewY(30deg);
-ms-transform: translateX(50%) rotate(-60deg) skewY(30deg);
transform: translateX(50%) rotate(-60deg) skewY(30deg);
}
.hex:nth-child(7n+5):last-child,
.hex:nth-child(7n+6):last-child,
.hex:nth-child(7n+7):last-child {
margin-bottom: 0;
}
.hex:nth-child(7n+2),
.hex:nth-child(7n+6) {
margin-left: 1%;
margin-right: 1%;
}
.hex:nth-child(7n+3) {
margin-right: 1%;
}
.hex:nth-child(7n+8) {
clear: left;
}
.hex:nth-child(7n+5) {
clear: left;
margin-left: 0.5%;
}
}
@media (max-width: 900px) and (min-width:601px) {
.hex {
width: 32.666%; /* = (100-2) / 3 */
padding-bottom: 37.720%; /* = width / sin(60) */
}
.hex:nth-child(5n+4),
.hex:nth-child(5n+5) {
margin-top: -8.564%;
margin-bottom: -8.564%;
-webkit-transform: translateX(50%) rotate(-60deg) skewY(30deg);
-ms-transform: translateX(50%) rotate(-60deg) skewY(30deg);
transform: translateX(50%) rotate(-60deg) skewY(30deg);
}
.hex:nth-child(5n+4):last-child,
.hex:nth-child(5n+5):last-child {
margin-bottom: 0;
}
.hex:nth-child(5n+4) {
margin-right: 1%;
margin-left: 0.5%;
}
.hex:nth-child(5n+2) {
margin-left: 1%;
margin-right: 1%;
}
.hex:nth-child(5n+6) {
clear: left;
}
}
@media (max-width: 600px) {
.hex {
width: 49.5%; /* = (100-1) / 2 */
padding-bottom: 57.158%; /* = width / sin(60) */
}
.hex:nth-child(3n+3) {
margin-top: -13.423%;
margin-bottom: -13.423%;
-webkit-transform: translateX(50%) rotate(-60deg) skewY(30deg);
-ms-transform: translateX(50%) rotate(-60deg) skewY(30deg);
transform: translateX(50%) rotate(-60deg) skewY(30deg);
}
.hex:nth-child(3n+3):last-child {
margin-bottom: 0;
}
.hex:nth-child(3n+3) {
margin-left: 0.5%;
}
.hex:nth-child(3n+2) {
margin-left: 1%;
}
.hex:nth-child(3n+4) {
clear: left;
}
}
i would appreciate any kind of help, Thanks
Upvotes: 0
Views: 147
Reputation: 2642
you need to clear top margin in hover
state in .hexIn:hover p
class
.hexIn:hover p {
margin-top:0;
}
https://codepen.io/abdulmalik/pen/XWVgRRN
Upvotes: 0