简体   繁体   中英

Link into full div - html and css

Some text
.sliderPart { width: 25%; height: 100%; } .sliderPart a { display:block; position:relative; text-decoration:none; height: 100%; font: 1.3em Arial, Sans-serif; }

How can I make my link clickable for all div-area?

The easiest thing is to remove the div altogether:

<a href="#computers" class="sliderPart">
   <strong>Some text</strong>
</a>

a.sliderPart {
  ...
}

Try this:

$(".trigger").click(function() {
    window.location = $(this).find("a").attr("href");
    return false;
});

..you'd also need to give cursor: pointer to the clickable element.

Put the link outside the div. You can make an anchor tag act similarly to a div. Like you're doing in the css you posted.

For dropdown lists, I use the following method a lot...

If you're not opposed to using scripts, you can make the div itself a proxy of sorts, so that if you click anywhere on the div, the first link within that div is subsequently clicked automatically.

$(".sliderPart").bind("click", function(){
  $("a:first", this).trigger("click");
});

Of course you would want to update your styles for the div when you mouse over it to indicate the entire thing is clickable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM