Search code examples
imagehyperlinkclickable-image

My image-links won't work


I am trying to link an image, in html looks like this:

<a href="#" class="image"><img src="logo.png"></a>

and in CSS I have:

.baraMeniu a.image{
    display:block;
}

Yeah... display:block is just an awkward try to make the image clickable. I am begginer so please take it step by step.

Edit:I forgot to say that my image has the following properties:

.baraMeniu img{
    width:100%;
    height:40em;
    position:absolute;
    z-index:0;/*the image*/
}
.baraMeniu a.image{
    /*the clickable image*/
}
.baraMeniu .st{
    font-size:2em;
    padding-top:0.15em;
    padding-left:0.7em;
    padding-right:0.5em;
    color:orange;
    font-family:'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
    display:inline;
    text-decoration:none;
    float:left;
}
.baraMeniu .dr{
    font-size:2em;
    padding-top:0.15em;
    padding-left:0.7em;
    padding-right:0.5em;
    color:orange;
    font-family:'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
    display:inline;
    text-decoration:none;
    float:right;
}

.baraMeniu #ind{
    text-indent:20px;
}

Solution

  • If you're trying to wrap an <a> tag around your images, you don't need any special tricks.

    <a href="SomeLink.html"><img src="logo.png"></a>
    

    That would work fine.

    You can alter its appearance, hover effects, etc with CSS or JS later.

    EDIT for clarity. Instead of targeting your image through elements on a page, e.g. a.img.classwhatever{} I would just give it a class of its own or slap it in a div for simplicity's sake. Apply CSS to the class or ID.

    <div class="ImageLink">
    <a href="SomeLink.html"><img src="logo.png"></a>
    </div>
    

    As for the Z-index, please be careful. Negative means it's behind everything else.