How can I add a href to an entire figure - html

I have the following html snippet:
<figure>
<img src='image.png' height="250" width="250">
<figcaption>Album name goes here
<br>Year goes here
</figcaption>
</figure>
And the following css:
figure {
display: inline-block;
border: 1px;
margin: 20px; /* adjust as needed */
}
figure img {
vertical-align: top;
}
figure figcaption {
border: 1px;
text-align: center;
}
It would end up looking like this:
How can I set it up so that if a user clicks on the image or the caption under it they get directed to a new page.

You can just put it inside an anchor tag like:
<figure>
<a href="https://www.google.com">
<img src='image.png' height="250" width="250">
<figcaption>Album name goes here
<br>Year goes here
</figcaption>
</a>
</figure>

You can use <a target="_blank" href="link_here">your image code</a> Also you need to use target="_blank" to open new browser window.
<figure>
<a target="_blank" href="your_link_here">
<img src='image.png' height="250" width="250">
...
...
</a>
</figure>

Related

Responsive images different sizes

I've tried searching for this, but could not find a close enough issue.
I have a responsive web site, that looks great on a PC, but on mobile, the images of the gallery are all different sizes. The actual images are all identical sizes, but mobile seems to make them grow as they go. Tested on Android and iPhone.
Screenshots:
Site on PC
Site on Android & Site on iPhone
The image codes are thus:
#media screen and (max-width: 768px) {
#primary { width:100%; }
#secondary { width:100%; margin:0; border:none; }
}
img { max-width: 100%; height: 100%; }
#media (min-device-width:600px) {
img[data-src-600px] {
content: attr(data-src-600px, url);
}
}
#media (min-device-width:800px) {
img[data-src-800px] {
content: attr(data-src-800px, url);
}
}
<tr><td align="center" valign="middle"><img src="/images/weddings/Bridal_Shoot.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Bridal Shoot</td>
<td align="center" valign="middle"><img src="/images/weddings/Butler_Wedding.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Butler Wedding</td>
<td align="center" valign="middle"><img src="/images/weddings/Engagement_Session.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Engagement Session</td>
<td align="center" valign="middle"><img src="/images/weddings/Fluke–Chenault_Wedding.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Fluke–Chenault Wedding</td></tr>
What am I missing here? Any help would be great. (I've tried using Bootstrap, but it made other images used on the page distorted).
Here is an example of a responsive layout for the elements included in your question.
Please note - this is just an example of what you can do with CSS responsive features, properties and units.
I have included a #media query which reduces the number of columns from 4 to 2 at a breakpoint of 600px.
To demonstrate an array of what's possible I have also used responsive units:
%
vw
a responsive property:
aspect-ratio
a responsive display:
display: flex
and a responsive function:
min()
Working Example:
.gallery {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
width: min(100%, 960px);
margin: 0 auto;
}
.gallery-link {
display: block;
flex: 0 0 22%;
margin-bottom: 3%;
line-height: 1.5;
font-size: min(16px, 3vw);
text-align: center;
outline: 1px solid rgb(255, 0, 0);
}
.gallery-figure {
display: block;
width: 100%;
margin: 0;
}
.gallery-image {
display: block;
width: 100%;
border: 1px solid rgb(0, 0, 255);
border-radius: 50%;
aspect-ratio: 235/352;
}
#media screen and (max-width: 600px) {
.gallery-link {
flex: 0 0 44%;
}
}
<div class="gallery">
<a class="gallery-link" href="/Portfolio/Weddings/Bridal_Shoot/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Bridal_Shoot.jpg" title="Click on image to open gallery" alt="Bridal Shoot" />
</figure>
<figcaption>Bridal Shoot</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Butler_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Butler_Wedding.jpg" title="Click on image to open gallery" alt="Butler Wedding" />
</figure>
<figcaption>Butler Wedding</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Engagement_Session/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Engagement_Session.jpg" title="Click on image to open gallery" alt="Engagement Session" />
</figure>
<figcaption>Engagement Session</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Fluke–Chenault_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Fluke–Chenault_Wedding.jpg" title="Click on image to open gallery" alt="Fluke–Chenault Wedding" />
</figure>
<figcaption>Fluke–Chenault Wedding</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Bridal_Shoot/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Bridal_Shoot.jpg" title="Click on image to open gallery" alt="Bridal Shoot" />
</figure>
<figcaption>Bridal Shoot</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Butler_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Butler_Wedding.jpg" title="Click on image to open gallery" alt="Butler Wedding" />
</figure>
<figcaption>Butler Wedding</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Engagement_Session/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Engagement_Session.jpg" title="Click on image to open gallery" alt="Engagement Session" />
</figure>
<figcaption>Engagement Session</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Fluke–Chenault_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Fluke–Chenault_Wedding.jpg" title="Click on image to open gallery" alt="Fluke–Chenault Wedding" />
</figure>
<figcaption>Fluke–Chenault Wedding</figcaption>
</a>
</div>
https://youtu.be/tmWvwp3rpso
Please check above the link, you will get the solutions for the image responsive and also check the border-radius property for circle image
Well with w: 100% i h: 100% you told your image to scale max w and h on container, just use width: 100%. I use always some container than put img inside as background so i use backgroun-position and background-size: cover; after that you manipulate just with container width and height, and with background-positon you target what part of image you want to show if img is too big for mobile , you can also use transform : scale to zoom in

Putting a link below an image

