Vertical menu with images: align the first character of the items - css

I have a vertical menu. I would like to align vertically the name of the of items. I have this:
li {
list-style: none;
}
ul {
padding: 0;
}
img {
vertical-align: middle;
}
<ul>
<li>
<a href="#">
<img src="http://sermovi.es/images/car95.svg" />
<span>Cars</span>
</a>
</li>
<li>
<a href="#">
<img src="http://sermovi.es/images/restaurant95.svg" />
<span>Restaurants</span>
</a>
</li>
</ul>
The result is like this:
but I want this:
http://jsfiddle.net/o404phzt/

You could put the image in a fixed-width div:
li {
list-style: none;
}
ul {
padding: 0;
}
.menu-item {
display: inline-block;
width: 100px;
text-align: center;
}
img {
vertical-align: middle;
}
<ul>
<li>
<a href="#">
<div class="menu-item">
<img src="http://sermovi.es/images/car95.svg" />
</div>
<span>Cars</span>
</a>
</li>
<li>
<a href="#">
<div class="menu-item">
<img src="http://sermovi.es/images/restaurant95.svg" />
</div>
<span>Restaurants</span>
</a>
</li>
</ul>

You can try CSS tables:
ul {
padding: 0;
display: table;
}
ul > li {
display: table-row;
}
ul > li > * {
vertical-align: middle;
display: table-cell;
}
<ul>
<li>
<img src="http://sermovi.es/images/car95.svg" />
<span>Cars</span>
</li>
<li>
<img src="http://sermovi.es/images/restaurant95.svg" />
<span>Restaurants</span>
</li>
</ul>
Note I removed the links because they interfere with the layout.
However, since you use <a href="#">, you are probably handling them with JS. Then, you can just remove them, do the same click handling with JS, and fake links with CSS:
ul {
padding: 0;
display: table;
}
ul > li {
display: table-row;
color: blue;
cursor: pointer;
}
ul > li:hover {
text-decoration: underline;
}
ul > li > * {
vertical-align: middle;
display: table-cell;
}
<ul>
<li>
<img src="http://sermovi.es/images/car95.svg" />
<span>Cars</span>
</li>
<li>
<img src="http://sermovi.es/images/restaurant95.svg" />
<span>Restaurants</span>
</li>
</ul>

Probably the easiest way is to create a 2x2 table and not using lists.
<table>
<tr>
<td>
<img src="http://sermovi.es/images/car95.svg" />
</td>
<td>
<span>Cars</span>
</td>
</tr>
<tr>
<td>
<img src="http://sermovi.es/images/restaurant95.svg" />
</td>
<td>
<span>Restaurants</span>
</td>
</tr>
</table>
You can still use classes inside the td tag as needed. (aligning for example).

Structuring the image and spans inside inline-block divs will solve this flexibly:
li {
list-style: none;
}
ul {
padding: 0;
}
img {
vertical-align: middle;
}
li {
width: 300px;
}
li div {
display: inline-block;
}
.image {
width: 50%;
text-align: center;
}
.text {
width: 50%;
}
<ul>
<li>
<a href="#">
<div class="image">
<img src="http://sermovi.es/images/car95.svg" />
</div>
<div class="link">
<span>Cars</span>
</div>
</a>
</li>
<li>
<a href="#">
<div class="image">
<img src="http://sermovi.es/images/restaurant95.svg" />
</div>
<div class="link">
<span>Restaurants</span>
</div>
</a>
</li>
</ul>
Fiddle

Related

Flexbox css unordered list custom styling

I want to style my unordered list like this one below
Link to what i want to achive
My structure looks like:
<div class="tabs">
<ul class="tabs__labels">
<li class="0">
<a class="active" href="#">
<img/>
<div>something</div>
</a>
</li>
<li class="1">
<a class="" href="#">
<img/>
<div>something1</div>
</a>
</li>
...
</ul>
</div>
Is it a good idea to name the list classes like 0,1 etc. and style them separately to somehow achive this effect? How to use flexbox to get similar effect? Should i group them into rows?
Would this be a start?
.tabs__labels {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
list-style: none;
margin: 0;
padding: 0;
}
.tabs__labels li {
flex-basis: 45%;
margin: 20px 0;
padding: 0;
}
.tabs__labels li:nth-child(odd) {
display: flex;
justify-content: flex-end;
}
.tabs__labels li:nth-child(even) {
display: flex;
}
.tabs__labels li:nth-child(3),
.tabs__labels li:nth-child(4) {
flex-basis: 35%;
}
.tabs__labels li a {
display: flex;
justify-content: center;
align-items: center;
height: 40px;
width: 40px;
border-radius: 50%;
border: 1px solid red;
text-decoration: none;
}
.tabs__labels li:nth-child(1)::before {
content: 'some text';
text-decoration: underline;
margin-right: 10px;
}
.tabs__labels li:nth-child(2)::after {
content: 'some text';
text-decoration: underline;
margin-left: 10px;
}
<div class="tabs">
<ul class="tabs__labels">
<li>
<a class="active" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
<li>
<a class="" href="#">S
</a>
</li>
</ul>
</div>

image with lower z-index goes on content

I'm trying to create a header hero but my problem is that my background image goes on all my contents. Actually it has lower z-index than content but I don't know why doesn't it go on background.
.header
{
width: 100vw;
background-color: blue;
position: relative;
}
.headerbakground
{
position: absolute;
width: 100%;
z-index: 1;
}
.header ul li img,.header ul li
{
width: 2vw;
float: right;
}
.header .container
{
z-index: 2;
}
<div class="header">
<!--background image-->
<img src="https://www.renonation.sg/wp-content/uploads/2015/01/title-header-hero-01.jpg" class="headerbakground">
<!--header top-->
<div class="container">
<ul>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
<li><img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png" ></li>
</ul>
</div>
</div>
Only a positioned element can use z-index. According to MDN:
The z-index property specifies the z-order of a positioned (that is, one with any position other than static) element and
its descendants.
The .container doesn't have a position, so the z-index: 2 is ignored. Add position: relative to it:
.header .container {
position: relative;
z-index: 2;
}
.header {
width: 100vw;
background-color: blue;
position: relative;
}
.headerbakground {
position: absolute;
width: 100%;
z-index: 1;
}
.header ul li img,
.header ul li {
width: 10vw;
float: right;
}
.header .container {
position: relative;
z-index: 2;
}
<div class="header">
<!--background image-->
<img src="https://www.renonation.sg/wp-content/uploads/2015/01/title-header-hero-01.jpg" class="headerbakground">
<!--header top-->
<div class="container">
<ul>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
</ul>
</div>
</div>
You can also use a negative z-index: -1 on the element you want to push back:
.headerbakground {
position: absolute;
width: 100%;
z-index: -1;
}
.header {
position: relative;
width: 100vw;
background-color: blue;
}
.headerbakground {
position: absolute;
width: 100%;
z-index: -1;
}
.header ul li img,
.header ul li {
width: 10vw;
float: right;
}
<div class="header">
<!--background image-->
<img src="https://www.renonation.sg/wp-content/uploads/2015/01/title-header-hero-01.jpg" class="headerbakground">
<!--header top-->
<div class="container">
<ul>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
<li>
<img src="https://d30y9cdsu7xlg0.cloudfront.net/png/1832-200.png">
</li>
</ul>
</div>
</div>

How to vertically Align the button text to the second line w.r.t label. in an <li>

I need to vertically align the button text to the line with respect to second line(always to second line) of the label if there is a word-break else to the first line of the label text(which is dynamic.)
<ul>
<li>
<div id="label" class="left word-break-on-particular-width">A dynamic text</div>
<div id="value" class="right"><button>button text</button></div>
</li>
<li>
<div id="label1" class="left word-break-on-particular-width">A dynamic text(width of this will differ as per the text recieved)</div>
<div id="value1" class="right"><button>button text</button></div>
</li>
</ul>
output should be like this
Flexbox can do that:
ul {
list-style-type: none;
width: 50%;
/* for demo */
margin: auto;
}
li {
display: flex;
align-items: center;
margin-bottom: 1em;
}
li div {
padding: 0 1em;
}
.right {
margin-left: auto;
flex: 0 0 auto
}
<ul>
<li>
<div id="label" class="left word-break-on-particular-width">A dynamic text</div>
<div id="value" class="right">
<button>button text</button>
</div>
</li>
<li>
<div id="label1" class="left word-break-on-particular-width">A dynamic text(width of this will differ as per the text recieved)</div>
<div id="value1" class="right">
<button>button text</button>
</div>
</li>
</ul>
CSS Tables also
ul {
list-style-type: none;
display: table;
width: 50%;
margin: auto;
}
li {
display: table-row;
}
li div {
border: 1px solid grey;
padding: 1em;
display: table-cell;
vertical-align: middle;
}
.right {
white-space: nowrap;
}
<ul>
<li>
<div id="label" class="left word-break-on-particular-width">A dynamic text</div>
<div id="value" class="right">
<button>button text</button>
</div>
</li>
<li>
<div id="label1" class="left word-break-on-particular-width">A dynamic text(width of this will differ as per the text recieved)</div>
<div id="value1" class="right">
<button>button text</button>
</div>
</li>
</ul>

