I'm trying to make a slider in a webpage, but overflow:hidden is hidding' everything instead just hide what comes out of the screen.
i need the images to be aligned and everything that comes out of the screen to be hidden.
My fiddle here:
HTML
<div>
<ul>
<li><img src="http://b-i.forbesimg.com/geristengel/files/2013/05/i-ella-fashion-closet.jpg" class="imgs"/></li>
<li><img src="http://cdn.playbuzz.com/cdn/2bff0e00-cbe8-49e5-85d4-7e4c052df449/f097abfe-d3d6-42c5-9768-11616bc985e2.jpg" class="imgs"/></li>
<li><img src="http://www.lakecityphotography.com/design/images/fashion.jpg" class="imgs"/></li>
<li><img src="http://www.thefashionhall.com.br/wp-content/uploads/2012/12/hnjh.jpg" class="imgs"/></li>
</ul>
</div>
CSS:
ul{
list-style:none;
}
li{
position:absolute;
}
.imgs{
height:130px;
width:180px;
float:left;
}
div{
overflow:hidden;
position:relative;
}
Fiddle:
https://jsfiddle.net/mkv9x2fg/2/
Try removing the position absolute from the li
ul {
list-style: none;
white-space:nowrap;
}
li {
display:inline-block;
}
.imgs {
height: 130px;
width: 180px;
}
div {
overflow: hidden;
position: relative;
}
<div>
<ul>
<li>
<img src="http://b-i.forbesimg.com/geristengel/files/2013/05/i-ella-fashion-closet.jpg" class="imgs" />
</li>
<li>
<img src="http://cdn.playbuzz.com/cdn/2bff0e00-cbe8-49e5-85d4-7e4c052df449/f097abfe-d3d6-42c5-9768-11616bc985e2.jpg" class="imgs" />
</li>
<li>
<img src="http://www.lakecityphotography.com/design/images/fashion.jpg" class="imgs" />
</li>
<li>
<img src="http://www.thefashionhall.com.br/wp-content/uploads/2012/12/hnjh.jpg" class="imgs" />
</li>
</ul>
</div>
EDIT: made the li inline-block and set the div to hide the overflow.
It's a little unclear what the OP is trying to do.
Try setting a div width like width: 200px; heigth: auto: max-height: 500px;
Related
I have a DIV which is 900% wide, I'm trying to display 5 images in a line but the 5th one always wraps around and I can't work out why?
I'm well under 900px with my 5 images.
ul{
margin:0px;
padding:0px;
}
li{
margin:0px;
padding:0px;
list-style:none;
}
.photo-preview{
width:178px;
margin:0px;
display:inline-block;
text-align:center;
}
.bottom-row{
width:900px;
}
<div class="bottom-row">
<ul>
<li class="photo-preview"><img src="photo/2.JPG"></li>
<li class="photo-preview"><img src="photo/2.JPG"></li>
<li class="photo-preview"><img src="photo/2.JPG"></li>
<li class="photo-preview"><img src="photo/2.JPG"></li>
<li class="photo-preview"><img src="photo/2.JPG"></li>
</ul>
</div>
Most browsers add a little bit of space between inline list items. YOu can use this funky formatting hack to stop that happening. Or you could just float them left if that suits your needs.
<div class="bottom-row">
<ul>
<li class="photo-preview"><img src="photo/2.JPG"></li><li class="photo-preview">
<img src="photo/2.JPG"></li><li class="photo-preview">
<img src="photo/2.JPG"></li><li class="photo-preview">
<img src="photo/2.JPG"></li><li class="photo-preview">
<img src="photo/2.JPG"></li>
</ul>
</div>
Here you go!
Like #WizardCoder said, there will always be a tiny bit of spacing between images but a -1px will fix it for you!
EDIT: I have tailored the question to be exactly the code you posted on JSFiddle. Anyways,
You need to have your display: inline on the li item.
You need the class photo-preview on the img and not on the li item.
ul {
margin: 0px;
padding: 0px;
}
li {
margin: 0px;
padding: 0px;
list-style: none;
display: inline;
}
.photo-preview {
width: 178px;
margin: -1px;
text-align: center;
}
.bottom-row {
width: 900px;
}
<div class="bottom-row">
<ul>
<li><img class="photo-preview" src="https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg"></li>
<li><img class="photo-preview" src="https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg"></li>
<li><img class="photo-preview" src="https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg"></li>
<li><img class="photo-preview" src="https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg"></li>
<li><img class="photo-preview" src="https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg"></li>
</ul>
</div>
How do I to align the last line in left, keeping the first line alignment?
this code:
<ul style="position:inline-block; text-align:center; width:120px; background-color:green; margin:0; padding:0;">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg" width="33px">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg" width="33px">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg" width="33px">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg" width="33px">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg" width="33px">
</ul>
http://jsfiddle.net/vinoli/59cLmvxo/
You can target the last item of the list, exemple :
html:
<ul class="myList">
<li>A</li>
<li>B</li>
<li>C</li>
</ul>
css:
ul.myList li { background-color: #ff0000; }
ul.myList li:last-child { background-color: #00ff00; }
Just put the css you want for each case.
fiddle
Add an id to your tag such as to reference it directly in your styles.css then use the align left as you would normally.
Alternatively, you could just put in an inline style for just that item specifically instead of just your ul. Like this:
<il style="position:inline-block; text-align:left; width:120px; background-color:green; padding:5px;">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg" width="33px">
</il>
It's li tag and not il and please don't use inline style instead of css file. You can dispose a line with centered images and a line with images align to the left like:
ul {
position:inline-block;
width:120px;
background-color:green;
padding:5px;
list-style: none;
}
.align-left: {
text-align: left;
}
.align-center {
text-align: center;
}
img {
width: 33px;
display: inline-block;
}
<ul>
<li class="align-center">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg">
</li>
<li class="align-left">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg">
<img src="http://img2.timeinc.net/instyle/images/2011/GalxMonth/2012-Charlize-Theron-400.jpg">
</li>
</ul>
Is there any way how to make all list items of the same height? I searched this website and found this solution but it doesn't work for me if I add float:left. I need float:left for line breaks after each 4 images.
ul.Gallery{display:table-row;}
ul.Gallery li{float:left;list-style:none;margin:0 5px 5px 0;
display:table-cell;background:red;}
<ul class="Gallery">
<li><img src="image1.jpg"><p>description1</p></li>
<li><img src="image2.jpg"><p>description2</p></li>
<li><img src="image3.jpg"><p>description3</p></li>
<li><img src="image4.jpg"><p>description4 description4 description4 description4 description4 description4</p></li>
<li><img src="image5.jpg"><p>description5</p></li>
</ul>
This is what I need:
and this is what I get if some images don't have any description or description length is different.:
I can not set width or min-heigth for <li> elements because not all the images have description and description length may be very different.
I don't want to use javascript for this purpose.
Try this (edited code a bit):
ul.Gallery{display:block; padding:0; margin:0;}
ul.Gallery li{
padding:0;
background:red;
display:inline-block;
vertical-align: top;
width:23%;
margin:0 1% 5px 0;}
img {max-width: 100%; height: auto;}
http://jsfiddle.net/uR9YV/
Remove float:left and add height:100%
ul.Gallery li{
list-style:none;
margin:0 5px 5px 0;
background:red;
display:table-cell;
vertical-align: top;
height: 100%;
}
DEMO
Change float:left for display:table-cell an the li/cells will all have the same height.
Note however, that you may have to restrict the width of the li as the text will cause different widths depending on it's length.
JSfiddle Demo
CSS
ul, li {
list-style: none;
}
ul {
display: table;
}
li {
display:table-cell;
border:1px solid grey;
padding:5px;
width:20%;
}
li img {
display: block;
margin:0 auto;
}
li p {
text-align: center;
}
Here is one of realizing this layout using rather different mark-up.
The feature of this layout is that the li elements all have the same height which
means that the red backgorund has the same height with a row.
If it were not for the red background color, this problem would be a lot easier to
solve.
The HTML would look like this:
<div class="GalleryWrap">
<ul class="Gallery">
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat is wearing a fur coat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
</ul>
<ul class="Gallery">
<li>
<img src="http://placekitten.com/300/200" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat is wearing a fur coat.</p>
</li>
<li>
<img src="http://placekitten.com/150/100" />
<p>The cat in the hat.</p>
</li>
</ul>
</div>
and the CSS:
.GalleryWrap {
display: table;
width: auto;
margin: 0 auto;
border-collapse: collapse;
}
ul.Gallery {
display: table-row;
}
ul.Gallery li {
display: table-cell;
vertical-align: top;
width: 25%;
background-color: red;
border: 5px solid white;
}
ul.Gallery li img {
width: 100%;
}
ul.Gallery li p {
margin: 5px;
}
Create a the CSS table .GalleryWrap, and use display: table-row for ul.Gallery.
Within each ul.Gallery, put in the four images, and repeat for each group of four.
I added a white border to control the spacing between cells, but you can also use
cell spacing and cell padding.
In practice, the mark-up could be generated automatically using a scripting language
like PHP or the features of the template system used to build the pages of the website.
Demo: http://jsfiddle.net/audetwebdesign/DBZdf/
Note: This layout may be easier to build using flex, but flex is still rather new and supported only by the latest browsers.
I use this method here in the below example.
<!-- vim: set nowrap:-->
<html>
<style type="text/css">
#titleImg{ <!--No use in the code but it makes -->
<!--things to work for some odd reason?!-->
position:absolute; <!--If I remove this, FAILURE --not 2x2.-->
<!--It becomes one-after-another after rem.-->
<!--Why?-->
}
li{
width:190px;
height:190px;
display: block;
float: left;
margin: 5px;
}
</style>
<body>
<center>
<ul style="width:400px; height:400px; text-align:center;">
<li>
<img id="titleImg"
src="../Pictures/Logos/logo.png"
style="width:100%;height:100%">
</li>
<li> </li>
<li> </li>
</ul>
</center>
</body>
You don't I think. Here's an updated jsFiddle example of what I believe you are trying to accomplish. Note: never use <center></center> tags - they are not good practice. Instead set the parent to display: block and its margin to 0 auto.
Here is the new live example
And the code:
HTML
<ul>
<li> <img src="http://www.woodlands-junior.kent.sch.uk/customs/images/uk.jpg"></li>
<li> <img src="http://www.crwflags.com/fotw/images/u/us.gif"> </li>
<li> <img src="http://www.enchantedlearning.com/school/Canada/flagbig.GIF"> </li>
</ul>
CSS
ul {
display: block;
margin: 0 auto;
}
li {
width:190px;
height:190px;
display: block;
float: left;
margin: 5px;
overflow: hidden;
}
I have an outer div, and inside of that, I have an inner div which contains a list of images. When the images are wider than the outer div, I want to have it scroll horizontally, but instead, it just puts the image on the next line instead of expanding. If I add many rows, the div does scroll vertically, but horizontally, it doesn't do it. This happens on every browser I've tried - Firefox, Chrome, IE, and Safari.
Here is the css:
#grid-container { left:33px; position:relative; width:300px; }
#grid { width:310px; height:400px; overflow:auto; margin-bottom: 15px; }
#grid-container ul { width:305px; }
#grid-container li { float:left; list-style-type:none; padding:5px 15px 5px 15px; height:88px; text-align:center; }
.image-row { float:left; margin-left: 10px; }
.grid-image { height:50px; margin-left:-20px; }
Here is the html:
<div id="grid-container">
<div id="grid">
<div id="row1" class="image-row">
<ul>
<li>
<img id="img1" class="grid-image" src="images/img1.jpg">
</li>
<li>
<img id="img2" class="grid-image" src="images/img2.jpg">
</li>
<li>
<img id="img3" class="grid-image" src="images/img3.jpg">
</li>
<li>
<img id="img4" class="grid-image" src="images/img4.jpg">
</li>
</ul>
</div>
<div id="row2" class="image-row">
<ul>
<li>
<img id="img5" class="grid-image" src="images/img5.jpg">
</li>
<li>
<img id="img6" class="grid-image" src="images/img6.jpg">
</li>
</ul>
</div>
</div>
</div>
The problem is img4 is showing on the second row (with img5 and img5 on the third row), even though it should on the first row and the grid div should scroll horizontally. It does scroll vertically. Can I force the div to expand? If I remove the width from the grid div, I do get the horizontal scroll bar, but the image is still on the second row.
Will this do? I simplified it somewhat.
CSS (you can remove the borders, they are just so you can see what is happening):
#grid-container {position: relative; width: 300px; height: 400px; overflow: auto; border: 1px red solid;}
#grid {border: 1px blue solid;}
#grid ul {height: 40px; list-style-type: none; white-space: nowrap; padding: 0; margin: 0; border: 1px green solid;}
#grid ul li {display: inline; padding: 0; margin: 0;}
#grid ul li img {height: 50px;}
HTML:
<div id="grid-container">
<div id="grid">
<ul>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
</ul>
<ul>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
<li><img src="testimage.jpg"></li>
</ul>
</div>
</div>
You need to put a white-space:nowrap; on the UL and LI tags. You also need the LI elements to be display inline rather than floating them.
CSS:
#grid-container { left:33px; position:relative; width:300px; }
#grid { width:310px; height:400px; overflow:auto; margin-bottom: 15px; }
#grid-container ul { width:305px; }
#grid-container li {
display:inline;
list-style-type:none;
padding:5px 15px 5px 15px;
height:88px;
margin:0;
text-align:center;
}
ul, li{
white-space:nowrap;
}
HTML:
<div id="grid-container">
<div id="grid">
<div class="image-row">
<ul>
<li>
<img id="img1" class="grid-image" src="test.jpg" />
</li>
<li>
<img id="img2" class="grid-image" src="test.jpg" />
</li>
<li>
<img id="img3" class="grid-image" src="test.jpg" />
</li>
<li>
<img id="img4" class="grid-image" src="test.jpg" />
</li>
</ul>
</div>
<div class="image-row">
<ul>
<li>
<img id="img5" class="grid-image" src="test.jpg" />
</li>
<li>
<img id="img6" class="grid-image" src="test.jpg" />
</li>
</ul>
</div>
This works in latest versions of IE, FF, Safari and Chrome.
try this:
#grid-container li {
display: inline;
list-style-type:none;
padding:5px 15px 5px 15px;
height:88px;
text-align:center;
white-space: nowrap;
}
You're already on the right path: Your approach to set "float: left;" on the <li>s, in combination with setting "width: 305px" on the <ul>s should basically work to avoid float dropping.
However, a few things to check:
Are 305px really enough? (It must be at least as large as the combined width of the elements in row 1, including margins, paddings and borders) Try setting it to a much larger value. overflow: auto won't help, since the floats will always wrap instead of causing an overflow. Setting a large enough width works perfectly for me (at least in my own example).
Other things to try:
Try it without floating ".image-row".
Try setting a width on the images.
You have the id "row1" twice in your HTML - that's invalid.