Home >Web Front-end >CSS Tutorial >How to Create a Clickable Div with Variable Image Sizes in HTML/CSS?

How to Create a Clickable Div with Variable Image Sizes in HTML/CSS?

Susan Sarandon
Susan SarandonOriginal
2024-10-30 03:00:29871browse

How to Create a Clickable Div with Variable Image Sizes in HTML/CSS?

Creating an Entire Div Hyperlink in HTML/CSS

Problem:

Creating a hyperlink for a complete div (#parentdivimage) with varying image sizes (all under 180x235). The div has a border and vertically-aligned images.

Solution:

There are three primary options to consider:

1. Semantically Incorrect (But Functional):

<code class="html"><a href="http://google.com">
  <div>...</div>
</a></code>

This method technically works but violates HTML semantics.

2. Semantically Correct (Using JS):

<code class="html"><div style="cursor: pointer;" onclick="window.location='http://google.com';">...</div></code>

This method is semantically correct but relies on JavaScript for functionality.

3. Semantically Correct (Non-Div Link):

<code class="html"><a href="http://google.com">
  <span style="display: block;">...</span>
</a></code>

This method is both semantically correct and functional, but it changes the wrapper element from a div to a span.

The above is the detailed content of How to Create a Clickable Div with Variable Image Sizes in HTML/CSS?. 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