I am working on a course on CSS from Udemy called "Build Responsive Real World Websites with HTML5 and CSS3"
The images are supposed to stack across, like this:
image1 image2 image3 image 4.
But they are stacking down, like this:
image1
image2
image3
image4
The code is copied exactly, word for word.
Did I make a typing error?
To try and isolate the problem, I extracted the nonfunctional code into a separate file. I also tried to add
figure {
display: block;
float: left;
}
But that didn't work either. However this is not a part of the code that the instructor had given.
I would like to see the instructor-given code working, since ideally, I want to keep following along the same code as he gave to continue the book, so I am hoping there is maybe a syntactical issue or something, but I just can't figure it out....
Here is the code I extracted:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.meals-showcase {
list-style: none;
width: 100%;
}
.meals-showcase li {
display: block;
float: left;
width: 25%;
}
.meal-photo {
width: 100%;
margin: 0;
}
.meal-photo img {
width: 100%;
height: auto;
}
<section class="section-meals">
<ul class="meals-showcase">
<li>
<figure class="meal-photo">
<img src="resources/img/1.jpg" alt="Korean bimimbap with egg and vegetables">
</figure>
<figure class="meal-photo">
<img src="resources/img/2.jpg" alt="Chinese sholik with egg and vegetables">
</figure>
<figure class="meal-photo">
<img src="resources/img/3.jpg" alt="Indian Hamachaji with">
</figure>
<figure class="meal-photo">
<img src="resources/img/4.jpg" alt="Korean goolash with egg">
</figure>
</li>
</ul>
</section>
try with every figure tag inside li tag I think that what are you trying:
<section class="section-meals">
<ul class="meals-showcase">
<li>
<figure class="meal-photo">
<img src="resources/img/1.jpg" alt="Korean bimimbap with egg and vegetables">
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="resources/img/2.jpg" alt="Chinese sholik with egg and vegetables">
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="resources/img/3.jpg" alt="Indian Hamachaji with">
</figure>
</li>
<li>
<figure class="meal-photo">
<img src="resources/img/4.jpg" alt="Korean goolash with egg">
</figure>
</li>
</ul>
</section>
Try changing the size of your photos. I see that your code has 100% width for some of the photos. If that doesn't work, try using float:top; instead of float:left;.
.meal-photo has a width of 100% so no images will display aside of it if you remove that and replace it with display: inline-block; it should work however your other problem is .meals-showcase li width is 25%. remove that then your images will display next to each other horizontally.
NOTE: Figure and DIV elements are display: block; by default so they will always stack on top of each other unless otherwise specified through css. SPAN tags are display: inline; by default so they would be a better option, in this case, saving you time in code.
Related
I have been trying to create an image grid with HTML and CSS and following is the code I used. As I you can see in the picture I have attached to this. The picture on the bottom left corner has a bigger height than other images. Can someone kindly tell me why this happens and how can I make the image as same as the other images? Thank you.
Code - HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Float Test</title>
</head>
<body>
<h1>Float Test</h1>
<ul class="float-test">
<li>
<figure>
<img src="https://images.unsplash.com/photo-1521651201144-634f700b36ef?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80">
</figure>
</li><li>
<figure>
<img src="https://images.unsplash.com/photo-1500479694472-551d1fb6258d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80">
</figure>
</li><li>
<figure>
<img src="https://images.unsplash.com/photo-1456926631375-92c8ce872def?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80">
</figure>
</li><li>
<figure>
<img src="https://images.unsplash.com/photo-1489084917528-a57e68a79a1e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80">
</figure>
</li>
</ul>
<ul class="float-test">
<li>
<figure>
<img src="https://images.unsplash.com/photo-1484557985045-edf25e08da73?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1567&q=80">
</figure>
</li>
<li>
<figure>
<img src="https://images.unsplash.com/photo-1504618223053-559bdef9dd5a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80">
</figure>
</li>
<li>
<figure>
<img src="https://images.unsplash.com/photo-1477764250597-dffe9f601ae8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80">
</figure>
</li>
<li>
<figure>
<img src="https://images.unsplash.com/photo-1453227588063-bb302b62f50b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80">
</figure>
</li>
</ul>
</body>
</html>
Code: CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.float-test {
list-style: none;
width: 100%;
}
.float-test li {
display: block;
width: 25%;
float: left;
}
.flaot-test li figure {
width: 100%;
}
.float-test li figure img {
width: 100%;
}
It's because the image is a different size then the others (it's slightly larger). You can fix this either by limiting that specific images height or by using a program like photoshop to change the size of the image.
How do I place images side-by-side with captions underneath? I'm currently using a table to accomplish this effect and it looks like this:
<table align="center">
<tr>
<td>
<img style="width: 200px; height: 275px" src="image"/>
<br/>title
</td>
<td>
<img style="width: 200px; height: 275px" src="image"/>
<br/>title
</td>
</tr>
</table>
I was wondering if there was a better way to do this without using tables.
Use HTML5 Tags
CSS
figure{
display: inline-block;
}
HTML
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
figure{
display: inline-block;
}
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
<figure>
<img src='image.jpg' alt='missing' />
<figcaption>Caption goes here</figcaption>
</figure>
You can use divs to do this.
something simple like:
<ul>
<li class="container">
<img class="image" src="#"/>
<span class="caption">my caption</span>
</li>
<li class="container">
<img class="image" src="#"/>
<span class="caption">my caption</span>
</li>
</ul>
then you're looking at
.container {
float: left;
}
.image {
display: block
}
.caption {
display: block;
width: 100%;
text-align: center; //assuming centered captions
}
you might need a clearfix for the outer UL element (if you want to use a list to represent a list of images). Not sure but there's also the figure/figcaption route as well, but this would be fine if you weren't considering html5 elements.
As briefly mentioned, I suggest a UL/OL in this case because semantically it's probably a list of images. Even if you went the route with figures I would say to put the figures in each list item.
I'm creating a web page that shows pictures of cute dogs. For every dog, I want to show the name of the dog and then a picture below it.
I would like the images to be shown side by side, but they are shown stacked vertically.
Here is my fiddle
http://jsfiddle.net/53bnhscm/2/
Here is my HTML
<h1>Listing dogs</h1>
<ul>
<li> Dog 1 </li></br>
<li>
<a href="/dogs/2">
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</a>
</li>
</ul>
<ul>
<li> Dog 2 </li></br>
<li>
<a href="/dogs/3">
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</a>
</li>
</ul>
Here is my CSS
li {
list-style: none;
display: inline;
}
I thought a break statement after every list item and a display:inline property would do the trick, but I guess not.
Another solution is to use display: table-cell to ul elements:
ul {
display: table-cell;
}
li {
list-style-type: none;
}
<h1>Listing dogs</h1>
<ul>
<li>Dog 1</li>
</br>
<li>
<a href="/dogs/2">
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</a>
</li>
</ul>
<ul>
<li>Dog 2</li>
</br>
<li>
<a href="/dogs/3">
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</a>
</li>
</ul>
Your lis are contained within their own ul so you need to inline that instead.
ul {
list-style: none;
display: inline-block; //use instead of inline
}
FIDDLE
Also li tags are more for list items so this isn't a real efficient way of doing this. Plus its a lot of extra code. You could simply wrap your sections in a container and inline that:
HTML
<h1>Listing dogs</h1>
<div class="wrapper">
Dog 1
<a href="/dogs/2">
<img alt="Dog 1" src="..." />
</a>
</div>
<div class="wrapper">
Dog 2
<a href="/dogs/3">
<img alt="Dog 2" src="..." />
</a>
</div>
CSS
.wrapper{
display: inline-block;
}
.wrapper a{
display: block;
}
EXAMPLE
Here a fiddle. Your markup is messy by the way, I recommend to use HTML5 markup <figure> so you can easily add a <figcaption>: http://jsfiddle.net/53bnhscm/7/
<h1>Listing dogs</h1>
<figure>
<figcaption>Dog 1</figcaption>
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</figure>
<figure>
<figcaption>Dog2</figcaption>
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</figure>
CSS
figure {
float:left;
display:inline-block;
}
ul > li {
list-style: none;
display: inline;
float: left;
margin: 0 5px;
}
And I think may be you are looking something like this. In that case you have to edit your html code
http://jsfiddle.net/ahmadsharif/p0cbmy2h/
The following answer is correct for your markup.
ul {
list-style: none;
display: inline-block; //use instead of inline
}
But if you mean exactly what is written in your question then one thing that I need to mention and it is “You should take care of your HTML markup.”
<ul>
<li>
<a href="/dogs/2">
<b>Dog 1</b>
<img alt="Dog 1" src="http://renterswarehouse.com/wp-content/uploads/2013/12/Cute-Dog-dogs-13286656-1024-768-200x200.jpg" />
</a>
</li>
<li>
<a href="/dogs/3">
<b>Dog 2</b>
<img alt="Dog 2" src="https://v.cdn.vine.co/r/avatars/1D8A5A9AD81112510785588019200_21ff866832a.1.0.jpg?versionId=0I_eiPNigLBtjlgOMJIQyCYY4fKf2YNs" />
</a>
</li>
</ul>
and then your CSS will be:
ul li{
display: inline-block;
}
ul li a b{
display: block;
text-align: center;
margin-bottom: 5px
}
Just use UIKIT and its grid system. This way they will stack automatically on phones.
http://getuikit.com/docs/grid.html
<div class="uk-grid">
<div class="uk-width-1-2">Your Image HERE</div>
<div class="uk-width-1-2">Another Image Here</div>
</div>
this is my css and html for the menu. I am trying to work out how to make it all horizontal. Any help would be greatly appreciated. Cheers.
ol {
margin-top: 20px;
}
#images {
margin-left: 10px;
}
#images-text {
background: #f5f8ef;
border-radius: 10px;
width: 300px;
height: 40px;
font-family: Impact, Charcoal, sans-serif;
display: inline;
}
This is the html
<ol>
<li class="newbar">
<div id = "images">
<img src="images/crowd.png" width ="200" height="180">
<img src="images/crowd.png" width ="200" height="180">
<p>
<div id = "images-text">
Arctic Monkeys
</div>
<div id = "images-text">
Arctic Monkeys
</div>
</div>
</li>
</ol>
</div>
You don't need to use a <ol>. If you have <img> with some text below or above it is good practice to use <figure> and <figcaption>for the imagetext.
<figure>
<figcaption>
Image text
</figcaption>
<img src="images/crowd.png">
</figure>
If you want the image text below the <img> just put the <figcaption>below the <img>.
Than, the figures in a <div>:
<div>
<figure>
...
</figure>
<figure>
...
</figure>
<figure>
...
</figure>
...
</div>
The CSS for every <figure>:
div figure {
display: inline-block;
}
CSS selectors usage: http://www.w3schools.com/css/css_selectors.asp
example: http://jsfiddle.net/qpk9smm8/
I've been googling this and have found many answers, but none of them work in my situation because one of the divs is a gallery with multiple images. Basically, I'm trying to put an image and another gallery in the center of a page next to eachother.
HTML snippet:
<div class="sides">
<div class="featured-item">
<p class="featured-label">This weeks Featured Item is Mint Chip Cupcakes!</p> <img src="img/mintchip.jpg">
</div>
<div class="sides">
<div class="flexslider">
<ul class="slides">
<li>
<img src="img/1.jpg" alt="A Happy Birthday Mario Cake">
</li>
<li>
<img src="img/2.jpg" alt="A Pizza Hut Cake">
</li>
<li>
<img src="img/5.jpg" alt="A Makeup Cake">
</li>
<li>
<img src="img/6.jpg" alt="A Makeup Cake">
</li>
<li>
<img src="img/156.jpg" alt="A Makeup Cake">
</li>
</ul>
</div>
</div>
</div>
CSS:
.sides {
display: inline-block;
text-align: center;
max-width: 612px;
}
I also tried using each div seperately and using margin-left, margin-right but no luck. The max-width is 612px because that's the max-width of the gallery. I tried setting it to 1000 and it shows a ton of the images very widely.
Result: http://i.imgur.com/se8DwyL.png
One image is on top of the other, and they are on the left side of the screen.
First, you are using the "slides" class name for what seem like unrelated divs. I'd change that; it's only going to cause you grief. Next, the wrapper should have a set width and be centered with an auto margin -
.my-Wrapper-class {
width:960px;
margin:0px auto;
}
Now float the two divs holding your picture and slide show -
.featured-item {
float:left;
}
.flex-slider {
float:right;
}
You can add a margin to either of those until it's spaced to your liking.