Home > Mobile >  why link using anchor tag not working on image?
why link using anchor tag not working on image?

Time:04-06

I have created the following using html and css. But my link is not working whenever i try to click on the image.I have used the flex box in this an =d have used multiple elements in a row but giving the code for one element only.

<div id="CONTESTS">
    <div >
        <h2>Upcoming Contests</h2> 
        <div >
    <div >
        <div >
            <a href="https://www.codechef.com/contests" >
            <img src="codechef.png" alt="">
        </a>
            <div >
                <!-- CodeChef -->
            </div>
        </div>
    </div>
  </div>
        </div>
    </div>

SCSS code

.contests{
  width:80%;
  margin:auto;
  text-align: center;
  padding-top: 50px;;
}
.course-box{
  // padding:8vw 8vw 0 8vw;
  text-align: center;
  img{
    width: 100%;
    height:100%;
    background-size: cover;
    background-position: center;
  }
}
.list-col{
  flex-basis: 100%;
  border-radius: 10px;
  // margin-bottom: 30px;
  position: relative;
  overflow: hidden;
}
.list-col img{
  width: 100%;
}
.layer{
  // background: rgba(226, 0, 0, 0.7);
  background: transparent;
  height:100%;
  width:100%;
  position: absolute;
  top:0px;
  left:0;
  transition: 0.5s;
}
.layer:hover{
  cursor: pointer;
  background: rgba(255, 0, 0, 0.7);
}
.same-row{
  display: flex;
  flex-wrap: wrap;
}
.same-row > div {
  
  flex: 25%; /* or - flex: 0 50% - or - flex-basis: 50% - */
  /*demo*/
  // box-shadow: 0 0 0 1px black;
  // box-shadow: 2.5px 5px rgb(164, 164, 164);
  margin-bottom: 10px;
  margin-top:40px;
  margin-left: 20px;
  border-radius: 10px;
}

My main aim is to direct me to the page wheneevr i click on the image . I am not able to figure out the error in my code . Any help would be appreciated.

CodePudding user response:

Perhaps you'd like to try onClick event in img tag

<img src="codechef.png" alt="" onclick="window.open('https://www.codechef.com/contests')">

Regards

CodePudding user response:

just add the img inside the anchor then style the image as you wish and whenever you clock on it it'll take you to the URL.

<a href="https://www.codechef.com/contests"><img src="codechef.png" alt=""> </a>
           

  • Related