flex - align last item to right

  1. How can I stretch the last item to the right, and align the filter icon to right end of the page?

    the grey background need to stretch to right

  2. How can I center align the icons vertically in flex?

    align-items:center; causing the height of the li to collapse.

body{
  background: url(http://i.imgur.com/ilgJJ1Q.gif);
  margin: 0;
}
ul{
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  height: 80px;
}
li{
  padding: 10px;
  text-align: center;
  min-width: 80px;
}
li:last-child{
  background: rgba(38, 46, 54, .6);
}
.c2{ background: #a15796; }
.c3{ background: #b48c4d; }
.c4{ background: #3a7d7d; }
<ul>
  <li class="c1"><img src="http://i.imgur.com/SRVh4os.png" alt=""></li>
  <li class="c2"><img src="http://i.imgur.com/rBM2CYr.png" alt=""></li>
  <li class="c3"><img src="http://i.imgur.com/9dFFuH5.png" alt=""></li>
  <li class="c4"><img src="http://i.imgur.com/7bQ73kd.png" alt=""></li>
  <li class="c1"><img src="http://i.imgur.com/yJ4vKBG.png" alt=""></li>
</ul>

Answers


Since you have fixed height on ul you can use line-height for vertical align. Also you just have to add flex: 1 to li:last-child to take remaining space.


Instad of line-height you can also use display: flex on each li and then center its content with align-items: center and justify-content: center Fiddle

body{
  background: url(http://i.imgur.com/ilgJJ1Q.gif);
  margin: 0;
}
ul{
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  height: 80px;
}
li{
  padding: 10px;
  text-align: center;
  min-width: 80px;
  line-height: 80px;
}
li:last-child{
  background: rgba(38, 46, 54, .6);
  flex: 1;
}
.c2{ background: #a15796; }
.c3{ background: #b48c4d; }
.c4{ background: #3a7d7d; }
<ul>
  <li class="c1"><img src="http://i.imgur.com/SRVh4os.png" alt=""></li>
  <li class="c2"><img src="http://i.imgur.com/rBM2CYr.png" alt=""></li>
  <li class="c3"><img src="http://i.imgur.com/9dFFuH5.png" alt=""></li>
  <li class="c4"><img src="http://i.imgur.com/7bQ73kd.png" alt=""></li>
  <li class="c1"><img src="http://i.imgur.com/yJ4vKBG.png" alt=""></li>
</ul>

Need Your Help

javascript image into byte array

javascript image file-io yahoo-widgets

Is there a way in javascript for binary file manipulation like C. I'm in a critical situation to create an fliped image. I don't have support for css, canvas, HTML, DOM. But I have to do that with ...

Contacting local web service from android app running on emulator

android web-services android-emulator

I created a REST web service (using Web API), but I have not published it yet. I want before test the communication with the Android client. So I have temporarily published the ws on my local machi...