can i use Href on li b?

2.5k views Asked by At

preview of website homepage

my first problem is that the link wont work for li b

is this something impossible?

I want to move the navbuttons down to align with the logo. Also, I want to change the logo img for every navbutton (see img)

<ul>

  <li><a href="home"><img src='images/logo1.jpg' width='550 height='400' onmouseover="this.src='images/logo.jpg';" onmouseout="this.src='images/logo1.jpg';" /></a></li>
  <li><b href="music"><img src='images/m.jpg'/></b></li>
  <li><b href="news"><img src='images/j.jpg'/></b></li>
  <li><b href="contact"><img src="images/s.jpg"/></b></li>
  <li><b href="about"><img src="images/g.jpg"/></b></li>
  <li><b href="contact"><img src="images/p.jpg"/></b></li>
  <li><b href="about"><img src="images/c.jpg"/></b></li>
</ul>


ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;}
li {
    float: left;}

li a {
    display: block;
    padding: 0px 0px;
    text-decoration: none;}

li b {
    display: block;
    padding: 280px 0px 0px 0px ;
    text-decoration: none;}

li b:hover{

Hope someone can help, though i am really noob still

2

There are 2 answers

2
JDB On

href is what's known as an "attribute". Elements (like <a> and <b>) define and support their own attributes, so you can't just use an attribute that "works" with one element and use it on another. That said, some attributes, like class, have nearly universal support (meaning they are supported by almost all elements).

The short answer to your question is "no"... the <b> element does not support the href attribute.

You can, however, wrap most elements in an <a> tag to turn it into a link, like so:

<a href="http://www.google.com"><b>Go To Google</b></a>

Note that the href attribute must be a URL or URI if you want the link to actually work. home is not a URL, and thus the link won't work as you'd expect. See MDN's "What is a URL?" for more information.

For future reference, check out MDN's HTML element reference. There, you will find a complete list of elements and the attributes they support.

0
Arathi Sreekumar On

No you cannot use href with b.

As per the mdn reference: https://developer.mozilla.org/en/docs/Web/HTML/Element/b

which says standard attributes only, which are stated here: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes

I would suggest converting all your b tags to a. If you want to style them to look like b, you can do so using css.

Using the right html element for designed purpose is a best practice.

Please see What are the benefits of using semantic HTML?