Home > Net >  Is there a way to make the ":hover" background color wider?
Is there a way to make the ":hover" background color wider?

Time:10-05

I'm trying to build a header for my website and it's pretty much finished but I want to make a hover effect and change the background color. However it looks pretty ugly. I want to be able to make the hover background color wider, is there a way to do it?

.header {
  background-color: rgb(51, 51, 51);
  width: 100%;
  height: 3rem;
  position: fixed;
  z-index: 1;
}

.header-lines {
  color: #fff;
  font-family: "Noto Sans Display", sans-serif;
  font-style: none;
  text-decoration: none;
}

.header-list {
  list-style: none;
  margin: 0;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  line-height: 50px;
}

.header-item {
  margin-left: 2rem;
  font-style: none;
  text-decoration: none;
  color: #fff;
}

.header-item:hover {
  background-color: rgb(24, 24, 24);
}
<div class="header">
  <div class="header-lines">
    <ul class="header-list">
      <a target="_blank" href="#" class="header-item">youTunes</a>
      <a target="_blank" href="#" class="header-item">Overview</a>
      <a target="_blank" href="#" class="header-item">Music</a>
      <a target="_blank" href="#" class="header-item">Video</a>
      <a target="_blank" href="#" class="header-item">Gift Cards</a>
    </ul>
    <a href="#"></a>
  </div>
</div>

CodePudding user response:

you can try to make the width wider, something like:

.header-item
{
  margin-left: 2rem;
  font-style: none;
  text-decoration: none;
  color: #fff;
  width: 25%;
}

CodePudding user response:

Try this instead

.header-item:hover {
transition: 0.5s ease;
color: #0088a9;
}

and also add text-transform:uppercase; in .header-item

CodePudding user response:

To make a hovered background larger than the actual element you can put a pseudo element on the element, make it a bit wider and higher and position it centered on the element itself.

This snippet makes the background magenta just so you can definitely see the effect.

.header {
  background-color: rgb(51, 51, 51);
  width: 100%;
  height: 3rem;
  position: fixed;
  z-index: 1;
}

.header-lines {
  color: #fff;
  font-family: "Noto Sans Display", sans-serif;
  font-style: none;
  text-decoration: none;
}

.header-list {
  list-style: none;
  margin: 0;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  line-height: 50px;
}

.header-item {
  margin-left: 2rem;
  font-style: none;
  text-decoration: none;
  color: #fff;
  position: relative;
}

.header-item:hover::after {
 z-index: -1;
  background-color: rgb(24, 24, 24);
  background-color: magenta;
  content: '';
  width: 110%;
  height: 110%;
  position: absolute;
  display: inline-block;
  top: -5%;
  left: -5%;
}
<div class="header">
  <div class="header-lines">
    <ul class="header-list">
      <a target="_blank" href="#" class="header-item">youTunes</a>
      <a target="_blank" href="#" class="header-item">Overview</a>
      <a target="_blank" href="#" class="header-item">Music</a>
      <a target="_blank" href="#" class="header-item">Video</a>
      <a target="_blank" href="#" class="header-item">Gift Cards</a>
    </ul>
    <a href="#"></a>
  </div>
</div>

CodePudding user response:

I improved your code. Here is the result.

.header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Sans Display", sans-serif;
  background: #333333;
  position: fixed;
  width: 100%;
  color: white;
}

.header-item {
  color: inherit;
  text-decoration: none;
  padding: 20px 19px;
  outline-offset: -4px;
}

.header-item:hover {
  background: #111;
}

.header-lines:hover {
  padding: 0;
}

.header-list {
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-item:focus {
  outline: 1px solid #606060;
}
<div class="header">
  <a target="_blank" href="#" class="header-item">youTunes</a>
  <a target="_blank" href="#" class="header-item">Overview</a>
  <a target="_blank" href="#" class="header-item">Music</a>
  <a target="_blank" href="#" class="header-item">Video</a>
  <a target="_blank" href="#" class="header-item">Gift Cards</a>
  </ul>
</div>

  • Related