Figcaption prevents images from aligning inline - css

I'm building a navigation box with 3 rows and 3 columns of images. My target was to add some text below each image. I came across 'figcaption' today and although it seams like the perfect tag, i can't seam to get it to display properly.
The problem
The images display properly 'inline' until I add the 'figcaption' tags. The text appears in block (i assume), below each image which is great.. but it also forces the next image onto a new line (Even though inline block has been applied to the parent container '').
The html that i'm using goes as follows..
<section class="menu">
<h1>Menu</h1>
<br /><br />
<div>
<img src="img/image.png"><figcaption>Caption</figcaption>
<img src="img/image.png"><figcaption>Caption</figcaption>
<img src="img/image.png"><figcaption>Caption</figcaption>
</div>
***Div repeated twice***
</section>
And here is the css
.menu div {
padding: 0;}
.menu li a{display: inline;}
.menu a img{
width:32.1%; height:auto;
}
Here is a Fiddle
Thanks

According to MDN, <figcaption> needs to be inside a <figure> tag:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption
Here's an updated HTML structure:
<section class="menu">
<h1>Menu</h1>
<br />
<div>
<figure>
<a href="">
<img src="http://placekitten.com/100/100">
</a>
<figcaption>Caption</figcaption>
</figure>
<figure>
<a href="">
<img src="http://placekitten.com/100/100">
</a>
<figcaption>Caption</figcaption>
</figure>
<figure>
<a href="">
<img src="http://placekitten.com/100/100">
</a>
<figcaption>Caption</figcaption>
</figure>
</div>
</section>
and associated css:
.menu div {
padding: 0;}
.menu figure {display: inline-block;
width:100px;
}
.menu a img{
height:auto;
}
http://jsfiddle.net/DHM46/5/

Related

CSS on hover different elments change background img

i have 4 different icons and based on which icon i hover i want to change the background image in a div. The html is like so
<div class="col side">
<i id="icon1"></i>
<i id="icon2"></i>
<i id="icon3"></i>
<i id="icon4"></i>
</div>
<div class="col">
<img src="img1" id="img1" class="content" alt="" />
<img src="img2" id="img2" class="content" alt="" />
<img src="img3" id="img3" class="content" alt="" />
<img src="img4" id="img4" class="content" alt="" />
</div>
So when i hover icon1 i want to display img1 and so on. I know how to do it with jquery/javascript but is it possible with pure css?
it is not possible but try with adding background image on hover to each icon
#icon1:hover
{
background: url("path to img1");
}
like wise add this to all icons but i think it will result in bad alignment on hover
You can try some thing like
.content {
display: none;
}
#icon1:hover + #img1{
display: block; // or inline-block
}
#icon2:hover + #img2{
display: block;
}
#icon3:hover + #img3{
display: block;
}
#icon4:hover + #img4{
display: block;
}
It can be done with changed html-structure as someone has already mentioned in the comments. For example,
.content {
display: none;
}
#icon1:hover ~ .col img#img1 {
display: block;
}
#icon2:hover ~ .col img#img2 {
display: block;
}
<div class="col side">
<i id="icon1">First Icon</i> <i id="icon2">Second Icon</i>
<div>Images:</div>
<div class="col">
<img src="https://themcrazycats.files.wordpress.com/2020/11/1ce50-b8480db4-5bda-4912-84e4-3f8d79cae545.jpeg?w=400&h=200&crop=1" id="img1" class="content" alt="" />
<img src="https://themcrazycats.files.wordpress.com/2020/11/a66f0-4c055b18-860a-46b6-95a2-967b72e3547b.jpeg?w=400&h=200&crop=1" id="img2" class="content" alt="" />
</div>
</div>
The key here is to make possible usage of css ~ selector by placing .col inside .side. Why? There is no parent selector as of now in css as pointed out here.

Mutiple images in one line CSS + Div

