Search code examples
htmlcsshovercss-animationsz-index

Hover function interfering with a href tag


I have this code right here, and what I am trying to accomplish is clickable icons but it seems like the hover function I have is not allowing me to click on the icons. I have already tried z-index but that doesn't seem to work.

body {
	background-image: url("background.png");
	background-size: 100%;
	background-repeat: no-repeat;
	background-color: rgb(19,68,97)
}
h1 {
	font-family: 'Libre Baskerville', serif;
	font-size: 50px;
	padding: 0px 0px 0px 0px;
	display: inline;
}
p {
	font-family: 'Quicksand', sans-serif;
	font-size: 15px;
	padding: 0px 0px 0px 0px;
	display: inline;
}
.boxAnimation {
	width: 520px;
	height: 300px;
	position: relative;
	background: rgba(255,255,255,0.3);
	display: inline-block;
	margin: 0 10px;
	cursor: pointer;
	color: #fff;
	box-shadow: inset 0 0 0 3px rgba(192,192,192,1);
	-webkit-transition: background 0.4s 0.5s;
	transition: background 0.4s 0.5s;
	z-index: 0;
	margin: center;
}
svg {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 0;
}
svg line {
	stroke-width: 6;
	stroke: #fff;
	fill: none;
	stroke-dasharray: 250;
	-webkit-transition: -webkit-transform .6s ease-out;
	transition: transform .6s ease-out;
	z-index: 0;
}
div:hover {
	background: rgba(255,255,255,0);
	-webkit-transition-delay: 0s;
	transition-delay: 0s;
}
div:hover svg line.top {
	-webkit-transform: translateX(-400px);
	transform: translateX(-400px);
}
div:hover svg line.bottom {
	-webkit-transform: translateX(400px);
	transform: translateX(400px);
}
div:hover svg line.left {
	-webkit-transform: translateY(400px);
	transform: translateY(400px);
}
div:hover svg line.right {
	-webkit-transform: translateY(-400px);
	transform: translateY(-400px);
}
.icons {
	z-index: 5;
}
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<script src="https://use.fontawesome.com/e0037e252a.js"></script>
<body>
<center>
  <div class="boxAnimation"> <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
    <line class="top" x1="0" y1="0" x2="1560" y2="0"/>
    <line class="left" x1="0" y1="360" x2="0" y2="-720"/>
    <line class="bottom" x1="520" y1="360" x2="-1040" y2="360"/>
    <line class="right" x1="520" y1="0" x2="520" y2="1080"/>
    </svg>
    <h1>Donia Amer</h1>
    <br>
    <p>&lt; insert title &gt;</p>
    <br>
    <br>
    <div class="icons"> <a href="www.google.com"> <i class="fa fa-linkedin-square fa-inverse" aria-hidden="true" style="font-size:45px;"></i></a> &nbsp; 	&nbsp; &nbsp; 	&nbsp; <i class="fa fa-github-square" aria-hidden="true" style="font-size:45px;"></i> &nbsp; 	&nbsp; &nbsp; 	&nbsp; <i class="fa fa-twitter-square" aria-hidden="true" style="font-size:45px;"></i> &nbsp; 	&nbsp; &nbsp; 	&nbsp; <i class="fa fa-envelope-square" aria-hidden="true" style="font-size:45px;"></i> </div>
  </div>
</center>
</body>


Solution

  • Add position:relative to .icons The z-index property specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order. Note: z-index only works on positioned elements (position:absolute, position:relative, or position:fixed).

    here is the example

    body {
    	background-image: url("background.png");
    	background-size: 100%;
    	background-repeat: no-repeat;
    	background-color: rgb(19,68,97)
    }
    h1 {
    	font-family: 'Libre Baskerville', serif;
    	font-size: 50px;
    	padding: 0px 0px 0px 0px;
    	display: inline;
    }
    p {
    	font-family: 'Quicksand', sans-serif;
    	font-size: 15px;
    	padding: 0px 0px 0px 0px;
    	display: inline;
    }
    .boxAnimation {
    	width: 520px;
    	height: 300px;
    	position: relative;
    	background: rgba(255,255,255,0.3);
    	display: inline-block;
    	margin: 0 10px;
    	cursor: pointer;
    	color: #fff;
    	box-shadow: inset 0 0 0 3px rgba(192,192,192,1);
    	-webkit-transition: background 0.4s 0.5s;
    	transition: background 0.4s 0.5s;
    	z-index: 0;
    	margin: center;
    }
    svg {
    	position: absolute;
    	top: 0;
    	left: 0;
    	z-index: 0;
    }
    svg line {
    	stroke-width: 6;
    	stroke: #fff;
    	fill: none;
    	stroke-dasharray: 250;
    	-webkit-transition: -webkit-transform .6s ease-out;
    	transition: transform .6s ease-out;
    	z-index: 0;
    }
    div:hover {
    	background: rgba(255,255,255,0);
    	-webkit-transition-delay: 0s;
    	transition-delay: 0s;
    }
    div:hover svg line.top {
    	-webkit-transform: translateX(-400px);
    	transform: translateX(-400px);
    }
    div:hover svg line.bottom {
    	-webkit-transform: translateX(400px);
    	transform: translateX(400px);
    }
    div:hover svg line.left {
    	-webkit-transform: translateY(400px);
    	transform: translateY(400px);
    }
    div:hover svg line.right {
    	-webkit-transform: translateY(-400px);
    	transform: translateY(-400px);
    }
    .icons {
    	z-index: 5;
    	position:relative;
    }
    <link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
    <script src="https://use.fontawesome.com/e0037e252a.js"></script>
    <body>
    <center>
      <div class="boxAnimation"> <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
        <line class="top" x1="0" y1="0" x2="1560" y2="0"/>
        <line class="left" x1="0" y1="360" x2="0" y2="-720"/>
        <line class="bottom" x1="520" y1="360" x2="-1040" y2="360"/>
        <line class="right" x1="520" y1="0" x2="520" y2="1080"/>
        </svg>
        <h1>Donia Amer</h1>
        <br>
        <p>&lt; Developer + Algorithm Enthusiast &gt;</p>
        <br>
        <br>
        <div class="icons"> <a href="www.google.com"> <i class="fa fa-linkedin-square fa-inverse" aria-hidden="true" style="font-size:45px;"></i></a> &nbsp; 	&nbsp; &nbsp; 	&nbsp; <i class="fa fa-github-square" aria-hidden="true" style="font-size:45px;"></i> &nbsp; 	&nbsp; &nbsp; 	&nbsp; <i class="fa fa-twitter-square" aria-hidden="true" style="font-size:45px;"></i> &nbsp; 	&nbsp; &nbsp; 	&nbsp; <i class="fa fa-envelope-square" aria-hidden="true" style="font-size:45px;"></i> </div>
      </div>
    </center>
    </body>