I'm trying to put an link below an image and for whatever reason, the link just keeps going to the side (right) of the picture. The image displays fine and the link works, but I just need it underneath the picture.
Any ideas?
HTML:
<div class="images">
<img src="imgs/2.jpeg" width="280" height="350" alt="Exterior" />
<a class="link1" href="https://www.google.com">Test</a>
</div>
CSS:
.images {
position: absolute;
left:10px;
top: 200px;
font-size: 120%;
}
I'm new to HTML/CSS so if anyone can explain in easy terms, I would really appreciate it. I have tried lots of different things such as span, align etc and it just won't work!
If I use a p statement instead of a ULR (h ref) the text does go below the image, so I'm baffled!
Images are by default inline-element 8though treated as inline-block). All you need to do, is to set the image as block-level element with : img { display: block; }
img {
display: block;
}
<div class="images">
<img src="https://via.placeholder.com/100.jpg" width="280" height="350" alt="Exterior" />
<a class="link1" href="https://www.google.com">Test </a>
</div>
You can use display flex to make this a column.
Explanation: https://www.w3schools.com/css/css3_flexbox_container.asp
.images {
position: absolute;
left: 10px;
top: 200px;
font-size: 120%;
display: flex;
flex-direction: column;
}
<div class="images">
<img src="imgs/2.jpeg" width="280" height="350" alt="Exterior" />
<a class="link1" href="https://www.google.com">Test </a>
</div>
You could add the break line tag below the image tag.
<div class = "images">
<img src="imgs/2.jpeg" width="280" height="350" alt="Exterior" />
<br>
<a class="link1" href = "https://www.google.com" >Test </a>
</div>

How to make a figcaption not move the image?

I am looking to put a figcaption onto an image and not have it move the image from its original spot without the figcaption`. Here is my CSS for figcaption.
Here is my code for an image with a figcaption.
figcaption {
text-align: center;
display: inline-block;
}
<figure>
<a href="https://ibb.co/CbSzPRr">
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
</a>
<br>
<figcaption>
<div>Retouched, Untagged</div>
</figcaption>
</figure>
Here is also a screenshot of what it looks like. The image on the left is where the image should be. The image on the left has a figcaption and it's slightly up to the left.
I am very new to coding. Anything suggestions would help. Thank you! I think there is a really simple solution to this that I'm missing.
Are you looking for something like this -
figure {
display: block;
float: left;
width: 200px;
margin: 20px
}
figcaption {
display: block;
text-align: center;
width: 100%;
}
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>Retouched, Untagged</div>
</figcaption>
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>The image stays in same row without begin displaced</div>
</figcaption>
</figure>
The above code will display all images in single row and all the captions beneath them. The images won't be misaligned in a single row.
Another way of doing it would be to bring the captions over the image. This can be done as -
.row {
display: flex;
justify-content: flex-start;
flex-wrap: nowrap;
overflow-X: scroll;
}
figure {
display: block;
float: left;
position: relative;
margin: 30px 15px
}
figcaption {
position: absolute;
bottom: 0;
background: #fff;
opacity: .7;
width: 100%;
text-align: center;
}
.row-separator {
height: 5px;
background-color: grey;
margin: 20px 10px;
}
<div class="row">
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>Retouched, Untagged</div>
</figcaption>
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>caption on image</div>
</figcaption>
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>caption on image</div>
</figcaption>
</figure>
</div>
<div class="row-separator"></div>
<div class="row">
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>Retouched, Untagged</div>
</figcaption>
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>caption on image</div>
</figcaption>
</figure>
<figure>
<img src="https://i.ibb.co/CbSzPRr/Published-06-Retouced-Untagged.jpg" alt="Published-06-Retouced-Untagged" border="0">
<figcaption>
<div>caption on image</div>
</figcaption>
</figure>
</div>
Hope this helps !

Align a Figcaption text which is in Absolute position below an Image which is in a DIV

i'm trying to make a gallery and need some help with align multiple text in the center of the images
HTML:
<div class="gallery">
<figure class="gallery-item">
<a target="_blank" href="./Event/1.jpg">
<img class="thumbnail" src="./Event/1.jpg" width="500" height="281"></a>
<figcaption class="comment"><B>Text</b></figcaption>
</figure>
</div>
CSS:
.comment {
position: absolute;
color: #F04D46;
}
EDIT: Fixed the Typo, still same problem tho.

How do I place images side-by-side with captions underneath?

How do I place images side-by-side with captions underneath? I'm currently using a table to accomplish this effect and it looks like this:
<table align="center">
<tr>
<td>
<img style="width: 200px; height: 275px" src="image"/>
<br/>title
</td>
<td>
<img style="width: 200px; height: 275px" src="image"/>
<br/>title
</td>
</tr>
</table>
I was wondering if there was a better way to do this without using tables.
Use HTML5 Tags
CSS
figure{
display: inline-block;
}
HTML
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
figure{
display: inline-block;
}
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
You can use divs to do this.
something simple like:
<ul>
<li class="container">
<img class="image" src="#"/>
<span class="caption">my caption</span>
</li>
<li class="container">
<img class="image" src="#"/>
<span class="caption">my caption</span>
</li>
</ul>
then you're looking at
.container {
float: left;
}
.image {
display: block
}
.caption {
display: block;
width: 100%;
text-align: center; //assuming centered captions
}
you might need a clearfix for the outer UL element (if you want to use a list to represent a list of images). Not sure but there's also the figure/figcaption route as well, but this would be fine if you weren't considering html5 elements.
As briefly mentioned, I suggest a UL/OL in this case because semantically it's probably a list of images. Even if you went the route with figures I would say to put the figures in each list item.