Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove link from only one element?

I have two div in one a. I want link to only first div.

this is code:

HTML

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./style.css">
    <title>Document</title>
</head>
<body>
    <a href="#">
        <div id="div1"></div>
        <div id="div1info"></div>
    </a>
</body>
</html>

CSS

#div1 {
  width: 15em;
  height: 25em;
  background-color: rgb(214, 214, 214);
  border-radius: 5px;
  position: fixed;
}

#div1info {
  width: 30em;
  height: 25em;
  background-color: rgb(0, 0, 0);
  border-radius: 5px;
  opacity: 0;
  margin-left: 16em;
  transition: 1s;
}

#div1:hover + #div1info {
  width: 30em;
  height: 25em;
  background-color: rgb(10, 9, 9);
  border-radius: 5px;
  opacity: 100%;
  margin-left: 16em;
  transition: 1s;
}

I try change this:

<a href="#">
        <div id="div1"></div>
        <div id="div1info"></div>
</a>

To this

<a href="#">
        <div id="div1"></div>
</a>
<div id="div1info"></div>

but then CSS didn’t work.

How I can link only first div. with any language, CSS, jQuery, JS…

If there no way to do this without changing HTML structure, change it lightly.

>Solution :

The CSS "didn’t work" because when you change the markup structure then you also need to change any style selectors which depend on that markup structure. In this case specifically this one:

#div1:hover + #div1info

The #div1info is no longer a sibling of #div1. But is is a sibling of the surrounding a:

a:hover + #div1info

For example:

#div1 {
  width: 15em;
  height: 25em;
  background-color: rgb(214, 214, 214);
  border-radius: 5px;
  position: fixed;
}

#div1info {
  width: 30em;
  height: 25em;
  background-color: rgb(0, 0, 0);
  border-radius: 5px;
  opacity: 0;
  margin-left: 16em;
  transition: 1s;
}

a:hover + #div1info {
  width: 30em;
  height: 25em;
  background-color: rgb(10, 9, 9);
  border-radius: 5px;
  opacity: 100%;
  margin-left: 16em;
  transition: 1s;
}
<a href="#">
  <div id="div1"></div>
</a>
<div id="div1info"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading