Home >Web Front-end >CSS Tutorial >How to Make an Entire Div Clickable Without JavaScript?

How to Make an Entire Div Clickable Without JavaScript?

DDD
DDDOriginal
2024-11-09 19:37:02502browse

How to Make an Entire Div Clickable Without JavaScript?

Making a 'div' Whole Clickable with HTML and CSS

You seek a solution to make an entire 'div' clickable without JavaScript. While wrapping 'div's within 'a' tags may seem like a viable option, it raises HTML validation concerns. Here's a more compliant approach:

Using a Fill-Div Link

Create a link inside the 'div' and style it to fill the entire 'div' area. This will give the illusion that the 'div' itself is clickable.

CSS:

#my-div {
    background-color: #f00;
    width: 200px;
    height: 200px;
}
a.fill-div {
    display: block;
    height: 100%;
    width: 100%;
    text-decoration: none;
}

HTML:

<div>

By making the link a block element and setting its height and width to 100%, it covers the entire 'div' space. When clicked, the link will redirect to the specified page, making the 'div' appear clickable.

The above is the detailed content of How to Make an Entire Div Clickable Without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn