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"
Related
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;
}
I am currently creating hyperlinked social media icons in the footer of my website. Each of the 3 images are seperate and eahc hyperlinking to a different social media. However the 'Copyright' text underneath the images in the footer is automatically hyperlinking to the link as the last image= Instagram.
How do I unlink that text? As i want it to just be displayed text not a hyperlink
.Socials {
display: inline-block;
margin-left: auto;
margin-right: auto;
width: 30%;
}
#footer {
text-align: center;
background-color: #000000;
color: white;
font-family: 'Big Shoulders Stencil Text', cursive;
}
<div id="footer">
<div class="Socials">
<a href="https://www.facebook.com/studyatulster/">
<img id="Facebook" src="Facebook.png" alt="Facebook">
<a href="https://twitter.com/UlsterUni? ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor">
<img id="Twitter" src="Twitter.png" alt="Twitter">
<a href="https://www.instagram.com/ulsteruni/?hl=en">
<img id="Instagram" src="Instagram.png" alt="Instagram">
</div>
<p>Belfast Virtual Shopping Centre - Copyright 2020</p>
</div>
Close your hyperlinks with a </a>. For example:
<a href="https://www.facebook.com/studyatulster/">
<img id="Facebook" src="Facebook.png" alt="Facebook">
</a>
Otherwise the browser is trying to correct the markup structure for you, and it may not always guess correctly.
You need to end the <a> tags in order for the "linking" to not continue.
<div id="footer">
<div class="Socials">
<a href="https://www.facebook.com/studyatulster/">
<img id="Facebook" src="Facebook.png" alt="Facebook"
/></a>
<a
href="https://twitter.com/UlsterUni? ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor"
>
<img id="Twitter" src="Twitter.png" alt="Twitter"
/></a>
<a href="https://www.instagram.com/ulsteruni/?hl=en">
<img id="Instagram" src="Instagram.png" alt="Instagram"
/></a>
</div>
<p>Belfast Virtual Shopping Centre - Copyright 2020</p>
</div>
You should close your tags!
<a href="https://www.facebook.com/studyatulster/">
<img id="Facebook" src="Facebook.png" alt="Facebook"/>
</a>
And if it does not require closing, like the image, you can put a slash in the opening tag, as showed in the code sample.
I've been trying to solve this for almost 6 hours just to get this to be responsive on mobile. Will someone please help me? It's really difficult and I really want to finish this homework.
I wanted it to look like this, but mobile responsive: https://imgur.com/kRcHUDJ
I only use HTML and inline CSS, hopefully, there is a solution to this.
<center>
<div id="home-secondary" style ="display: inline-block";>
<ul id="homepageGuide">
<a href="/blog/"><img class="img-responsive" data-original="/uploads/button-1.png" />
<p><img src="https://cdn.theatlantic.com/assets/media/img/mt/2019/07/GettyImages_138965532/lead_720_405.jpg?mod=1563813032" width="500px" alt="example one"></p>
<span class="color-overlay"></span>
</a></ul>
</div>
<div id="home-secondary" style ="display: inline-block";>
<ul id="homepageGuide">
<a href="/testimonials.php">
<img class="img-responsive" data-original="/uploads/button-2.png" />
<p><img src="https://cdn.theatlantic.com/assets/media/img/mt/2018/11/shutterstock_552503470/lead_720_405.jpg?mod=1541605820" width="500px" alt="example two"></p>
<span class="color-overlay"></span>
</a></ul>
</div>
</center>
Demo here: https://codepen.io/anon/pen/WVpwwX
It does appear to be working great on desktop, what I wanted to achieve is given; but when it comes to mobile, the results aren't great. I had to scroll to the right just to see the full image.
My expected output is to have the images stacked up together when viewed on mobile. Thanks guys.
Almost there. The images need to have a max-width set for mobile devices so they will resize automatically instead of flowing off the screen because of their 500px width setting. Set display to inline-block as well:
https://codepen.io/ZorlacMeister/pen/PMpNRK
You can test easily in Chrome. Hit F12, then click on the little icon that looks like two mobile devices standing upright next to each other, then RELOAD the page to see the mobile layout.
HTML
<center>
<div id="home-secondary" style ="display: inline-block">
<ul id="homepageGuide">
<a href="/blog/"><img data-original="/uploads/button-1.png" />
<p><img class='img-responsive' src="https://cdn.theatlantic.com/assets/media/img/mt/2019/07/GettyImages_138965532/lead_720_405.jpg?mod=1563813032" width="500px" alt="example one"></p>
<span class="color-overlay"></span>
</a></ul>
</div>
<div id="home-secondary" style ="display: inline-block">
<ul id="homepageGuide">
<a href="/testimonials.php">
<img data-original="/uploads/button-2.png" />
<p><img class='img-responsive' src="https://cdn.theatlantic.com/assets/media/img/mt/2018/11/shutterstock_552503470/lead_720_405.jpg?mod=1541605820" width="500px" alt="example two"></p>
<span class="color-overlay"></span>
</a></ul>
</div>
</center>
CSS
.img-responsive {
max-width:75%;
display: inline-block;
}
You can use a grid layout to achieve this.
grid-gap: 1em; specifies your padding between elements
center {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 1em;
}
img {
max-width: 100%;
}
<center>
<div id="home-secondary" style="display: inline-block" ;>
<ul id="homepageGuide">
<a href="/blog/"><img class="img-responsive" data-original="/uploads/button-1.png" />
<p><img src="https://cdn.theatlantic.com/assets/media/img/mt/2019/07/GettyImages_138965532/lead_720_405.jpg?mod=1563813032" width="500px" alt="example one"></p>
<span class="color-overlay"></span>
</a>
</ul>
</div>
<div id="home-secondary" style="display: inline-block" ;>
<ul id="homepageGuide">
<a href="/testimonials.php">
<img class="img-responsive" data-original="/uploads/button-2.png" />
<p><img src="https://cdn.theatlantic.com/assets/media/img/mt/2018/11/shutterstock_552503470/lead_720_405.jpg?mod=1541605820" width="500px" alt="example two"></p>
<span class="color-overlay"></span>
</a>
</ul>
</div>
</center>
I set the image width to 100% and used a class named column on the <ul> to set the box-sizing, float a relative width and display.
I also set the <ul> paddings to 2.5%.
Check it on Codepen or below
.column {
box-sizing: border-box;
float: left;
width: 50%;
display: inline-block;
}
ul{
padding-left: 2.5%;
padding-right: 2.5%;
}
<center>
<ul class="homepageGuide column">
<a href="/blog/"><img class="img-responsive" data-original="/uploads/button-1.png" />
<p>
<img src="https://cdn.theatlantic.com/assets/media/img/mt/2019/07/GettyImages_138965532/lead_720_405.jpg?mod=1563813032" width="100%" alt="example one">
</p>
<span class="color-overlay"></span>
</a>
</ul>
<ul class="homepageGuide column">
<a href="/testimonials.php">
<img class="img-responsive" data-original="/uploads/button-2.png" />
<p>
<img src="https://cdn.theatlantic.com/assets/media/img/mt/2018/11/shutterstock_552503470/lead_720_405.jpg?mod=1541605820" width="100%" alt="example two">
</p>
<span class="color-overlay"></span>
</a>
</ul>
</center>
I have a few wrapped images in my HTML file:
<div id="banners">
<div id="friend">
<a target="_blank" href="http://www.google.com">
<img src="../assets/images/friends/friend_1_256.png" alt="TEST 1" width="200" height="200">
</a>
</div>
<div id="friend">
<a target="_blank" href="https://www.google.com">
<img src="../assets/images/friends/friend_2_512x157.png" alt="TEST 2" width="400" height="123">
</a>
</div>
</div>
I want to display these images in a row. I have tried solutions such as float: left or display: inline-block but none of them works. Is it possible to display wrapped images inline?
It should work. Try something like this.
#friend {
display: inline-block;
border: 1px solid red; /*Just to highlight */
width:200px; /*Set width according to parent id banners*/
text-align:center /*center image*/
}
<div id="banners">
<div id="friend">
<a target="_blank" href="http://www.google.com">
<img src="https://i.stack.imgur.com/kMcaV.jpg?s=328&g=1" alt="TEST 1" width="200" height="200">
</a>
</div>
<div id="friend">
<a target="_blank" href="https://www.google.com">
<img src="https://i.stack.imgur.com/kMcaV.jpg?s=328&g=1" alt="TEST 2" width="400" height="123">
</a>
</div>
</div>
Try this out, it worked for me, hope it will resolve your issue as well
#friend{display:table-cell;}
Basically I have put a gallery into the website that I am making, and it works well. But. The pictures just scroll down the left side of the screen. I would like half of the pictures to be to the right of the other pictures... Here is a screenshot of my website (With Hi-tech red boxes drawn in paint to show where I would like half of the pictures to go)
http://tinypic.com/view.php?pic=hx3fbb&s=8#.U2JPKYFdX-k
Here is my code....(html)
<div class="img">
<a target="_blank" href="Gallery/Ss1.jpg">
<img src="Gallery/Ss1.jpg" alt="Screenshot1" width="500" height="400">
</a>
<div class="desc">Death vs Colossus</div>
</div>
<div class="img">
<a target="_blank" href="Gallery/Ss2.jpg">
<img src="Gallery/Ss2.jpg" alt="Screenshot2" width="500" height="400">
</a>
<div class="desc">Death's forge</div>
</div>
<div class="img">
<a target="_blank" href="Gallery/Ss3.jpg">
<img src="Gallery/Ss3.jpg" alt="Screenshot3" width="500" height="400">
</a>
<div class="desc">Death vs Horseman</div>
</div>
<div class="img">
<a target="_blank" href="Gallery/Ss4.jpg">
<img src="Gallery/Ss4.jpg" alt="FanArt1" width="500" height="400">
</a>
<div class="desc">Horse Jump</div>
</div>
<p></p>
<div class="img">
<a target="_blank" href="Gallery/fa1.jpg">
<img src="Gallery/fa1.jpg" alt="FanArt1" width="500" height="400">
</a>
<div class="desc">Fan Art #1</div>
</div>
<div class="img">
<a target="_blank" href="Gallery/fa2.jpg">
<img src="Gallery/fa2.jpg" alt="FanArt2" width="500" height="400">
</a>
<div class="desc">Fan Art #2</div>
</div>
<div class="img">
<a target="_blank" href="Gallery/fa3.jpg">
<img src="Gallery/fa3.jpg" alt="FanArt3" width="500" height="400">
</a>
<div class="desc">Fan Art #3</div>
</div>
<div class="img1">
<a target="_blank" href="Gallery/fa4.jpg">
<img src="Gallery/fa4.jpg" alt="FanArt4" width="500" height="400">
</a>
<div class="desc">Fan Art #4</div>
</div>
and here is my CSS code;
div.img
{
margin:5px;
padding: 5px;
border:1px solid #0000ff;
height:auto;
width:auto;
float:left;
text-align:center;
}
div.img img
{
display:inline;
margin:5px;
border:1px solid #ffffff;
}
div.img a:hover img
{
border:1px solid #0000ff;
}
div.desc
{
text-align:center;
font-weight:normal;
width:120px;
margin:5px;
}
So again, I would basically like the Fan art pictures to appear to the right of the Screenshot pictures. I tried making a new div class for the fan art and changing the float to 'right' but that didn't work.
Thankyou in advance for your time and input :)
There are a couple different methods you could use for this. You could use floats or display: inline-block.
http://jsfiddle.net/Davidicus/p4Qkh/
Here is a simple float example.
I have a pen where i am using "inline-block" to float elements. Click on the little eye icon in the css panel to see the compiled css.
http://codepen.io/davidicus/pen/vxIra