to learn HTML more in depth I’m building the website of a famous fashion brand, trying to emulate and build all the functions that I see with the HTML knowledge that I have.
I’m coding a part of the website in which a whole <div>
is clickable, including a button, some text and an image.
The problem is that all the text that is included in this div (that is, in its turn, included in an Anchor element), becomes a link.
How do I make the text appear normal?
This is what I’ve tried so far.
<section class="twoModels">
<a href="#">
<div class="first-model">
<div class="first-model-photo">
<img src="/img/first-model.jpg" alt="Our Coats" title="Our coats" width="375" loading="lazy">
</div>
<div class="first-model-text">
<h3><!--This is the part of text I want to look normal-->Dress Code: Maglieria</h3>
</div>
<div class="first-model-cta">
<button>Scopri di più</button>
</div>
</div>
</a>
</section>
2
Answers
First, you don’t need to use the button tag to make something look like a button. You can use basic CSS for that. Also, you don’t want to have a button as a child of an anchor, that could have unexpected results.
To make text not have underlines, you can use
text-decoration:none
For my answer, I converted your button to a div and styled it via CSS. I also set the text to text-decoration:none so the text didn’t have an under.
To make only specific parts of a clickable and leave the rest of the text looking normal, you can use nested anchor tags and CSS to style the text differently. Here’s how you can modify your HTML and CSS to achieve this:
In this modified code, we’ve wrapped only the "Maglieria" text within its own tag. This will make only the "Maglieria" text a clickable link, and the rest of the text will appear normal. Additionally, we’ve added some CSS to style the link and its hover state.
Make sure to replace #YourDesiredTextColor with the color you want for the link text.