Vertical-align is not working on li

I'm trying to have my li element align in the middle - vertically.
But it looks like vertical-align is not working. Any ideas?
HTML
<body>
<div class="toolbar">
<ul>
<li>
<input type="radio" value="one" name="try" />
<img src="try1_30X30.png"/>
hello
</li>
<li>
<input type="radio" value="two" name="try" />
<img src="try2_30X30.png"/>
world
</li>
</ul>
</div>
</body>
CSS
.toolbar ul {
list-style-type: none;
height: 50px;
}
.toolbar ul li {
float: left;
display: block;
line-height: 50px;
padding-left: 10px;
vertical-align: middle;
}
Try to apply the vertical-align property to the img tag itself.
Please see code below or working example here (http://jsbin.com/oxoMeCo/1/)
<html>
<head>
<style type="text/css">
.toolbar ul {
list-style-type: none;
height: 50px;
}
.toolbar ul li
{
float: left;
display: block;
line-height: 50px;
padding-left: 10px;
}
.toolbar ul li img {
vertical-align:middle;
}
</style>
</head>
<body>
<div class="toolbar">
<ul>
<li>
<input type="radio" value="one" name="try" />
<img src="http://placehold.it/30x30">
hello
</li>
<li>
<input type="radio" value="two" name="try" />
<img src="http://placehold.it/30x30">
world
</li>
</ul>
</div>
</body>
</html>

website head-menu with text and picture

Please help me to solve my problem.
I need to make head menu with pictures.
Now i have:
What i need to do:
My HTML code here:
<div id="head">
<div class="site_info">
<div id="tabs">
<ul id="tabMenu">
<li class="dropdown">
<div><a class="tab1">поиск по производителю</a></div>
</li>
<li class="dropdown">
<div><a class="tab2">поиск по назначению</a></div>
</li>
<li class="dropdown">
<div>
<span id="more_search"></span>
<a class="tab4" href="/emarket/cart/">покупки</a>
</div>
</li>
<li class="dropdown">
<div><a class="tab3">сравнение</a></div>
</li>
<li class="dropdown">
<div><a class="tab3">кабинет</a></div>
</li>
</ul>
</div>
</div>
<div class="work" umi:element-id="40">
<div umi:field-name="order_info_top"></div>
</div>
</div>
CSS:
#main #head div.site_info {
padding-top: 45px;
}
#main #head div.site_info ul {
width: 50%;
margin: 0 auto;
min-width: 1024px;
}
#main #head div.site_info ul li {
display: inline;
margin-right: 18px;
}
#main #head div.site_info ul li a.tab1 a.tab2 a.tab3 a.tab4 {
float: left;
margin-left: 89px;
}
Give a height and width to the individual menu. Then add a style with your image as its background. Position the backgruond image top center.
HTML
<div>
<ul>
<li class="dropdown"><div><a class="tab1">Menu 1</a></div></li>
<li class="dropdown"><div><a class="tab2">Menu 2</a></div></li>
</li>
</ul>
</div>
CSS
li
{
list-style: none;
float: left;
width :100px;
}
.dropdown .tab1
{
background : url('http://www.indievisionmusic.com/wp-content/themes/indievisionmusic/images/at_symbol_10x10.gif') no-repeat top center;
padding-top: 10px;
}
.dropdown .tab2
{
background : url('http://www.gigabyte.us/images/icon_blue.png') no-repeat top center;
padding-top: 10px;
}
DEMO
Just change your text for <img src="images/image.jpg">
And if you want it to be a link: <img src="images/image.jpg" width="100" height="100"/>
you could just use images instead of text and add in the image using the CSS backgroundd feature
li a.tab1 { background: url(); width:XXpx; height: XXpx }
li a.tab2 { background: url(); width:XXpx; height: XXpx }
li a.tab3 { background: url(); width:XXpx; height: XXpx }

Resources