Used this code around every image
<div class="side-by-side"> <a href="http://example.com ....> (include ALL the code for the image here) </div>
This is the CSS snippet
.side-by-side { float: left; margin-right: 5px }
It works... I mean images are on one line
But unfortunately the images align left, and I want them centered, all together.
Wrap your images in a div and set the text-align:center; then you dont need the extra div to wrap your a tags in you can just style the a tag itself. Like so:
<div class="centered-content">
<a href="#" class="side-by-side">
<img src="http://placehold.it/100x100"/>
</a>
<a href="#" class="side-by-side">
<img src="http://placehold.it/100x100"/>
</a>
<a href="#" class="side-by-side">
<img src="http://placehold.it/100x100"/>
</a>
</div>
And Css:
.centered-content{
text-align:center;
}
.side-by-side{
margin-right:5px;
display:inline-block;
}
I would use Flexbox to do it. Wrap your div in a container
<div class="container">
<div class="side-by-side">
</div>
</div>
CSS
.container {
display: flex;
justify-content: center;
}

Css hover not effect with bottom and right margin

I have this css code
#menu:hover img
{
margin-bottom:50px;
}
and html
<figure id="menu">
<img src="demo HTML/CaptionHoverEffects/demo 1/images/1.png"/>
<figcaption class="content">
<h3>Settings</h3>
<span>Jacob Cummings</span>
Take a look
</figcaption>
</figure>
At css code, when I change margin-bottom to margin-left or margin-right, it safe run, but with margin-bottom, it's not effect. How can I solve it?
#menu:hover img {
margin-bottom: 50px;
}
<figure id="menu">
<img src="http://placehold.it/350x150" />
<figcaption class="content">
<h3>Settings</h3>
<span>Jacob Cummings</span>
Take a look
</figcaption>
</figure>

Center image inside an anchor tag, but make the extra space unclickable?

HTML :
<a href="">
<img class="center" src="">
</a>
CSS :
.center { display: block; margin: 0 auto; }
That centers the image, but the problem is any extra white-space around the image is also clickable. Is there a way to fix that?
(Images vary in size)
You could just wrap a div around it and center the that div rather than the image itself.
<div class="center">
<a href="">
<img src="">
</a>
</div>
And then add a style definition for the div.
.center { margin: 0 auto; }
The only option I see would be putting the anchor in a div (non -clickable, with the size and style of your current anchor) and sizing the anchor based on the image:
HTML:
<div class="container">
<a href="" class="anchor">
<img src="http://placehold.it/350x150" />
</a>
</div>
CSS:
.container {
width: 100%;
text-align:center;
}
JSFIDDLE:
http://jsfiddle.net/Atumra/0jncgxkb/
How about doing this
<a href="" class="center">
<img src="">
</a>

set height div to other element height on page

I've created this content with drupal. Below the image you have a next page button.
I also set a button for next image on top of the image (pager) so if the visitor clicks on the image it would go next page.
How can i stretch the link over my image, drupal generated 2 divs and the images are variable in height.
<div class="view-content">
<div class="container12">
<div class="pagerfoto column12">
<h2 class="element-invisible">Pagina's</h2>
<div class="item-list">
<ul class="pager">
<li class="pager-next first">
›
</li>
<li class="pager-last last">
</ul>
</div>
</div>
</div>
<div class="container12">
<ul>
<li class="views-row views-row-1 column12">
<div>
<div class="views-field views-field-field-image">
<div class="field-content">
<img width="900" height="675" alt="" src="http://www.logicaarchitectuur.be/test/sites/default/files/styles/gallery_large/public/desert.jpg?itok=J6D4TAEL" typeof="foaf:Image">
</div>
</div>
</li>
</ul>
</div>
site
.pagerfoto{
z-index:1;
position:absolute;
padding-top:1.71429em;
display:block;
}
.pagerfoto ul li.pager-next a{
display:block;
margin:0 auto;
padding:0;
text-indent: -9999px;
}
This is the current css i use for ma a label.
Try giving this css:
.view-project11 {
position: relative;
}
.item-list {
left: 50%;
position: absolute;
top: 50%;
}
If I understand your question correctly you would like the user to click on the image and then the page will go to the next image.
wrapping your image in the tag will allow you to do that.
example
<a width="900" height="675" href="/test/project11?page=1">
<img width="900" height="675" alt="" src="http://www.logicaarchitectuur.be/test/sites/default/files/styles/gallery_large/public/desert.jpg?itok=J6D4TAEL" typeof="foaf:Image">
</a>

Resources