Comment: You read that right: Use an A tag to wrap block-level elements. Before HTML5, the a tag belonged to the in-line element, while div, h1, p, etc. are block-level elements. If you forcibly wrap, it may be forcibly truncated into multiple A tags. Interested friends can learn more.
Compared to XHTML, HTML5 has caused a series of thoughts through simpler elements, and frankly, this is really a much-needed simplification. One of these simplifications is the ability to wrap block-level elements like div, h tag (h1...h6), and paragraph tag P. You read that right: wrap the block-level element with an A tag (Translator's note: Before HTML5, the a tag belonged to the in-line element, while div, h1, p, etc. were block-level elements. If it was forcibly wrapped, it might be forcibly truncated into multiple a tags. Of course, it is all about the browser.).Sample code:
<body>
<a href="/about-page.php">
<div>
<h1>About David Walsh</h1>
<p>
The original author is 27-year-old Web Developer, and is an expert consultant in jQuery & MooTools. The address is Madison and Wisconsin. He is also the founder and director of Wynq Web Lab. Motto: I don’t design websites, I just let them run.
</p>
</div>
</a>
</body>
That's it. An A tag is wrapped with elements such as div, p, h1. It should be noted that you cannot include another A tag in one A tag, otherwise what happens may be that each browser is inconsistent.
What do you think?
I'm very conflicted about using A tags to contain block-level elements, and it feels like a bunch of junk code when viewing quickly. On the other hand, to avoid this approach, we have been using JavaScript to deal with it. The purpose of clickable elements is to complete tasks and functions. Using native HTML to complete this function is more natural than JS, and sometimes it will definitely be very convenient. What I want to ask is: What do you think of this practice? Can you use it immediately? Please share your views!
(Translator's note: In the translator's project, a team member uses this function. It's sad to see in MyEclipse because it's a bunch of yellow warnings. But objectively speaking, sometimes some codes are really effective, such as <red> or something)