figure {
display: grid;
padding: 5px;
float: left;
background-color: #fff;
font-size: .875em;
}
figure img {
display: block;
max-width: 100%;
}
figcaption {
display: table-caption;
caption-side: bottom;
text-align: center;
padding: 0 5px 5px;
}
<figure>
<figcaption>Video</figcaption>
<img src=http://wordpress.local/wp-content/uploads/Thumbnail_2.png">
<figcaption>PDF</figcaption>
</figure>
Hi I'm having some issues with distributing images horizontally. The Code above results in this:
I Would like to make it distribute the images horizontally like img1 caption1 | img2 caption2 | img3 caption3
If possible I'd like it to be a grid thats 3 across and as deep as required, as the number of images could vary.
I am editing this in a beaver builder html module in wordpress.
Thanks for the help :)
I ended up figuring it out :)
<figure class="item">
[acf_repeater field="linked_gallery" sub_fields="external_link,cover_image,file_type"]
<div class="wrap">
[generate_image picture_url="%cover_image%" external_url ="%external_link%" file_type = "%file_type%" ]
<figcaption class="caption">%file_type%</figcaption>
</div>
[/acf_repeater]
</figure>
.item {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
float: left;
}
.caption {
/*display: inline-block;*/
caption-side: bottom;
}
.img {
display: block;
max-width: 100%;
}
.wrap{
text-align: center;
}
Related
Hi I have 6 images that I have in my website that are appearing vertically stacked but I want them to be horizontally stacked and center aligned. 4 of the images have captions too that I need to appear right below each image... can someone please help thanks so much
Here is my html:
<div class="container-fluid">
<div class="container-of-images">
<img src="chick2.png">
<figure>
<img id="img1" src="dice6.png">
<figcaption>Testing</figcaption>
</figure>
<figure>
<img id="img2" src="dice6.png">
<figcaption>Testing</figcaption>
</figure>
<figure>
<img id="img3" class="threeChoices" src="dice6.png">
<figcaption>Testing</figcaption>
</figure>
<figure>
<img id="img4" class="fourChoices" src="dice6.png">
<figcaption>Testing</figcaption>
</figure>
<img src="chick1.png">
</div>
</div>
And here is my CSS:
body {
background-color: #b6e6bd;
line-height: 1.6;
}
.container-fluid {
padding: 1% 20%;
margin: auto;
text-align: center;
}
img {
width: 100px;
line-height: 0;
margin: 0 1%;
display: flex;
justify-content: center;
}
figcaption {
text-align: center;
width: 100px;
}
Try this CSS code, the problem I found was that display: inline-block should have been used instead of flex.
body {
background-color: #b6e6bd;
line-height: 1.6;
}
.container-fluid {
margin: auto;
text-align: center;
width:100%;
}
img {
width: 100px;
line-height: 0;
margin: 0 1%;
display: inline-block;
justify-content: center;
vertical-align: middle;
}
figcaption {
text-align:
center;
width: 100px;
}
figure {
display: inline-block;vertical-align: middle;
}
Make your image container a flex element that lays out the content in a row:
.container-of-images {
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-items: center;
}
You need to add dispay: inline; or dispay: inline-block; to your css.
body {
background-color: #b6e6bd;
line-height: 1.6;
}
.container-fluid {
padding: 1% 20%;
margin: auto;
text-align: center;
}
img {
width: 100px;
line-height: 0;
margin: 0 1%;
display: flex;
justify-content: center;
display: inline;
}
figcaption {
text-align: center;
width: 100px;
}
Did you try to use flexbox on the container? Try this:
.container-of-images {
display: flex;
}
Based on your if you add the CSS property display:flex to container-of-images class it will solve your problem. But you solve be aware of the responsive design for it.
.container-of-images {
display: flex;
flex-direction: row; /* extra line flex alone can solve your problem */
justify-content: space-around; /* extra line to space images around */
}
Im writing some code using HTML and CSS only. And in header i have 1 image and some text after it. I need to place them in a one row to make it look like a normal header.
I was trying to use display: inline-block but it not worked for some reason
header{
display: inline-block;
width: auto;
}
<header>
<img src="https://picsum.photos/200" height="35" width="35" />
<h1>Learn about your game</h1>
</header>
Using flex
header {
display: flex;
align-items: center
}
.image-text {
display: flex;
align-items: center;
}
.image-text__image {
flex: 0 0 auto;
padding: 1em;
}
.image-text__image img {
display: block;
}
.image-text__text {
flex: 1 1 auto;
padding: 1em;
}
<header>
<div class="image-text">
<div class="image-text__image">
<img src="https://picsum.photos/200" height="35" width="35" />
</div>
<div class="image-text__text">
<h1>Learn about your game</h1>
</div>
</div>
</header>
Use Flexbox:-
header {
display: flex;
align-items: center;
justify-content:center;
}
header h1 {
padding-left:20px;
box-sizing:border-box;
}
header{
display: flex;
width: 90%;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 20px auto;
background-color: red;
text-align: center;
}
header img,header h1{
display: block;
width: 80%;
margin: 5px auto;
}
</style>
add this to your css
Im trying to keep an image with a description underneath it on desktop and then for mobile want the image to the left and description to the right... more for keeping everything above the fold as much as possible.
I want on desktop the DIVs to be:
A A A
B B B
But on mobile:
A B
A B
A B
I have them in parents to try and keep them together within there but doesn't seem to be working.
<style>
.pathOption_row {
display: inline-block;
position: relative;
width: 100%;
text-align: center;
margin: 0 auto;
vertical-align: middle;
}
.pathOption_block {
display: inline-block;
position: relative;
width: 30%;
height: 300px;
text-align: center;
margin: 0 auto;
vertical-align: middle;
}
.pathOption_img {
display: inline-block;
position: relative;
width: 100%;
height: 100%;
text-align: center;
margin: 0 auto;
vertical-align: middle;
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
#media only screen and (max-width: 768px) {
.pathOption_block{
width:70%;
position: relative;
text-align: center;
}
.pathOption_image {
float: left;
display: inline-block;
position: absolute;
text-align: center;
margin: 0 auto;
vertical-align: middle;
.pathOption_text {
float: right;
}
.pathOption_img {
display: inline-block;
float: left;
position: relative;
width: 50%;
height: 100%;
text-align: center;
margin: 0 auto;
vertical-align: middle;
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
</style>
<div class="pathOption_row">
<div class="pathOption_block">
<div class="pathOption_image">
<a class="pathOption_link" href="X">
<img class="pathOption_img" src="http://tug.ctan.org/macros/latex/contrib/mwe/example-image-a.png" alt="" />
</a><!--/.po_link-->
</div><!--/.pathOption_image-->
<div class="pathOption_text">
B
</div><!--/.pathOption_text-->
</div><!--/.pathOption_block-->
<div class="pathOption_block">
<div class="pathOption_image">
<a class="pathOption_link" href="X">
<img class="pathOption_img" src="http://tug.ctan.org/macros/latex/contrib/mwe/example-image-a.png" alt="" />
</a><!--/.po_link-->
</div><!--/.pathOption_image-->
<div class="pathOption_text">
B
</div><!--/.pathOption_text-->
</div><!--/.pathOption_block-->
<div class="pathOption_block">
<div class="pathOption_image">
<a class="pathOption_link" href="X">
<img class="pathOption_img" src="http://tug.ctan.org/macros/latex/contrib/mwe/example-image-a.png" alt="" />
</a><!--/.po_link-->
</div><!--/.pathOption_image-->
<div class="pathOption_text">
B
</div><!--/.pathOption_text-->
</div><!--/.pathOption_block-->
</div><!--/.pathOption_row-->
Here's a working fiddle: https://jsfiddle.net/zsvfLy7q/5/
Basically you want to wrap the As and Bs vertically and then stack them inline on mobile.
.wrapper {
display: flex;
flex-direction: column;
}
#media (min-width:800px) {
.wrapper {
flex-direction: row;
}
}
#media (max-width:800px) {
.block {
display: flex;
}
}
I was using flexbox since it's preferred way nowadays, but the same can be achieved with floats, the idea is the same.
I'm attempting to vertically align 2 divs with different heights and widths, which I've horizontally centered on the page. Text-align doesn't appear to do anything, and I was hoping that there was a solution that I'm missing.
CSS
.center {
text-align: center;
}
div#map {
background: blue;
display: inline-block;
height: 250px;
margin: 10px 15px;
width: 300px;
}
div.contact {
display: inline-block;
margin: 10px 15px;
overflow: auto;
text-align: center;
width: 350px;
}
HTML
<div class="center">
<div id="map">...</div>
<div class="contact">...</div>
</div>
Just add vertical-align: middle:
div#map,
div.contact {
vertical-align: middle;
display: inline-block;
}
.center {
text-align: center;
}
div#map {
vertical-align: middle;
background: blue;
display: inline-block;
height: 250px;
margin: 10px 15px;
width: 300px;
}
div.contact {
vertical-align: middle;
display: inline-block;
background: green;
margin: 10px 15px;
overflow: auto;
text-align: center;
width: 350px;
}
<div class="center">
<div id="map">...</div>
<div class="contact">...</div>
</div>
I'd set text-align: left for the .contact div and vertical-align: middle for both (since they are inline-blocks)
http://codepen.io/anon/pen/QdNaoJ
You can use flexbox
.center {
align-items: center;
}
You can find the flexbox documentation here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
User this in your css
div#map,div.contact {
display: inline-block;
vertical-align:middle;
}
vertical-align:middle; will aling the data in middle between your div
Question:
Is it possible to vertically centre a child element in a floated div in relation to the dynamic height of a floated div along side it?
Desired result
Background:
I'm using a WordPress theme which has shortcodes for creating columns. The columns are created through floated divs. As such, I'd like to stick to using float, instead of using a table layout as has been suggested to similar questions (Vertically center content of floating div).
I'd like the result to be responsive. The image height changes with the screen width, and so I cannot set explicit height or margins on the p element.
The text in p is also more than one line, so I cannot set line-height as a solution (Vertically centre a div).
Example:
http://codepen.io/besiix/pen/rxdOWM
.wrapper {
background-color: #50C5B7;
padding: 5px;
}
.image {
width: 100%;
}
.clear {
clear: both;
}
.one-half {
float: left;
width:48%;
margin-right: 4%;
background-color: lightgrey;
position: relative;
display: inline;
box-sizing: border-box;
}
.last {
clear: right;
margin-right: 0;
}
<section class="wrapper">
<div class="one-half">
<p class="v-center"> This wants to be centered vertically in relation to the image on the right.</p>
</div>
<div class="one-half last">
<img class="image" src="http://www.premiercottages.co.uk/images/regions/Scotland.jpg">
</div>
<div class="clear"></div>
</section>
You could use flexbox, see jsfiddle https://jsfiddle.net/d5Lptwut/2/
<section class="wrapper">
<div class="one-half vertical-align">
<p> This wants to be centered vertically in relation to the image on the right.</p>
</div>
<div class="one-half last">
<img class="image" src="http://www.premiercottages.co.uk/images/regions/Scotland.jpg">
</div>
</section>
.wrapper {
background-color: #50C5B7;
padding: 5px;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.image {
width: 100%;
height: auto;
}
.one-half {
width:48%;
margin-right: 4%;
background-color: lightgrey;
display: inline-block;
box-sizing: border-box;
}
.vertical-align {
flex-item-align: center;
-webkit-align-self: center;
-ms-flex-item-align: center;
align-self: center;
}
.last {
margin-right: 0;
}
you can try this one:
.wrapper {
background-color: #50C5B7;
padding: 5px;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
}
.image {
width: 100%;
height: auto;
}
.one-half {
width:48%;
margin-right: 4%;
background-color: lightgrey;
display: inline-block;
box-sizing: border-box;
}
.vertical-align {
flex-item-align: center;
-webkit-align-self: center;
-ms-flex-item-align: center;
align-self: center;
}
.last {
margin-right: 0;
clear:both;
}
DEMO HERE
you can use display: inline-block, this allow vertical-alignelements:
http://codepen.io/yukulele/pen/bEvYEZ?editors=1100