Skip to content Skip to sidebar Skip to footer

How To Set Background Color For A Boxed Link?

I have a link on my website with borders.HTML:

Explore our menu

CSS: #hero4 { border:1px solid white; border-radi

Solution 1:

Then just set the hover to the #hero4:

#hero4:hover { /*removed a*/background-color:grey;
}

You can use :hover for any element.

Solution 2:

You can move the style from the <p> into the <a> tag, and also set it to display:block;.

#hero4a {
  border: 1px solid blue;
  border-radius: 5px;
  width: 150px;
  height: 30px;
  margin: auto;
  display: block; /*added*/text-align: center; /*extra: center text horizontally*/line-height: 30px; /*extra: center text vertically*/
}
#hero4a:hover {
  background-color: grey;
}
<pid="hero4"><ahref="menu.html">Explore our menu</a></p>

Solution 3:

Don't use hover over for anchor tag a, instead use it for the paragraph tag p, as p is the parent for the anchor tag.

Code

#hero4:hover {
  background-color: grey;
}

EXAMPLE FIDDLE

Post a Comment for "How To Set Background Color For A Boxed Link?"