This seems like a simple problem, but I can't crack it. I'm trying to set up a responsive image gallery much like the one demonstrated at W3Schools. That gallery looks fine--until you change the length of the captions. Then the height of the boxes starts to vary, and the arrangement of the gallery gets all screwed up. How can I set the height of those boxes so they line up neatly, even when the captions range from, say, 2-4 lines long?
One thing that you can do is, you can give a min-height and make it fixed height.
div.desc {
padding: 15px;
text-align: center;
min-height: 50px;
}
Snippet:
div.img {
border: 1px solid #ccc;
}
div.img:hover {
border: 1px solid #777;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
min-height: 50px;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
#media only screen and (max-width: 700px){
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px){
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
<h2>Responsive Image Gallery</h2>
<h4>Resize the browser window to see the effect.</h4>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_fjords.jpg">
<img src="img_fjords.jpg" alt="Trolltunga Norway" width="300" height="200">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_forest.jpg">
<img src="img_forest.jpg" alt="Forest" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_lights.jpg">
<img src="img_lights.jpg" alt="Northern Lights" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img_mountains.jpg">
<img src="img_mountains.jpg" alt="Mountains" width="600" height="400">
</a>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<div class="clearfix"></div>
<div style="padding:6px;">
<p>This example use media queries to re-arrange the images on different screen sizes: for screens larger than 700px wide, it will show four images side by side, for screens smaller than 700px, it will show two images side by side. For screens smaller than 500px, the images will stack vertically (100%).</p>
<p>You will learn more about media queries and responsive web design later in our CSS Tutorial.</p>
</div>
You can do 2 things. Put both of these on the class applied to each block.
overflow-y: hidden; //Or scroll if you want...
max-height: 400px;
Related
I'm trying to align two images side by side - pair after pair down by landing page on wide screen and single image - one after another on mobile screen layout:
<div class="container">
<div class="set">
<div class="column">
<img src="" id="img3" class="images">
</div>
<div class="column">
<img src="" id="img4" class="images">
</div>
<div class="column">
<img src="" id="img5" class="images">
</div>
<div class="column">
<img src="" id="img6" class="images">
</div>
</div>
</div>
container css:
.container {
height: relative;
padding: 0px 12px;
margin-top:0px;
margin-bottom:0px;
border-radius: 0px;
background-color: transparent;
}
set and column css:
* {
box-sizing: border-box;
}
.set {
display: flex;
}
.column {
flex: 33.33%;
padding: 5px;
}
images css:
.images {
position: relative;
width: 100%;
height: auto;
padding: 23px;
}
Actual result is a scalable images in one line with both screen layouts, left is a wide screen, right is mobile:
but I'm trying to get this result:
You just need to give one more parameter in your css file
#media screen and (max-width:768px){
.set{display:block}
}
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 website that im working on and there is a box with some links it it. I want this box to be the same size as the images around it. Right now the problem is that when the window size gets smaller the images will scale smaller or larger but this div with these links does not scale the same way.
Here is a image (left box is the links, images are surrounding it):
Here is html for the download box and images:
<div class="appDownload">
<header class="downloadHeader"><span class="downloadTitle">Download</span></header>
<!--Apple App Store</br>
Google Play Store</br>
Amazon App Store</br> -->
<a href="https://itunes.apple.com/us/app/igun-pro-hd/id574123647?mt=8" target="_blank">
<div class="appStoreBadge"><img src="images/App_Store_Badge135x40.svg" width="100%"></div>
</a>
<a href="https://play.google.com/store/apps/details?id=com.avidionmedia.iGunHD" target="_blank">
<div class="appStoreBadge"><img
src="images/Google_Play_Badge564x168.png" width="100%"></div>
</a>
<a href="http://www.amazon.com/iGun-Pro-Original-Gun-App/dp/B00G4E1DOI" target="_blank">
<div class="appStoreBadge"><img
src="images/Amazon_Badge564x168.png" width="100%"></div>
</a>
</div>
The images:
<div class="appScreenshots">
<img id="screenshot1" width="100%" src="images/igp1_screenshot_1.png">
<img id="screenshot2" width="100%" src="images/igp1_screenshot_3.png">
<img id="screenshot2" width="100%" src="images/igp1_screenshot_5.png">
<img id="screenshot2" width="100%" src="images/igp1_screenshot_7.png">
</div>
This is the download box css:
.appDownload{
width: 100%;
margin: 0px 0px 3px 0px;
background: #333;
float: left;
}
And this is the css for the images:
.appScreenshots{
width: 100%;
margin: 0px;
background: transparent;
overflow: hidden;
}
.appScreenshots img{
float: none;
clear: none;
}
<section>
<style>
div.img {
border: 1px solid #ccc;
}
div.img:hover {
border: 1px solid #777;
}
div.img img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
#media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
</style>
<div class="responsive">
<div class="img">
<a target="_blank" href="img\aviary-image-1479454871589.jpeg">
<img src="/img/aviary-image-1479454871589.jpeg" alt="A Boeing 747-400 descending" width="300" height="200">
</a>
<div class="desc">A Boeing 747-400 descending</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img\Screenshot_2016-11-18-13-30-35-973.jpg">
<img src="/img/Screenshot_2016-11-18-13-30-35-973.jpg" alt="Boeing 787-9 touching down" width="600" height="400">
</a>
<div class="desc">Boeing 787-9 touching down</div>
</div>
</div>
<div class="responsive">
<div class="img">
<a target="_blank" href="img\Slack for iOS Upload.jpg">
<img src="/img/Slack for iOS Upload.jpg" alt="Boeing 777-200ER climbing" width="600" height="400">
</a>
<div class="desc">A Boeing 777-200ER climbing</div>
</div>
</div>
</section>
Please note, that this is only a section of the page, that is why there are no starting tags etc.
For some reason, my gallery is not loading. The images are uploaded, but none of the gallery is showing up on the site. You can look at the site here: https://britishairways.000webhostapp.com/photos.html
Anything I'm doing wrong?
Thank you!
Make your <section> in which your gallery items are located a flex container. Just like:
section {
display: flex;
}
Visual Reference:
The section holding the three gallery images has zero height. This, in turn, is because the gallery images have float:left, which takes them out of the layout flow and causes their parent not to use their size in calculating its height.
See How do you keep parents of floated elements from collapsing?
Link to website: foxweb.marist.edu/users/kf79g/contact.php
This is it. The last step I have to fix before deploying my website and finally finishing it. But I do not know how to resolve this issue. On medium and small screens, I am having a lot of trouble with my social icons. I want the whole thing on medium and small devices to be centered and 100% responsive. I have tried making a container to make them responsive, but no matter what I do, it always looks messy in IE 7-10. The icons are moving to the next line instead of staying on one line evenly as the page width gets smaller and smaller. I tried adjusting the margins, but that didn't helps since that ruined my center attribute for the whole page. I simply do not know what to do or how to fix this issue. If anybody can help me I would really appreciate it.
Visual representation of problem (IE):
http://tinypic.com/r/nla7eq/5
What I want it to look like (modern browsers):
http://tinypic.com/view.php?pic=vp9gg7&s=5
HTML:
<h2> Social networks </h2><br/>
<div id = "center_icons">
<img src="images/facebook.png" alt="facebook" style="margin:1px;">
<img src="images/google-plus.png" alt="google plus" style="margin:1px;">
<img src="images/linkedin.png" alt="linkedin" style="margin:1px;">
<img src="images/github.png" alt="github" style="margin:1px;">
</div>
<br/>
</div>
</section>
Main CSS:
#details_section {
max-width:100%;
float:left;
margin-right:20px;
}
Large screens:
#details_section {
width:320px;
}
Medium screens:
#center{
width: 450px;
display: block;
margin-left: auto;
margin-right: auto;
}
#center_icons{
width: 213px; /*this value is changing for IE and chrome*/
display: block;
margin-left: auto;
margin-right: auto;
}
Small screens:
#center{
width: 220px;
display: block;
margin-left: auto;
margin-right: auto;
max-width:100%;
}
#center_icons{
width: 214px; /*this value is changing for IE and chrome*/
display: block;
margin-left: auto;
margin-right: auto;
max-width:100%;
}
You could also remove spaces between "=", and use " instead of '.
<div id = "center">
<div id='details_section'>
should be
<div id="center">
<div id="details_section">
You should also indicate the image size somewhere.
<div id="container">
<div id="center_icons">
<img src="images/facebook.png" alt="facebook" width="40" height="40">
<img src="images/google-plus.png" alt="google plus" width="40" height="40">
<img src="images/linkedin.png" alt="linkedin" width="40" height="40">
<img src="images/github.png" alt="github" width="40" height="40">
</div>
</div>
And a simpler CSS would be:
div {border: 1px red solid;padding: 5px} /*this is only for us to see it when testing*/
#container {
text-align:center;
}
#center_icons{
width: 214px; /*this value is changing for IE and chrome*/
display: block;
margin-left: auto;
margin-right: auto;
max-width:100%;
}
Check it working here: http://codepen.io/anon/pen/mAjzo
Just use <center> </center> in code instead of Div id "center".
you need to change your CSS properties just measure your screen co-ordinates and put it in margin or you can use HTML5 to solve this problem.