4

I want to make my Logo in my header clickable and link to the homepage but i don't know exactly how to do this right.

My code:

Navigation menu:

HTML

<div id="myMenu">
            <div class="myWrapper">
                <nav>
                    <div class="logo"></div>
                </nav>
            </div>
        </div>

CSS

#myMenu
{
    width: 100%;
    height: 30px;
    z-index: 999; 
    background-color: #252e30;

}
.myWrapper
{
    max-width: 660px;
    margin: 0 auto;
}

.logo
{
    display: inline-block;
    width: 156px;
    height: 30px;
        margin-top: 5px;
        background-size: auto 43px;
    background-image: url(../images/mylogo.png);
    background-repeat: no-repeat;
}

I want my logo make clickable and link to the page: Homepage.cshtml

Jack Allen
  • 549
  • 2
  • 5
  • 19
Maarten Verstraten
  • 139
  • 1
  • 5
  • 11

6 Answers6

17

Instead of using CSS to set your logo as a background image, what would be wrong with using the img tag, surrounding by a link? Like so:

<div id="myMenu">
  <div class="myWrapper">
    <nav>
    <a href="/"><img src="../images/mylogo.png" height="30" width="156" /></a>
    </nav>
  </div>
</div>

This has the added benefit of being more accessible (especially if you use an alt attribute on your logo), which makes search engine bots happier. Image content that conveys meaning to the user should never bet set using CSS.

Jonah Bishop
  • 12,279
  • 6
  • 49
  • 74
1

You better use an image wrapped in an anchor-tag.

But else this should work:

<div class="logo" onclick="window.location.href='homepage.html'"></div>
Tim Baas
  • 6,035
  • 5
  • 45
  • 72
0

You can't make a background image a link. Move the image into the HTML code, and then make that a link.

  • 1
    This is misleading. An element can have a background image and be linked, visually making the background image the link. – MikeSmithDev Feb 08 '13 at 15:44
0
<div id="myMenu">
         <div class="myWrapper">
             <nav>
                 <a href="Homepage.cshtml"><div class="logo"></div></a>
             </nav>
         </div>
    </div>
Jack Allen
  • 549
  • 2
  • 5
  • 19
0

also it can be like following example:

<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #000000;">     
      <div class="logo" >
            <a href="{% url 'major' %}">
                <img src="{% static 'images/logo.gif' %}" style="width:80px;height:80px;"/>
            </a>
      </div>
      .....
</nav>
Alexander
  • 29
  • 6
-1

Use an <a> instead of the <div> for the logo..

kleinfreund
  • 6,546
  • 4
  • 30
  • 60
Roger C
  • 338
  • 1
  • 5