This is my first time on Stack Overflow. I recently started learning about HTML/CCS and I am stuck on a current project.
I wanted to make a gallery of album covers for a project, but whenever I 'zoom' in on the webpage (probably not the right term) the lay-out goes crazy. I think this issue is a 'responsive' issue and I tried adding a media query but i can 't make it look decently.
How can I change so that for example, it goes from a row of 5 album covers to 4 without there being gaps in the gallery? It goes from looking decent to 4 white squares in the same row.
I took the relevant code and pasted it in this link, if this isn't enough information I'd be happy to show all the code (it's still a bit of a mess, hence why I took this piece of code out of the full page)
https://codepen.io/LotteElders/pen/ZEpeRzN
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
.responsive {
padding: 0 6px;
float: center;
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%;
}
}
<figure>
<figcaption>
<h3> A summary of Cady Groves's albums </h3>
</figcaption>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/1oN2SgPwi43flviKj6rbBA">
<img src="https://m.media-amazon.com/images/I/714Jha+uaKL._SS500_.jpg" alt="Album cover of A Month of Sundays" width="600" height="400">
</a>
<div class="desc">A Month of Sundays (2009)</div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/1vW2HVeeXpmGBbpLkzt375">
<img src="https://images.genius.com/0add2529149d47b12983fa2e4a07b2a6.300x300x1.jpg" alt="Album cover of The Life of a Pirate (2010)" width="600" height="400">
</a>
<div class="desc">The Life of a Pirate (2010)</div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/6csTNqy5qkYCzPFJyHDA67">
<img src="https://m.media-amazon.com/images/I/71WUWQUq4-L._SS500_.jpg" alt="Album cover of This Little Girl" width="600" height="400">
</a>
<div class="desc">This Little Girl (2012)</div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/5HYv3SmW85lbspRTA1rDY0">
<img src="https://img.discogs.com/vCdTJTKCznRPIgplZuMLAZeIoio=/fit-in/300x300/filters:strip_icc():format(jpeg):mode_rgb():quality(40)/discogs-images/R-14325893-1572275353-3944.jpeg.jpg" alt="Album cover of Dreams" width="600" height="400">
</a>
<div class="desc">Dreams (2015)</div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/0k7vFx71y0w5r6RGhDMAfG">
<img src="https://images.genius.com/558fcb01fc43d257d8663b625cfa7086.1000x1000x1.jpg" alt="Album cover of Bless My Heart (2020)" width="600" height="400">
</a>
<div class="desc">Bless My Heart (2020)</div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/7swc0NVH2XCLH1EAXnbsP3">
<img src="https://cont-5.p-cdn.us/images/public/int/9/3/2/2/886444042239_1080W_1080H.jpg" alt="Single cover of Forget You (2013)" width="600" height="400">
</a>
<div class="desc">Forget You (2013)</div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/5jiaYe6RTZ5jpcqGbIVVyO">
<img src="https://resources.tidal.com/images/d4bbe9f2/bcdc/4489/81ef/42580782144b/640x640.jpg" alt="Album cover of This Little Girl" width="600" height="400">
</a>Whiskey & Wine feat. Christian Burghardt (2015) </div>
</div>
<div class="gallery">
<a target="_blank" href="https://open.spotify.com/album/6wUnijjeRKwBTqJSb7TcF4?highlight=spotify:track:3cXEhlI2PKHEjDt39I2upA">
<img src="https://images.genius.com/e45451e414fac83f6523a491f652a14a.500x500x1.jpg" alt="Single cover of Love Actually (2012)" width="600" height="400">
</a>
<div class="desc">Love Actually (2012)</div>
</div>
<div class="gallery">
<a target="_blank" href=https://open.spotify.com/album/0m2SFT766eRgMkzIjQHTOn?highlight=spotify:track:5eue4RoH3PG3k9qWdTwjL8>
<img src="https://images-na.ssl-images-amazon.com/images/I/91MNZnhU74L._SL1500_.jpg" alt="Single cover of Oh, Darling (2012)" width="600" height="400">
</a>
<div class="desc">Oh, Darling feat. Plug In Stereo (2012)</div>
</div>
</figure>
Thank you for reading this!
Please add the codes that I wrote.
figure {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
align-items: center;
justify-content: center;
}
Related
I've tried searching for this, but could not find a close enough issue.
I have a responsive web site, that looks great on a PC, but on mobile, the images of the gallery are all different sizes. The actual images are all identical sizes, but mobile seems to make them grow as they go. Tested on Android and iPhone.
Screenshots:
Site on PC
Site on Android & Site on iPhone
The image codes are thus:
#media screen and (max-width: 768px) {
#primary { width:100%; }
#secondary { width:100%; margin:0; border:none; }
}
img { max-width: 100%; height: 100%; }
#media (min-device-width:600px) {
img[data-src-600px] {
content: attr(data-src-600px, url);
}
}
#media (min-device-width:800px) {
img[data-src-800px] {
content: attr(data-src-800px, url);
}
}
<tr><td align="center" valign="middle"><img src="/images/weddings/Bridal_Shoot.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Bridal Shoot</td>
<td align="center" valign="middle"><img src="/images/weddings/Butler_Wedding.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Butler Wedding</td>
<td align="center" valign="middle"><img src="/images/weddings/Engagement_Session.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Engagement Session</td>
<td align="center" valign="middle"><img src="/images/weddings/Fluke–Chenault_Wedding.jpg" alt="Click on image to open gallery" width="235" height="352" class="z-depth-2 rounded-circle img-fluid"/><BR>Fluke–Chenault Wedding</td></tr>
What am I missing here? Any help would be great. (I've tried using Bootstrap, but it made other images used on the page distorted).
Here is an example of a responsive layout for the elements included in your question.
Please note - this is just an example of what you can do with CSS responsive features, properties and units.
I have included a #media query which reduces the number of columns from 4 to 2 at a breakpoint of 600px.
To demonstrate an array of what's possible I have also used responsive units:
%
vw
a responsive property:
aspect-ratio
a responsive display:
display: flex
and a responsive function:
min()
Working Example:
.gallery {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
width: min(100%, 960px);
margin: 0 auto;
}
.gallery-link {
display: block;
flex: 0 0 22%;
margin-bottom: 3%;
line-height: 1.5;
font-size: min(16px, 3vw);
text-align: center;
outline: 1px solid rgb(255, 0, 0);
}
.gallery-figure {
display: block;
width: 100%;
margin: 0;
}
.gallery-image {
display: block;
width: 100%;
border: 1px solid rgb(0, 0, 255);
border-radius: 50%;
aspect-ratio: 235/352;
}
#media screen and (max-width: 600px) {
.gallery-link {
flex: 0 0 44%;
}
}
<div class="gallery">
<a class="gallery-link" href="/Portfolio/Weddings/Bridal_Shoot/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Bridal_Shoot.jpg" title="Click on image to open gallery" alt="Bridal Shoot" />
</figure>
<figcaption>Bridal Shoot</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Butler_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Butler_Wedding.jpg" title="Click on image to open gallery" alt="Butler Wedding" />
</figure>
<figcaption>Butler Wedding</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Engagement_Session/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Engagement_Session.jpg" title="Click on image to open gallery" alt="Engagement Session" />
</figure>
<figcaption>Engagement Session</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Fluke–Chenault_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Fluke–Chenault_Wedding.jpg" title="Click on image to open gallery" alt="Fluke–Chenault Wedding" />
</figure>
<figcaption>Fluke–Chenault Wedding</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Bridal_Shoot/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Bridal_Shoot.jpg" title="Click on image to open gallery" alt="Bridal Shoot" />
</figure>
<figcaption>Bridal Shoot</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Butler_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Butler_Wedding.jpg" title="Click on image to open gallery" alt="Butler Wedding" />
</figure>
<figcaption>Butler Wedding</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Engagement_Session/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Engagement_Session.jpg" title="Click on image to open gallery" alt="Engagement Session" />
</figure>
<figcaption>Engagement Session</figcaption>
</a>
<a class="gallery-link" href="/Portfolio/Weddings/Fluke–Chenault_Wedding/index.html" target="_blank">
<figure class="gallery-figure">
<img class="gallery-image" src="/images/weddings/Fluke–Chenault_Wedding.jpg" title="Click on image to open gallery" alt="Fluke–Chenault Wedding" />
</figure>
<figcaption>Fluke–Chenault Wedding</figcaption>
</a>
</div>
https://youtu.be/tmWvwp3rpso
Please check above the link, you will get the solutions for the image responsive and also check the border-radius property for circle image
Well with w: 100% i h: 100% you told your image to scale max w and h on container, just use width: 100%. I use always some container than put img inside as background so i use backgroun-position and background-size: cover; after that you manipulate just with container width and height, and with background-positon you target what part of image you want to show if img is too big for mobile , you can also use transform : scale to zoom in
Alright, so I'm back with another question about centering my images. None of the advice I received (older post) solved the issue. Grant it, the images are no longer scattered and take up a different amount of space. They are lined on top of each other on the left side of the screen. I have ten images. I'm trying to achieve two rows of three centered images with the extra photo either right above or below the two rows. I took out any break elements because they didn't seem to be doing anything.
div.gallery {
margin: 5px;
border: 5px solid white;
width: 500px;
font-family: Consolas, "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "Monaco", "Courier New", "monospace";
color: yellow;
}
div.gallery:hover {
border: 5px solid yellow;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
<h1 class="work1"><center><a class="ex1">Photography Assignment</a></center></h1>
<div class="gallery">
<a target="_blank" href="images/SS1.png">
<img src="images/SS1.png" alt="Margaret's bag" height="200" width="300">
</a>
<div class="desc">An extreme close up of Margaret's bag</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS2.png">
<img src="images/SS2.png" alt="Margaret's notes" height="200" width="300">
</a>
<div class="desc">A picture of Margaret's bag</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS3.png">
<img src="images/SS3.png" alt="Close up of Margaret's face" height="200" width="300">
</a>
<div class="desc">A close up of Margaret against a pink house</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS4.png">
<img src="images/SS4.png" alt="A medium shot of Margaret" height="200" width="300">
</a>
<div class="desc">A medium shot of Margaret</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS5.png">
<img src="images/SS5.png" alt="A medium long shot of Margaret" height="200" width="300">
</a>
<div class="desc">A medium long shot of Margaret</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS6.png">
<img src="images/SS6.png" alt="A long shot of Margaret in motion" height="200" width="300">
</a>
<div class="desc">A long shot of Margaret in motion</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS7.png">
<img src="images/SS7.png" alt="A upward medium shot of Margaret" height="200" width="300">
</a>
<div class="desc">An upward medium shot of Margaret</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS8.png">
<img src="images/SS8.png" alt="A telephoto shot of a sunflower with Margaret in the background" height="200" width="300">
</a>
<div class="desc">A telephoto shot of a sunflower with Margaret in the background</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS9.png">
<img src="images/SS9.png" alt="A telephoto shot of Margaret" height="200" width="300">
</a>
<div class="desc">A telephoto shot of Margaret</div>
</div>
<div class="gallery">
<a target="_blank" href="images/SS10.png">
<img src="images/SS10.png" alt="A wide shot of Margaret getting into a firetruck" height="200" width="300">
</a>
<div class="desc">A wide shot of Margaret</div>
</div>
I was able to get the desired layout using Flexbox with these updates:
Add a container div to wrap around all 10 of the gallery divs.
Add this CSS for the new container div:
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
align-items: flex-start;
}
Add to the CSS width:30%; to the div.gallery
Here are these edits in CodePen:
https://codepen.io/jessbodie/pen/OONpRE?editors=1100
Refer to great article: "A Complete Guide to Flexbox"
I'm trying to make a simple homepage with clickable images as buttons, no problem, I can do that.
But I'm stuck at this part:
I have these 4 images in dividers with on hover shadow.
Now these images are vertical under each other.
I want them horizontal next to each other.
EDIT: Got it, now I need it to center it horizontal and vertical.
Code:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.imgBox
{
width: 300px;
height: 600px;
display: inline-block
}
.imgBox:hover
{
display: inline-block
-moz-box-shadow: 0 0 10px #ccc;
-webkit-box-shadow: 0 0 10px #ccc; box-shadow: 0 0 10px #ccc; }
</style>
</head>
<body background="back.jpg">
<center>
<div align="left">
<div class="imgBox">
<a target="_blank" href="IntensityBanner.png">
<img src="IntensityBanner.png" alt="Trolltunga Norway" width="300" height="600">
</a>
</div>
<div class="imgBox">
<a target="_blank" href="EarningsBanner.png">
<img src="EarningsBanner.png" alt="Forest" width="300" height="600">
</a>
</div>
<div class="imgBox">
<a target="_blank" href="img_lights.jpg">
<img src="DesignBanner.png" alt="Northern Lights" width="300" height="600">
</a>
</div>
<div class="imgBox">
<a target="_blank" href="img_mountains.jpg">
<img src="SpaarGamesBanner.png" alt="Mountains" width="300" height="600">
</a>
</div>
</center>
</div>
</body>
</html>
Live demo: http://twanofzo.nl/test/
First, make sure you close that first imgBox div (line 12) or it'll give you trouble.
Next, to make them display horizontally, you should just be able to either add display: inline-block or float: left to your css for .imgBox
I'm a web design student and still haven't gotten the hang of everything yet. I've been playing with this for awhile and I'm trying to make it work but one specific page on my website isn't working. Can't seem to figure out why, hence why I said "maybe" html, since im not completely sure that it's a css issue.
Here is my site and the specific page I'm having issue with: http://phlbombers.com/teamlist.html
First problem is I want the "This Season" section to be up much farther. If you click any of the other tabs, you will see that that section is in the same spot in all other pages, and you can see it just as soon as you click on the page. Sadly that is not the case on the "team" page.
Second problem is with the pictures. I want the first two pics to be stacked, exactly like they are. Problem occur's when I get to pictures three through six. I want those four pictures to be stacked 2 x 2. Is it possible to do that with a class setup, or would I need to change to a ID selector?
HTML
<div id="col3">
<h2>End of 2014/2015 Season playoff's pic</h2>
<div class="img">
<a target="_blank" href="images/IMG957247.jpg">
<img src="images/IMG957247.jpg" alt="2014/2015 Season" width="450" height="300">
</a>
<div class="desc">2014/2015 Season</div>
</div>
<h2>Bomber's 2014/2015 Admiral game outing</h2>
<div class="img">
<a target="_blank" href="images/IMG_0400.jpg">
<img src="images/IMG_0400.jpg" alt="Bomber's Admiral game outing" width="450" height="300">
</a>
<div class="desc">Bomber's Admiral game outing</div>
</div>
<h2>2015 Bomber's golf outing pictures</h2>
<div class="img">
<a target="_blank" href="images/golf.jpg">
<img src="images/golf.jpg" alt="Winners of the 2015 gold outing" width="450" height="300">
</a>
<div class="desc">Winners of the 2015 gold outing</div>
</div>
<div class="img">
<a target="_blank" href="images/golf2.jpg">
<img src="images/golf2.jpg" alt="2015 golf outing" width="450" height="300">
</a>
<div class="desc">2015 golf outing</div>
</div>
<div class="img">
<a target="_blank" href="images/golf3.jpg">
<img src="images/golf3.jpg" alt="2015 golf outing" width="450" height="300">
</a>
<div class="desc">2015 golf outing</div>
</div>
<div class="img">
<a target="_blank" href="images/golf4.jpg">
<img src="images/golf4.jpg" alt="2015 golf outing" width="450" height="300">
</a>
<div class="desc">2015 golf outing</div>
</div>
</div>
with CSS:
div.img { border: 1px solid #ccc; float: left; width: 300px; clear: both; margin-bottom: 10px; }
div.img:hover { border: 1px solid #777; }
div.img img { width: 100%; height: auto; }
div.desc { padding: 15px; text-align: center; }
col3 h2 {
padding-bottom: 10px;
font-size: 2em;
border-top: 1px solid;
border-left: 5px solid;
padding-top: 10px;
padding-left: 5px;
Float: left;
border-color: #A28B84;
color: #C2443D;
margin-bottom: 20px;
clear: both;
}
I'm sure im leaving some info that is needed out, which is why I linked the page itself. If need be, you can always inspect it.
Thank you!
First problem
You're missing the following in your css:
.col3{
float: left;
width: 600px;
}
Without these, your .col3 would just take up the entire page width, and your Season box would place itself below it.
Second problem
Create a containing div around each post/gallery item, so your structure looks like this:
<div class="post">
<h2>Title</h2>
<div class="img">...</img>
<div class="img">...</img>
</div>
This will give the img divs a place to float in. Now just remove the clear: both from your .img class since this negates your float property.
Also remember to change the width of your .img to 298px, because right now the div is 302px wide in total (300px width + 2px border) and will not fit 2x2.
I suggest reading up on how floats work to better grasp the concept and how to use them correctly.
I have 6 images that I want to have at the bottom and one large image above them. I am trying to make an image gallery.
I have set margin-top to the 6 images. I have added the other image which I want larger for the preview image but it seems to be making the other images move down and some out of the div. I know this may have something to do with the images being floated? I am a bit confused on where to put the float I initially just floated the images but it didn't seem to need it I guess because they're inline.I may possibly need to put them in divs? Overall I'm just confused :/
Here is an image to make it clear what I want to achieve:
Here is my code:
HTML
<div class="mainInfo">
<div class="gallery">
<!-----this is the first image I want to be the large preview--->
<img src="../assets/images/gallery/gallery3.png" alt="">
<img src="../assets/images/gallery/gallery1.png" alt="">
<img src="../assets/images/gallery/gallery2.png" alt="">
<img src="../assets/images/gallery/gallery3.png" alt="">
<img src="../assets/images/gallery/gallery4.png" alt="">
<img src="../assets/images/gallery/gallery5.png" alt="">
<img src="../assets/images/gallery/gallery6.png" alt="">
</div>
<!--END OF MAIN INFO-->
</div>
CSS
.mainInfo {
height: 650px;
background-color:#FCFCFC;
color:#001D5D;
padding: 100px 0 0 30px;
/* .............Gallery section........... */
.gallery {
float: left;
}
.gallery img {
width:140px;
height:auto;
margin:365px 0 0 15px;
}
.displayImage img {
width:400px;
height: auto;
margin: 0 auto;
padding:10px 0 0 30px;
}
/* .............Gallery section END........... */
Organize
You need to organize your HTML for layout.
Try inserting your big image in a <div class="displayImage"></div> tag. Then you can control it easier with your CSS.
Use CSS to define constraints.
Let's try adding appropriate widths to your images and fixing the margins.
Updated CSS
.gallery {
float: left;
}
.gallery img {
width:80px;
height: 80px;
margin: 10px;
}
.displayImage {
text-align: center;
padding-bottom: 20px;
}
.displayImage img {
width: 400px;
height: auto;
margin: 0 auto;
}
Updated HTML
<div class="gallery">
<div class="displayImage">
<img src="http://images.summitpost.org/original/371959.JPG" alt="" class="displayImage">
</div>
<a href="#">
<img src="http://www.slowtrav.com/blog/chiocciola/IMG_1368.jpg" alt="">
</a>
<a href="#">
<img src="http://www.nyroute28.com/pics/Thurmond_mountain_fall.jpg" alt="">
</a>
<a href="#">
<img src="http://images.summitpost.org/original/134465.jpg" alt="">
</a>
<a href="#">
<img src="http://www.domnik.net/topoi/commons/AT/alps/05n_mountain.jpg" alt="">
</a>
<a href="#">
<img src="http://people.hsc.edu/faculty-staff/mhight/Fulbright_Images/ItalySept2007/Cassino01.jpg" alt="">
</a>
<a href="#">
<img src="http://www.nyroute28.com/pics/Thurmond_mountain_fall.jpg" alt="">
</a>
</div>
Just remember, HTML is your friend. Organize it to best parallel with your CSS. This is a small case that could still survive without less structured HTML, but it's a great practice to get started.
Here's a example of it all: http://codepen.io/anon/pen/LjgdF
Do something like this,then you can position first images as per your wish.
Something you will get in Fiddle
<div class="mainInfo">
<div class="gallery">
<div class="bigpic">
<img src="../assets/images/gallery/gallery3.png" alt="">
</div>
<img src="../assets/images/gallery/gallery1.png" alt="">
<img src="../assets/images/gallery/gallery2.png" alt="">
<img src="../assets/images/gallery/gallery3.png" alt="">
<img src="../assets/images/gallery/gallery4.png" alt="">
<img src="../assets/images/gallery/gallery5.png" alt="">
<img src="../assets/images/gallery/gallery6.png" alt="">
</div>
</div>