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

Why won't the text in this span underline on hover?

I am trying to get the span to underline the text on hover over anywhere in the image, but it won’t work. I can change the color on hover, but not the text-decoration. Is it possible to make it underlined? My html and css are as follows:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
    <title>News</title>
    <meta content="" name="description" />
    <meta content="" name="keywords" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"    rel="stylesheet"/>
    <link href="style.css" rel="stylesheet" />
  </head>

  <body>
    <div class="contain">
      <div class="col-6 main__story">
        <a href="https://www.google.com">
          <div class="myfilter">
            <img
              id="main__story__img"
              class="img-fluid" 
              src="https://media.istockphoto.com/photos/handsome-guy-and-an-attractive-girl-kiss-each-other-near-a-large-picture-id997518432"
            />
          </div>
          <span id="main__story__span">This is the story of a ...</span>
        </a>
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"></script>
  </body>
</html>
.main__story a {
  color: white;
}

.main__story a:hover {
  text-decoration: underline;
  color: blue;
}

.main__story span {
   display:block;
   font-weight: bold;
   font-size: 40px;
}

#main__story__img {
  border-radius: 20px;
}

.main__story {
  position: relative;
}

span {
  position: absolute;
  bottom: 0;
  margin-bottom: 30px;
  margin-left: 20px;
}

.myfilter{
  position: relative;
}

.myfilter:after{
  position: absolute; content: ''; display: block; top: 0; left: 0; height: 100%; width: 100%;
  background: linear-gradient(to bottom,rgba(245, 245, 245, 0) 0%, rgba(0, 0, 0, 0.54) 100%);
  mix-blend-mode: darken;
  border-radius: 20px;
}

.contain {
  margin-left: 135px;
  margin-right: 135px;
  margin-top: 20px;
}

Long time user, first time poster, as the issue doesn’t make sense to me, that I can change some attributes, but not others. Any help would be greatly appreciated.

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

>Solution :

You are selecting and changing styles of a tag in your :hover. You need to select the child span inside a:hover as follows:

.main__story a:hover span{
  text-decoration: underline;
  color: blue;
}
.main__story a {
  color: white;
}

.main__story a:hover span{
  text-decoration: underline;
  color: blue;
}


.main__story span {
   display:block;
   font-weight: bold;
   font-size: 40px;
}

#main__story__img {
  border-radius: 20px;
}

.main__story {
  position: relative;
}

span {
  position: absolute;
  bottom: 0;
  margin-bottom: 30px;
  margin-left: 20px;
}

.myfilter{
  position: relative;
}

.myfilter:after{
  position: absolute; content: ''; display: block; top: 0; left: 0; height: 100%; width: 100%;
  background: linear-gradient(to bottom,rgba(245, 245, 245, 0) 0%, rgba(0, 0, 0, 0.54) 100%);
  mix-blend-mode: darken;
  border-radius: 20px;
}

.contain {
  margin-left: 135px;
  margin-right: 135px;
  margin-top: 20px;
}
<body>
    <div class="contain">
      <div class="col-6 main__story">
        <a href="https://www.google.com">
          <div class="myfilter">
            <img
              id="main__story__img"
              class="img-fluid" 
              src="https://media.istockphoto.com/photos/handsome-guy-and-an-attractive-girl-kiss-each-other-near-a-large-picture-id997518432"
            />
          </div>
          <span id="main__story__span">This is the story of a ...</span>
        </a>
      </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js"></script>
  </body>
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