Search code examples
htmlcssanchor

I assistance with with div tags and css with adding anchor tags


I made a box with <div class="box"></div> then I styled it in css with .box {} but I want to make it so when I click the box, it brings me to another page. Here is my current code.

.box18 {
    width: 240px; height: 230px;
    outline: 5px solid black;
    position: absolute; top: 450px; right: 140px;
    background-image: url(wfc.jpg);
    background-position: top;
}
<div class="box18" title="Credit: Hasbro/Takara"></div>

I tried to add an anchor tag within the div or within the css styling but it didnt work and made the text dissapear.


Solution

  • You just need to wrap your div in an anchor tag.

    .box18 {
        width: 240px; height: 230px;
        outline: 5px solid black;
        position: absolute; top: 450px; right: 140px;
        background-image: url(wfc.jpg);
        background-position: top;
    }
    <a href="https://stackoverflow.com" target="_blank">
      <div class="box18" title="Credit: Hasbro/Takara"></div>
    </a>