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 */
}
Related
I tried aligning my image next(right side) to my heading . With the following code.
The following html code for element:
/* And Tried to Align using css */
#colorlib-logo img {
display: flex;
align-items: center;
width: 30px;
height: 30px;
}
#colorlib-logo h1 {
margin-right: 3px;
margin-left: 0px;
}
#colorlib-logo {
width: 300px;
}
<h1 id="colorlib-logo">HaamTheLord<img src="" alt="logo" /></h1>
This Code Displays the image below the heading .But I Want The Image To be Displayed To right of the text
So you put the display flex on the image, it needs to go on the parent;
I've changed up the CSS a lot and made it simpler. I also changed the HTML markup, I made the parent tag an anchor (link) and the text is now the H1
#colorlib-logo {
display: inline-flex;
align-items: center;
justify-content: center;
}
#colorlib-logo h1 {
font-size: clamp(1rem, 4vw, 4rem);
margin: 0 0.5rem 0 0;
}
<a href="#" id="colorlib-logo">
<h1 href="">HaamTheLord</h1>
<img src="" alt="logo" height="30" width="30" />
</a>
You're applying display: flex property incorrectly.
I have made some changes to your code, please check:
#container {
display: flex;
justify-content: space-between;
align-items: center;
}
#colorlib-logo img {
width: 30px;
height: 30px;
}
#colorlib-logo h1 {
margin-right: 3px;
margin-left: 0px;
}
#colorlib-logo {
width: 300px;
}
<div id="container">
<h1 id="colorlib-logo">HaamTheLord</h1>
<img src="https://i.stack.imgur.com/11BLZ.jpg" alt="logo" />
</div>
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;
}
I'm using wkhtmltopdf to convert a HTML to PDF. I know wkhtmltopdf uses an old version of webkit, which makes things a little more complicated.
I have a contact image and I want to display the contact name right next to it:
Image: How it's supposed to look
This is my HTML:
<div class="contact">
<img src="C:/mypath/picture.jpg">
<span>Contact Name</span>
</div>
CSS:
div.contact {
display: -webkit-flex;
flex-direction: row;
justify-content: left;
}
div.contact>img {
width: 70px;
border-radius: 50%;
margin-right: 20px;
}
div.contact>span {
display: inline-block;
width: 110px;
}
Doesn't work so far. Applying align-items: center; to div.contact doesn't work either.
I think I found your solution. Actually align-self is working but .contact height is not big enough to cover viewport. So I wrote this; I hope it's enough for you.
For HTML
<div class="contact">
<div class="contact-box">
<img src="C:/mypath/picture.jpg">
<span>Contact Name</span>
</div>
</div>
And for CSS
body {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
background-color: #000000;
}
.contact {
display: flex;
display: -webkit-flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 100%;
min-height: 100vh;
margin: auto;
}
.contact-box {
background-color: white;
padding: 10px;
}
.contact img {
align-self: center;
justify-self: center;
width: 70px;
border-radius: 50%;
margin-right: 20px;
}
.contact span {
align-self: center;
justify-self: center;
width: 110px;
}
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
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