How do I make entire div a link? [duplicate]


Tags: html,css

Problem :

This question already has an answer here:

I have a div like this <div class="xyz"></div> and all the content in that div is in the css. How do I make that div into a link? I tried wrapping the a tag around it, but that didn't seem to work.

Thanks!!



Solution :

You need to assign display: block; property to the wrapping anchor. Otherwise it won't wrap correctly.

<a style="display:block" href="http://justinbieber.com">
  <div class="xyz">My div contents</div>
</a>

    CSS Howto..

    How to keep border inside to take ribbon over to div?

    How does google do the barrel roll?

    How to center this popup text box

    How to make image 3D using CSS

    How can .css('display') be block, [0].hidden be false, and .is(':hidden') be true?

    How to adjust the height of the footer automatically

    How to make a background text appear under youtube video?

    How to Prevent Opacity for Sub Div using Jquery

    How to center an input field in HTML / CSS / Bootstrap

    How to allow scroll on mobile

    How to make the table use multiple lines on long text using css

    Slideshow using Jquery, images do not fit window

    How can I shift up a div and all divs that follow it?

    Understanding float and how and when to float an element in CSS3?

    How do I stop css pushing
  • to the right?
  • How to make a div appear when hyperlink is clicked once and disappear when hyperlink is clicked a second time? Can this be repeated?

    How to convert a HTML/CSS template to haml/sass template? [closed]

    How to add a line break inside with CSS?

    How can I avoid my headers and footers being broken when displaying content wider than the viewport?

    How Do I set this PHP printed HTML form to stay within

    tags?

    How to change font-size of multiple elements using jQuery

    How to make separating lines/borders in a table disappear with CSS?

    Javascript - How to alter a property of a css class

    How to display data from a file on website load? [closed]

    How can i draw a box using css like the answer box in stackoverflow?

    How can I apply CSS to a link if at least one input is not original, and undo that change if all inputs are original?

    How should I do this in CSS?

    Show/Hide images based on tab selection

    How i can put a picture above a border in css?

    CSS table: How to position action buttons left to each row