So I've spent the last hour or so trying to figure out how to put captioned images next to each other. Most solutions/questions other people have don't work when I try to add text below it using figcaption or something of that sort.
I want the text to be underneath the images and move with the images but for some reason it moves the other image to another layer when I add text. Any help would be greatly appreciated. Thank you.
(This is only a small portion of it because there's a lot of other stuff not related to this issue in that style)
.gunimage {
display: inline-block;
margin-left: auto;
margin-right: auto;
width: 15%;
padding-left: 20px;
}
#images {
text-align: center;
}
<div id="images">
<img class="gunimage" border="0" alt="idk" src="gg.png" /></a>
<p>this is text</p>
<img class="gunimage" border="0" alt="idk" src="gg2.png" /></a>
<p>this is also text</p>
</div>
This method uses HTML 5 figure and figcaption elements, and CSS 3 flexbox.
#images {
display: flex;
justify-content: center;
}
figure {
text-align: center;
}
<div id="images">
<figure>
<img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt="">
<figcaption>this is text</figcaption>
</figure>
<figure>
<img src="http://i.imgur.com/60PVLis.png" width="50" height="50" alt="">
<figcaption>this is also text</figcaption>
</figure>
</div>
NOTE: Flexbox is supported by all major browsers, except IE 8 & 9. Some recent browser versions, such as Safari 8 and IE10, require vendor prefixes. For a quick way to add prefixes, use Autoprefixer. More details in this answer.
Here is a solution using floats
.gunimage {
display: inline-block;
margin-left: auto;
margin-right: auto;
width: 15%;
}
.half {
width:50%;
float: left;
}
#images {
text-align: center;
width: 100%;
}
<div id="images">
<div class="half">
<img class="gunimage" border="0" alt="idk" src="gg.png">
<p>this is text</p>
</div>
<div class="half">
<img class="gunimage" border="0" alt="idk" src="gg2.png">
<p>this is also text</p>
</div>
</div>
Related
I'm new to coding and basically don't understand anything and I've been trying to solve this problem for about a week and haven't got anywhere close
here is my HTML code
.cats {
height: 118px;
width: auto;
object-position: 1px;
display: inline-block;
vertical-align: middle;
}
<div>
<img class="cats" src="black.jpeg" alt="beautiful cat">
<span style="text-align: center;">cutie</span>
</div>
I'm trying to have the image at the left like it is by default and have my text in the same line aligned to the center of the page.
Is this what your looking for? For the <img> to be positioned at the top left of the viewport and the <span> text to be centered on the page. Try this out.
.cats {
height: 118px;
width: auto;
object-position: 1px;
display: inline-block;
vertical-align: middle;
}
.container {
display: flex;
align-items: center;
}
.container span {
/* width: 85%; vary width to your liking if need be */
margin: 0 auto;
}
<div class="container">
<img class="cats" src="https://i.ibb.co/56tbCQP/Screen-Shot-2021-02-25-at-8-46-16-PM.png" alt="beautiful cat">
<span style="text-align: center;">cutie</span>
</div>
You can add display: block to span tag.
<span style="text-align: center; display: block">cutie</span>
If I'm understanding you correctly that you want the text centered and to the right of the photo then flexbox can help here. Try this snippet:
<div style="display: flex; align-items: center">
<img class="cats" src="black.jpg" alt="beautiful cat">
<span style="text-align: center; padding-left: 20px;">cutie</span>
</div>
If you are wanting the text below the picture I suggest using <figure> and <figcaption>:
<figure>
<img class="cats" src="black.jpg" alt="beautiful cat">
<figcaption style="text-align: center;">cutie</figcaption>
</figure>
This question already has answers here:
How to overlay images
(11 answers)
Closed 3 years ago.
I want to apply text over image on hover to every picture without it messing up elements container.
I've tried THIS and solutions similar, but It doesn't work for me.
This is what I have.
/*CSS*/
.item {
display: inline-block;
}
img {
padding-right: 10px;
}
.kulso {
text-align: center;
padding-top: 20px;
}
.kulso2 {
text-align: center;
}
<!--HTML-->
<div class="kulso">
<div class="item">
<img src="./img/long_macchiato.jpg" width="300px" height="200px" />
<p>Long Macchiato</p>
</div>
<div class="item">
<img src="./img/longblack.jpg" width="300px" height="200px" />
<p>Long Black</p>
</div>
<div class="item">
<img src="./img/café latte.jpg" width="300px" height="200px" />
<p>Café Latte</p>
</div>
<div class="item">
<img src="./img/ristretto.jpg" width="300px" height="200px" />
<p>Ristretto</p>
</div>
</div>
<div class="kulso2">
<div class="item">
<img src="./img/Cappuccino.jpg" width="300px" height="200px" />
<p>Capuccino</p>
</div>
<div class="item">
<img src="./img/flat-white.jpg" width="300px" height="200px" />
<p>Flat White</p>
</div>
<div class="item">
<img src="./img/mocha-coffee.jpg" width="300px" height="200px" />
<p>Mocha Coffee</p>
</div>
<div class="item">
<img src="./img/affogato.jpg" width="300px" height="200px" />
<p>Affogato</p>
</div>
</div>
Demo site:
https://peaceful-carson-9d2ad7.netlify.com/products.html/
I understad I have to have a wrapper around each image and caption. My problem is, no matter what properties I'm modifying or adding while trying to apply the text over image on hover using THIS, either...
"inline-block" is off, the pictures won't stay next to each other
opacity, transition affects padding between pictures
the text is in the center of the page, not the picture
the size of the pictures change
I noticed that adding
<div class="text">This is the text that appears on hover in the center of the image</div>
instantly messes up everything.
Please give me tips or solutions using my code I shared above!
You have to have a wrapper around each image and caption, much like the examples you link to. You can modify this a bit as the css could be a bit cleaner but this is the basic thing you can do.
.container {
padding-bottom: 20px;
}
.container__row {
display: flex;
}
img {
max-width: 100%;
display: inline-block;
padding-bottom: 10px;
}
/* For medium devices (e.g. tablets) */
#media (min-width: 420px) {
.image-container {
max-width: 48%;
}
}
/* For large devices (e.g. desktops) */
#media (min-width: 760px) {
.image-container {
max-width: 24%;
}
}
.egykispadding {
padding-top: 20px;
}
.image-container {
position: relative;
max-width: 400px;
}
.image-container__caption {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: deepskyblue;
color: white;
font-size: 2rem;
opacity: 0;
visibility: hidden;
transition: opacity 140ms;
}
.image-container:hover .image-container__caption {
opacity: 1;
visibility: visible;
}
<div class="container">
<div class="container__row egykispadding">
<div class="image-container">
<img src="https://www.stickpng.com/assets/images/580b585b2edbce24c47b2c8c.png" width="400" height="200" />
<div class="image-container__caption">Image caption</div>
</div>
</div>
<div class="container__row">
<div class="image-container">
<img src="https://www.stickpng.com/assets/images/580b585b2edbce24c47b2c8c.png" width="400" height="200" />
<div class="image-container__caption">Image caption</div>
</div>
<div class="image-container">
<img src="https://www.stickpng.com/assets/images/580b585b2edbce24c47b2c8c.png" width="400" height="200" />
<div class="image-container__caption">Image caption</div>
</div>
</div>
You can try this:
<div id='hover2change' style="background-image:url('a.png');width:50px;height:50px;">
<img src="b.png" style="position:absolute;top:0px;left:0px;width:50px;">
</div>
<style>
#hover2change:hover img {left:-100%;}
</style>
I have a row with seven small images and a heading which I need to stack horizontally but they're stacking vertically. This is how it looks -
I'm sure this is really simple but I'm stumped. I'm using reset & skeleton grid. This is the relevant code -
HTML
<section id="products">
<div class="container">
<div class="row">
<div class="twelve columns agencyproducts">
<h2>WHAT PRODUCT ARE YOU INTERESTED IN?</h2>
<img src="images/production.png" alt="Production" style="width:50px;height:50px;">
<h4>2K / 4K PRODUCTION</h4>
<img src="images/post-production.png" alt="Post-Production" style="width:50px;height:50px;">
<h4>POST PRODUCTION</h4>
<img src="images/animation.png" alt="Animation" style="width:50px;height:50px;">
<h4>2D / 3D ANIMATION</h4>
<img src="images/ADHOC.png" alt="ADHOC" style="width:50px;height:50px;">
<h4>ADHOC</h4>
<img src="images/interactive.png" alt="Interactive" style="width:50px;height:50px;">
<h4>INTERACTIVE & PERSONALISED</h4>
<img src="images/tv-adverts.png" alt="TV ADVERTS" style="width:50px;height:50px;">
<h4>TV ADVERTS</h4>
<img src="images/360.png" alt="360 Video and VR" style="width:50px;height:50px;">
<h4>360 VIDEO & VIRTUAL REALITY</h4>
</div>
</div>
CSS
section#products {
height: 700px;
max-width: 100%
}
.row {
height: 350px;
max-width: 100%;
}
.agencyproducts {
position: relative;
display: block;
text-align: center;
}
.agencyproducts img {
position: relative;
line-height: 1;
top: 50%;
}
.agencyproducts h4 {
display: block;
text-align: center;
font-size: 10px;
}
The h4 tags which you re using as captions are block elements, which means, their width is 100% by default. Also, you have nothing that associates/unifies them with the images they belong to.
The common way nowadays is to use a figuretag to wrap image and text, and put the text into a figcaptiontag inside that figure tag. Then apply text-align: center; and display: inline-block; to the figure tag to center image and text inside and allow them to appear next to each other:
figure {
text-align: center;
display: inline-block;
max-width: 100px;
vertical-align: top;
margin:10px;
}
<figure>
<img src="http://placehold.it/80x80/cac">
<figcaption>
This is an image
</figcaption>
</figure>
<figure>
<img src="http://placehold.it/80x80/cac">
<figcaption>
This is an image with a longer caption
</figcaption>
</figure>
<figure>
<img src="http://placehold.it/80x80/cac">
<figcaption>
This is an image
</figcaption>
</figure>
Images and Headers by default have display set to block, meaning they are on their own lines. float used to be the preferred way of achieving single-line display for block elements but it should be avoided as float has some weird behaviors. Instead we now use display: inline-block; or display: inline; - apply this to the elements you want on a single line and it will make it so!
just example (not copying your code - just simple example script):
HTML:
<div>
<img src="one.png" class="inlineImg" />
<img src="two.png" class="inlineImg" />
<img src="three.png" class="inlineImg" />
</div>
CSS:
.inlineImg {display: inline;}
this will display the images on a single line (providing the div is big enough)
.agencyproducts {
position: relative;
display: inline-flex;
text-align: center;
}
And you could put the main title outside of row div
That should all make them horizontal. You may need to add some padding to separate the items tho.
You can wrap the img- and h4-Tags with a div-Tag and make it float.
<div class="wrapper">
<img src="images/production.png" alt="Production" style="width:50px;height:50px;">
<h4>2K / 4K PRODUCTION</h4>
</div>
CSS:
.wrapper {
float: left;
}
Don't forget to unfloat afterwards.
The H4 will make them 'stack' vertically. Best to enclose each image and heading in it's own block or span, and on that div/span use " display: block; float: left;".
Basicly the h4 element has automaticly a wifth of 100%, you can check this easily with the inspection tool of your browser.
The easiest was is to put a div arround h and img element
<div class="containerIcon">
//img element
//h element
</div>
.conainterIcon {
display: block;
width: 13%, //So they all fit in one line
float: left;
}
Put the image and the title below in a div, and float them all to the left. Like so—
.bullet-point { float: left; }
.clear-float { clear: both; }
<div class="bullet-point">
<img src="images/production.png" alt="Production">
<h4>2K / 4K PRODUCTION</h4>
</div>
<div class="bullet-point">
<img src="images/production.png" alt="Production">
<h4>2K / 4K PRODUCTION</h4>
</div>
.
.
.and so on
<div class="clear-float"></div>
I have a simple thumbnail with images and a caption for each image. The images do not have the same height but are always 125px.
Captions can be short and long, they do not have the same height.
I want to align all of the images at the bottom so i can put the caption at the same level.
Did some research here and was able to align the images at the bottom, but without the caption
https://jsfiddle.net/0bzz7397/2/
.thumb {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
}
.thumb > div {
flex: 0 0 125px;
background-color: white;
}
.thumb > div ~ div {
margin-left: 20px;
}
When i add the caption, well, it's a MESS!
https://jsfiddle.net/fuk45osb/1/
EDIT:
i've included an example with multiple wrapped thumbs
https://jsfiddle.net/fuk45osb/5/
Basically, this is the effect i'm hoping for. Images with different height are all aligned at the bottom, and the caption starts at the same level. It's simple and clean.
Ive try using flexbox. But, maybe i'm wrong and there are better ways.
Any ideas how to achieve this ?
In this very limited scenario I'd use absolute positioning for title and subtitle.
body {
background: #eee;
}
.thumb {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
}
.thumb>div {
flex: 0 0 125px;
background-color: white;
position: relative;
}
.thumb>div~div {
margin-left: 20px;
}
.title {
position: absolute;
top: 100%;
background: #fff;
width: 100%;
}
<div class="thumb">
<div>
<img src="" width="125" height="125">
</div>
<div>
<img src="" width="125" height="170">
<div class="title">wefweergergerg erg er erg erg erg er gfwef</div>
</div>
<div>
<img src="" width="125" height="125">
</div>
<div>
<img src="" width="125" height="130">
</div>
<div>
<img src="" width="125" height="160">
</div>
<div>
<img src="" width="125" height="125">
<div class="title">wefwefwef</div>
</div>
<div>
<img src="" width="125" height="125">
</div>
</div>
I kept researching a couple of more hours here and found an answer, for those who are interested.
The answer comes from this very similar post created years ago:
Align multiple images (with captions) to baseline, all different heights
Basically, you just need to change the attribute align-items from flex-end to baseline. As simple as that.
Here's a working example
https://jsfiddle.net/fuk45osb/7/
I have two logos on my website which should go on top of my website.
One logo should be aligned to the left and the second logo to the right.
Now when the browser window gets pushed smaller, the space in between those two logos should get narrower and eventually when the two logos "hit" each other, both are supposed to scale smaller without breaking the line.
Right now only the left logo scales down and the right logo breaks the line and gets pushed lower without scaling down at all.
Can anybody help me?
My CSS:
.image-wrapper
{
position: relative;
white-space: nowrap;
}
.scale-image
{
display: block;
width: auto;
max-width: 55%;
white-space: nowrap;
}
Here is my HTML code:
<div class="image-wrapper">
<a href="#" ><img src="http://www.drogies-test.de/wp-content/uploads/2016/05/Logo_oskar.jpg" align="left" class="scale-image"/></a>
<div />
<div class="image-wrapper">
<a href="#" target="_blank" ><img src="http://www.drogies-test.de/pics/Logo_theater_os.gif" align="right" class="scale-image"/></a>
<div />
Example link: http://www.drogies-test.de/header_show.html
I've adjusted the mark-up structure to nest elements correctly.
.image-wrapper:first-of-type,.image-wrapper:nth-child(1) {
float: left;
}
.image-wrapper:last-of-type,.image-wrapper:nth-child(2) {
float: right;
}
.image-wrapper {
max-width: 50%;
}
.scale-image {
width: 100%;
height: auto;
}
<body>
<div class="image-wrapper">
<img src="http://www.drogies-test.de/wp-content/uploads/2016/05/Logo_oskar.jpg" align="left" class="scale-image">
</div>
<div class="image-wrapper">
<img src="http://www.drogies-test.de/pics/Logo_theater_os.gif" align="right" class="scale-image">
</div>
</body>
Here's a flex solution:
.image-wrapper {
max-width: 50%;
}
.scale-image {
width: 100%;
height: auto;
}
.flex-wrapper {
display: flex;
justify-content: space-between;
}
<div class="flex-wrapper">
<div class="image-wrapper">
<img src="http://www.drogies-test.de/wp-content/uploads/2016/05/Logo_oskar.jpg" align="left" class="scale-image">
</div>
<div class="image-wrapper">
<img src="http://www.drogies-test.de/pics/Logo_theater_os.gif" align="right" class="scale-image">
</div>
</div>
Note that flex is not supported in legacy browsers like IE 8 and 9, and some older versions of webkit browsers like Safari and Firefox (a deprecated or hybrid syntax variation is supported instead).
Learn more: caniuse.com