I'd like to align a series of li items to the bottom of their parent, the ul. One of the tricky parts is: the li items require a float: left as well as the items being variable in height and width. Is there a way to achieve this without using a "hacky" method?
Here's my current code:
ul {
width: 1000px;
height: 400px;
float: left;
vertical-align: bottom; /* doesn't influence the list items because of the float: left. i thought i'd put it here anyways */
}
ul li {
float: left;
display: inline-block;
}
ul li figure {
/* determines the width & height of the list item */
margin: 0; padding: 0;
width: 150px;
height: 150px;
background: red;
}
ul li:nth-child(2n) figure {
width: 300px;
height: 300px;
}
<ul>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
</ul>
NOTE: The width of the ul's width is variable and my design requires there to be no gap between the list items. This is what I'm looking to achieve:
See snippet, note that the fixed width on the ul means an even distribution of the li with table-cell, so you may need to work on that in regards to the "gaps" between the li. As you didn't specify how that is supposed to look I didn't try to solve it in any specific way.
I think this is the way to go to get a bottom align.
ul {
height: 400px;
float: left;
display: table;
list-style: none;
}
ul li {
display: table-cell;
vertical-align: bottom;
margin: 0;
padding: 0;
}
ul li figure {
/* determines the width & height of the list item */
margin: 0;
padding: 0;
width: 150px;
height: 150px;
background: red;
display: inline-block;
}
ul li:nth-child(2n) figure {
width: 300px;
height: 300px;
}
<ul>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
</ul>
float is not compatible with vertical alignement.
inline-block & vertical-align does :
ul {
width: 1000px;
height: 400px;
float: left;
}
ul li {
/*float: left;*/
display: inline-block;
vertical-align:bottom
}
ul li figure {
/* determines the width & height of the list item */
margin: 0; padding: 0;
width: 150px;
height: 150px;
background: red;
}
ul li:nth-child(2n) figure {
width: 300px;
height: 300px;
}
<ul>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
</ul>
display:flex & align-items does :
ul {
width: 1000px;
height: 400px;
display:flex;
align-items:flex-end;
}
ul li {
display:block;
float:right;
/* whatevever float or display will be overide by flex model */
margin:1px; /* is efficent */
}
ul li figure {
/* determines the width & height of the list item */
margin: 0; padding: 0;
width: 150px;
height: 150px;
background: red;
}
ul li:nth-child(2n) figure {
width: 300px;
height: 300px;
}
<ul>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
</ul>
display:grid
* {margin:0;padding:0;}
ul {
width: 1000px;
height: 400px;
float: left;
display:grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 0));
grid-auto-flow: dense;
grid-auto-rows: minmax(150px, 300px);
grid-gap: 1px;/* whatever */
align-items: end;/* or align-self on children */
}
ul li {
display:block;
/* align-self: end; */
}
ul li:nth-child(2n) {
grid-column: span 2;}
ul li figure {
margin: 0; padding: 0;
width: 150px;
height: 150px;
background: red;
}
ul li:nth-child(2n) figure {
width: 300px;
height: 300px;
}
<ul>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
<li>
<figure>
<img />
</figure>
</li>
</ul>
display:table of course
Related
I have a vertical carousel that is in a floating div that is on top of a div that contains a horizontal slider. The floating div carousel contains scrolling logos that extend past the slider and pushes down the next div. How can I contain the floating div inside the bottom slider div?
This is the html code.
<div class="slider">
<div class="slider-1">
<ul class="rslides" id="slider-1">
<li>
<img src="images/slide-1.jpg" alt="">
<div class="caption">
<h3 class="home">Welcome To Company</h3>
</div>
</li>
<li>
<img src="images/slide-2.jpg" alt="">
<div class="caption">
<h3 class="home">Welcome To Company</h3>
</div>
</li>
<li>
<img src="images/slide-3.jpg" alt="">
<div class="caption">
<h3 class="home">Welcome To Company</h3>
</div>
</li>
<li>
<img src="images/slide-4.jpg" alt="">
<div class="caption">
<h3 class="home">Welcome To Company</h3>
</div>
</li>
<li>
<img src="images/slide-5.jpg" alt="">
<div class="caption">
<h3 class="home">Welcome To Company</h3>
</div>
</li>
</ul>
</div>
<div id="scrollbox">
<ul class="scroll-img">
<li><img class="hotel-logo" src="images/logo.png" alt="logo"></li>
<li><img class="hotel-logo" src="images/logo.png" alt="logo"></li>
<li><img class="hotel-logo" src="images/logo.png" alt="logo"></li>
<li><img class="hotel-logo" src="images/logo.png" alt="logo"></li>
<li><img class="hotel-logo" src="images/logo.png" alt="logo"></li>
<li><img class="hotel-logo" src="images/logo.png" alt="logo"></li>
</ul>
</div>
</div>
Here is the css code.
.slider {
padding: 0;
position: relative;
}
.rslides {
position: absolute;
list-style: none;
overflow: hidden;
width: 100%;
padding: 0;
margin: 0;
}
.rslides li {
-webkit-backface-visibility: hidden;
position: absolute;
display: none;
width: 100%;
left: 0;
top: 0;
}
.rslides li:first-child {
position: relative;
display: block;
float: left;
}
.rslides img {
display: block;
height: auto;
float: left;
width: 100%;
border: 0;
}
.layer {
position: absolute;
width: 100%;
height: 100%;
background: rgba(0,0,0,.4);
text-align: center;
}
.caption {
position: absolute;
top: 38%;
left: 14%;
}
.caption h3 {
text-align: left;
font-size: 38px;
font-weight: 800;
line-height: 40px;
color: #FFF;
width: 80%;
}
.caption h3.home {
text-align: left;
font-size: 52px;
font-weight: 800;
line-height: 50px;
color: #FFF;
width: 100%;
}
.slider #scrollbox {
background-color: rgba(2,56,122,0.6);
position: relative;
z-index: 75;
right: 75px;
top: 87px;
width: 185px;
float: right;
height: auto;
padding: 20px;
}
.slider #scrollbox .scroll-img {
list-style-type: none;
display: inline;
height: auto;
width: 100%;
}
I appreciate any help!
I'm trying to center these images in the UL. I've looked at some of the other topics on this, but couldn't apply the solutions to my situation. If anyone can help me, I'd appreciate it. Thank you.
JSFiddle: https://jsfiddle.net/dvbL2d5y/1/
HTML
<div id="posts-wrap">
<div id="primary">
<div class="hentry">
<div class="entry-content">
<div id="equipment-gallery">
<ul class="medium-grid">
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
CSS
#posts-wrap {
padding: 30px 50px;
text-align: center;
}
ul.medium-grid {
margin: 0 auto;
}
#equipment-gallery li {
float: left;
list-style: none;
margin: 20px;
}
Please apply below css. i have removed the float property and introduce display:inline-block.
#posts-wrap {
padding: 30px 50px;
text-align: center;
}
ul.medium-grid {
margin: 0 auto;
padding:0;
}
#equipment-gallery li {
display: inline-block;
list-style: none;
margin: 20px;
}
I have modified your code. I hope it helps. You just need to add inline-block to an element if you want to center it with the help of text-align: center tag.
#posts-wrap {
padding: 20px;
text-align: center;
}
ul.medium-grid {
display:inline-block;
margin:0;
padding:0;
}
#equipment-gallery li {
float: left;
list-style: none;
margin: 20px;
}
<div id="posts-wrap">
<div id="primary">
<div class="hentry">
<div class="entry-content">
<div id="equipment-gallery">
<ul class="medium-grid">
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Is this what you were looking for?
#equipment-gallery li {
float: left;
list-style: none;
margin: 0 auto;
display: block;
width: 100%;
}
Remove "float:left" from this class"#equipment-gallery li" and add "display:inline-block"
#equipment-gallery li {
display: inline-block;
list-style: none;
margin: 20px;
}
#posts-wrap {
padding: 20px;
text-align: center;
}
ul.medium-grid {
margin: 0 auto;
display: inline-block;
padding: 0;
text-align: center;
}
#equipment-gallery li {
float: none;
list-style: none;
margin: 20px;
display: inline-block;
}
You can see link fiddler add this css https://jsfiddle.net/zdso82b7/1/
To align center I had used flexbox concept in ul tag
ul.medium-grid {
display: flex;
align-items: center;
justify-content: center;
flex-flow: wrap row;
}
for more details regarding flex box, please find on CSS-Tricks A Complete Guide to Flexbox
#posts-wrap {
padding: 20px;
text-align: center;
}
ul.medium-grid {
display: flex;
justify-content: center;
flex-flow: wrap row;
}
#equipment-gallery li {
float: left;
list-style: none;
margin: 20px;
}
<div id="posts-wrap">
<div id="primary">
<div class="hentry">
<div class="entry-content">
<div id="equipment-gallery">
<ul class="medium-grid">
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
<li>
<img src="https://dummyimage.com/100.png/09f/fff">
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
I am trying to make a simple piece of code that makes some links sit in the top right corner of the page, but they won't line up nicely. They keep lining up vertically, and I want them horizontal. I'm sure it's probably something obvious I'm missing, but I'm not sure what. I also tried using float left but it didn't change anything.
CSS & HTML
.social {
position: fixed;
right: 0;
/* display:inline-block; */
/* float:left; */
}
.social-buttons-list {
list-style-type: none;
list-style-position: outside;
margin: 0;
padding: 0;
/* display: inline-block; */
/* float:right; */
}
.social-button {
margin: 5px;
width: 50px;
height: 50px;
display: inline-block;
/* float:right; */
}
<div class="social">
<ul class="social-buttons-list">
<li>
<a href="">
<img src="img/Twitter.png" alt="" class="social-button">
</a>
</li>
<li>
<a href="">
<img src="img/Facebook.png" alt="" class="social-button">
</a>
</li>
<li>
<a href="">
<img src="img/Snapchat.png" alt="" class="social-button">
</a>
</li>
</ul>
</div>
You're forgetting that the <li> of your list has a default display:block. By addressing that and adding text-align: right to your list you'll achieve a horizontal, right-aligned list.
.social {
position: fixed;
right: 0;
/* display:inline-block; */
/* float:left; */
}
.social-buttons-list {
list-style-type: none;
list-style-position: outside;
margin: 0;
padding: 0;
/* display: inline-block; */
/* float:right; */
text-align: right;
}
.social-buttons-list li {
display: inline-block;
}
.social-button {
margin: 5px;
width: 50px;
height: 50px;
display: inline-block;
/* float:right; */
}
<div class="social">
<ul class="social-buttons-list">
<li>
<a href="">
<img src="img/Twitter.png" alt="" class="social-button">
</a>
</li>
<li>
<a href="">
<img src="img/Facebook.png" alt="" class="social-button">
</a>
</li>
<li>
<a href="">
<img src="img/Snapchat.png" alt="" class="social-button">
</a>
</li>
</ul>
</div>
They are aligning because you have the buttons in "un-ordered list" , they are used to display list. Just remove them
.social {
position: fixed;
right: 0;
/* display:inline-block; */
/* float:left; */
}
.social-buttons-list {
list-style-type: none;
list-style-position: outside;
margin: 0;
padding: 0;
/* display: inline-block; */
/* float:right; */
}
.social-button {
margin: 5px;
width: 50px;
height: 50px;
display: inline-block;
/* float:right; */
}
<div class="social">
<a href="">
<img src="img/Twitter.png" a class="social-button">
</a>
<a href="">
<img src="img/Facebook.png" class="social-button">
</a>
<a href="">
<img src="img/Snapchat.png" class="social-button">
</a>
</div>
ul {
list-style-type: none;
}
li {
float: right;
}
li a {
display: block;
color: white;
}
http://codepen.io/anon/pen/BLBBWG
Here is your solution
I am working on an HTML CSS template, i stuck in a situation in which my list item (li) is getting bottom-margin from somewhere, here is my code:
JSFIDDLE
HTML
<div id="main-4">
<ul>
<li>
<img src="http://demo.htmlcoder.me/ivega/images/portfolio-1.jpg" alt="#">
</li>
<li>
<img src="http://demo.htmlcoder.me/ivega/images/portfolio-2.jpg" alt="#">
</li>
<li>
<img src="http://demo.htmlcoder.me/ivega/images/portfolio-3.jpg" alt="#">
</li>
<li>
<img src="http://demo.htmlcoder.me/ivega/images/portfolio-4.jpg" alt="#">
</li>
</ul>
</div>
CSS
#main-4 ul li {
list-style-type: none;
float: left;
width: 337px;
}
#main-4 ul li > img {
width: 337px;
}
it's because images do that. give your images vertical-align:bottom and see how it's being fixed:
#main-4 ul li {
list-style-type: none;
float: left;
width: 337px;
}
#main-4 ul li > img {
width: 337px;
vertical-align:bottom;
}
I have this HTML:
<article class="images">
<ul class="cf">
<li>
<a href="#">
<img src="http://www.placehold.it/800x600" alt="" />
</a>
</li>
</ul>
</article>
And this CSS:
* {
margin: 0;
padding: 0;
}
.images ul {
margin-left: -3%;
width: 100%;
background: red;
}
.images li {
list-style-type: none;
}
.images li img {
width: 17%;
margin-left: 3%;
margin-bottom: 3%;
float: left;
}
Still, in Safari the ul seems to have some kind of padding on the right.
In Firefox the ul is displayed correctly.
See it for yourself: http://jsfiddle.net/EdCXx/
Is there any way to fix that?
Edit: With Safari 6.0.2 on OS X 10.8.2 it looks like this:
I'm assuming the issue is that you're using negative margin and this is causing a problem (I don't have access to a Mac at the moment, so I can't verify).
Try changing your CSS to what's below. I also changed your clearfix to one I picked up a while ago that has had excellent cross-browser results.
http://jsfiddle.net/EdCXx/4/
CSS:
/* Reset */
* {
margin: 0;
padding: 0;
}
/* Clearfix */
.clear:after {
clear: both;
content: ".";
display: block;
height: 0;
line-height: 0;
visibility: hidden;
}
/* Images */
.images ul {
width: 100%;
background: red;
}
.images li {
list-style: none;
overflow: hidden;
margin-right: 3%;
margin-bottom: 3%;
float: left;
width: 17%;
height: 17%;
}
.images li img {
float: left;
max-width: 100%;
max-height: 100%;
}
And tighten up your HTML (not necessary, but it's prettier):
<article class="images">
<ul class="clear">
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
<li><img src="http://www.placehold.it/800x600" alt="" /></li>
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
<li> <img src="http://www.placehold.it/800x600" alt="" /></li>
</ul>
</article>