skip to Main Content

I have made a custom title box and the old one still displays along with the new one when I hover over my icons.
I have provided an
Image of what is happening. If you look at the image you can see a black box with "Homepage" and white text above the icon. I want the white text only.

header {
  background-color: #195190;
  color: #fff;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.nav-buttons {
  display: flex;
  gap: 30px;
  justify-content: flex-end;
  animation: slideInL 1s ease-in-out;
}

.nav-button {
  background-color: transparent;
  color: #fff;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.nav-button:hover {
  color: #ccc;
}

li {
  list-style-type: none;
  position: relative;
  display: inline-block;
  margin-top: 20px;
}

li[title]:hover::after {
  content: attr(title);
  position: absolute;
  width: 120px;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
  background-color: none;
  color: #fff;
  text-align: center;
  padding: 5px 0;
}
<head>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
  />
</head>
<body>
  <header>
    <ul class="nav-buttons">
      <li title="Homepage">
        <a id="navhomepage" href="./index.html" class="nav-button">
          <span class="material-symbols-outlined">
            home
          </span>
        </a>
      </li>
      <li title="Photopage">
        <a id="navphotopage" href="./Photosite/index.html" class="nav-button">
          <span class="material-symbols-outlined">
            photo_camera
          </span>
        </a>
      </li>
      <li title="Startside">
        <a id="navstartside" href="./Startside/index.html" class="nav-button">
          <span class="material-symbols-outlined">
            web
          </span>
        </a>
      </li>
      <li title="Contact">
        <a id="navcontact" href="#Contact" class="nav-button">
          <span class="material-symbols-outlined">
            contact_page
          </span>

I tried disabling the title using js but that ended up disabling both of them.

2

Answers


  1. Test thist

    li[title]:hover::after {
                      content: "";
                      position: absolute;
                      width: 120px;
                      bottom: 100%;
                      left: 50%;
                      margin-left: -60px;
                      background-color: #195190;
                      color: #fff;
                      text-align: center;
                      padding: 5px 0;
                      z-index: 1; 
        }
                    
        li[title]:hover::after {
        }
    

    Edited:

    Html:

    <head>
      <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200">
    </head>
    <body>
      <header>
        <ul class="nav-buttons">
          <li>
            <a id="navhomepage" href="./index.html" class="nav-button">
              <span class="material-symbols-outlined">
                home
              </span>
              <span class="nav-text">Homepage</span>
            </a>
          </li>
          <li>
            <a id="navphotopage" href="./Photosite/index.html" class="nav-button">
              <span class="material-symbols-outlined">
                photo_camera
              </span>
              <span class="nav-text">Photopage</span>
            </a>
          </li>
          <li>
            <a id="navstartside" href="./Startside/index.html" class="nav-button">
              <span class="material-symbols-outlined">
                web
              </span>
              <span class="nav-text">Startside</span>
            </a>
          </li>
          <li>
            <a id="navcontact" href="#Contact" class="nav-button">
              <span class="material-symbols-outlined">
                contact_page
              </span>
              <span class="nav-text">Contact</span>
            </a>
          </li>
        </ul>
      </header>
    </body>
    

    Css

    header {
      background-color: #195190;
      color: #fff;
      padding: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
    }
    
    .nav-buttons {
      display: flex;
      gap: 30px;
      justify-content: flex-end;
      animation: slideInL 1s ease-in-out;
    }
    
    .nav-button {
      background-color: transparent;
      color: #fff;
      border: none;
      font-size: 16px;
      cursor: pointer;
      position: relative;
    }
    
    .nav-text {
      display: none;
      position: absolute;
      width: 120px;
      bottom: 100%;
      left: 50%;
      margin-left: -60px;
      background-color: none;
      color: #fff;
      text-align: center;
      padding: 5px 0;
      white-space: nowrap; 
    }
    
    .nav-button:hover .nav-text {
      display: block;
    }
    
    .nav-button:hover {
      color: #ccc;
    }
    
    li {
      list-style-type: none;
      position: relative;
      display: inline-block;
      margin-top: 20px;
    }
    
    Login or Signup to reply.
  2. You can "patch" your page with javascript, setting a blank title to the a link inside the li.

    let elements = document.querySelectorAll(".nav-buttons li[title] > a");
    
    for (element of elements) {
        console.log("discarding title of", element.id);
        element.title = "";
    }
    header {
        background-color: #195190;
        color: #fff;
        padding: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
    }
    
    .nav-buttons {
        display: flex;
        gap: 30px;
        justify-content: flex-end;
        animation: slideInL 1s ease-in-out;
    }
    
    .nav-button {
        background-color: transparent;
        color: #fff;
        border: none;
        font-size: 16px;
        cursor: pointer;
    }
    
    .nav-button:hover {
        color: #ccc;
    }
    
    li {
        list-style-type: none;
        position: relative;
        display: inline-block;
        margin-top: 20px;
    }
    
    li[title]:hover::after {
        content: attr(title);
        position: absolute;
        width: 120px;
        bottom: 100%;
        left: 50%;
        margin-left: -60px;
        background-color: none;
        color: #fff;
        text-align: center;
        padding: 5px 0;
    }
    <head>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" />
    </head>
    
    <body>
        <header>
            <ul class="nav-buttons">
                <li title="Homepage">
                    <a id="navhomepage" href="./index.html" class="nav-button">
                        <span class="material-symbols-outlined">
                            home
                        </span>
                    </a>
                </li>
                <li title="Photopage">
                    <a id="navphotopage" href="./Photosite/index.html" class="nav-button">
                        <span class="material-symbols-outlined">
                            photo_camera
                        </span>
                    </a>
                </li>
                <li title="Startside">
                    <a id="navstartside" href="./Startside/index.html" class="nav-button">
                        <span class="material-symbols-outlined">
                            web
                        </span>
                    </a>
                </li>
                <li title="Contact">
                    <a id="navcontact" href="#Contact" class="nav-button">
                        <span class="material-symbols-outlined">
                            contact_page
                        </span>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search