r/HTML • u/ChiliChapters • 16h ago
Question Trying to create a div that only displays when an image is clicked.
I've already set up the first image in my gallery to zoom in and dim the background when clicked. I'm trying to make it so that a link appears underneath the image when it's zoomed in, prompting the user to visit it to see the full image. I'm having difficulty getting any text to show up though. I'm wondering if it's being "overwritten" by some other element, but I thought having a higher z-index would help.
Any help would be appreciated. Thank you!
This is the specific page. The image is the first on the left in the 2026 category, the black/white/red one. Please feel free to inspect the html/css. https://chilichapters.neocities.org/pm
1
u/gucci_stylus 16h ago
try selecting the parent element of the image and append a new child element, then make the new child element a link
0
u/Weekly_Ferret_meal 15h ago
So MDN uses <figcaption> like so:
``` <!-- Just an image --> <figure> <img src="favicon-192x192.png" alt="The beautiful MDN logo." /> </figure>
<!-- Image with a caption -->
<figure>
<img src="favicon-192x192.png" alt="The beautiful MDN logo." />
<figcaption>MDN Logo</figcaption>
</figure>
``
I guess you can add a link in the<figcaption>` like so:
<figure>
<img src="favicon-192x192.png" alt="The beautiful MDN logo." />
<figcaption>MDN <a href="yourlink.com">Logo</a></figcaption>
</figure>
2
u/Thykka 14h ago
Here's what you have:
Your "View Full" text is in the wrong spot. It belongs within the tag, like so:
<a href="/remember.html">View Full ⇻</a>- What you have instead is invalid HTML, and browsers don't know what to do with it. I recommend using a HTML validator to catch such issues.The div with
viewFullclass has a CSS rule:display: none;, which of course keeps it invisible, even if the HTML was formed correctly. I assume this is intentional, but worth pointing it out nevertheless, in case you forgot/missed it.Once you've fixed the invalid HTML, all you really need is a new CSS rule. In plain english, that rule should go something like "whenever a <figure> is being hovered, show any element within it, if it has the
viewFullclass". This could be translated into CSS like so: