I have a ul li list, I am trying to align li to center of the ul.
I have attached my HTML code and CSS.
Important: On li hover I have added some animation (margin-top).
Expected output: Align li to the center of ul without affecting li,
#content-right {
border-top: 3px solid #f1f1f1;
border-bottom: 3px solid #f1f1f1;
width: 100%;
border: 1px solid green;
float: left;
}
#content-right {
float: left;
height: 159px;
}
#partner-icons {
margin: 0 0 0 20px;
padding: 0;
text-align: center;
}
#partner-icons li {
list-style: none;
float: left;
margin: 10px;
text-align: center;
width: 14%;
text-transform: uppercase;
font-size: 0.8em;
height: 50px;
font-weight: 700;
display: inline-block;
}
#partner-icons li figure {
color: #e90e0e;
}
#partner-icons li img {
width: 90%;
margin-bottom: 10px;
}
#partner-icons li figure {
transition: all 0.2s ease;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
}
#partner-icons li:hover figure {
margin-top: 5px;
}
<div id="content-right">
<ul id="partner-icons" class="cf">
<li id="first">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
ABCDEF
</li>
<li id="second">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
GHJIDDK
</li>
<li id="fifth">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
FDSNOISD
</li>
<li id="sixth">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
GDSFDSDSD
</li>
</ul>
</div>
I tried my self to align it to center, I changed the CSS of li (float:none), It's working fine but on hover animation is not working.
Please, can anyone help to resolve this.
Remove float:left and add vertical-align: top; to li, by default inline-block elements are aligned to baseline that's why removing margin affects all li elements.
#content-right {
border-top: 3px solid #f1f1f1;
border-bottom: 3px solid #f1f1f1;
width: 100%;
border: 1px solid green;
float: left;
}
#content-right {
float: left;
height: 159px;
}
#partner-icons {
margin: 0 0 0 20px;
padding: 0;
text-align: center;
}
#partner-icons li {
list-style: none;
/*float: left;*/
margin: 10px;
text-align: center;
width: 14%;
text-transform: uppercase;
font-size: 0.8em;
height: 50px;
font-weight: 700;
display: inline-block;
vertical-align: top;
}
#partner-icons li figure {
color: #e90e0e;
}
#partner-icons li img {
width: 90%;
margin-bottom: 10px;
}
#partner-icons li figure {
transition: all 0.2s ease;
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
}
#partner-icons li:hover figure {
margin-top: 5px;
}
<div id="content-right">
<ul id="partner-icons" class="cf">
<li id="first">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
Offers
</li>
<li id="second">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
Fantasy Football
</li>
<li id="fifth">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
Find a Job
</li>
<li id="sixth">
<figure>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/256/cat-icon.png">
</figure>
Buy Sell
</li>
</ul>
</div>
Related
I'm having a lot of troubles trying to do this. I finally found how to do an expansion animation for an aside menu im doing, when I hover one of its elements.
The problem is that i want to do an animation to close it as well. I tried making an animation as the open animation (with from -> to) and it doesn't work.
I tried making transitions with max height, using the different containers in the list (ul, div, li, whatever one by one), I tried searching different kinds of already made animations, but none worked, the menu just pop out and disappear without animation.
What I basically want is a smooth animation to move the other elements down (reached), and then up when the menu closes.
Actually it has 2 animations: to expand the max height, and to move it from right to left. but I can't reach to close it with animation.
I don't want to use Javascript, because is for school project but we haven't seen it yet.
https://jsfiddle.net/exrp4doa/
#-webkit-keyframes slider {
from {
border-left: 300px
}
to {
border-left: 0px
}
}
#keyframes slider {
from {
margin-left: 300px
}
to {
margin-left: 0px
}
}
#-webkit-keyframes altura {
from {
max-height: 0px
}
to {
max-height: 500px
}
}
#keyframes altura {
from {
max-height: 0px
}
to {
max-height: 500px
}
}
aside {
width: 25%;
display: inline-block;
vertical-align: top;
margin-top: 20px;
margin-bottom: 20px;
}
aside > div:not(#marcador) {
background-color: rgb( 40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-top: 5px;
margin-right: -15px;
font-family: 'Press Start 2P';
font-size: 0.7em;
line-height: 10px;
padding: 15px;
-moz-transition: opacity 0.4s ease-in-out;
-o-transition: opacity 0.4s ease-in-out;
-webkit-transition: opacity 0.4s ease-in-out;
transition: opacity 0.4s ease-in-out;
}
#marcador div {
display: none;
opacity: 0;
visibility: hidden;
position: static;
}
#marcador li:hover >div {
display: block;
opacity: 1;
visibility: visible;
padding-left: 20px;
-webkit-animation-name: slider;
-webkit-animation-duration: 0.5s;
animation-name: slider;
animation-duration: 0.5s;
}
#marcador li li {}
#marcador li:hover li {
-webkit-animation-name: altura;
-webkit-animation-duration: 5s;
animation-name: altura;
animation-duration: 5s;
}
#marcador li:hover >a {
display: block;
opacity: 1;
visibility: visible;
}
#marcador ul {
margin: 0;
padding: 0;
list-style-type: none;
position: static;
}
#marcador ul li>a {
background-color: rgb( 40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-top: 5px;
margin-right: -15px;
font-family: 'Press Start 2P';
font-size: 0.7em;
line-height: 10px;
padding: 15px;
padding-left: 35px;
}
#marcador ul ul {
padding: 0;
margin: auto;
}
#marcador ul ul a {
margin-left: 20px;
background-color: dimgray;
}
#marcador ul ul ul a {
margin-left: 40px;
background-color: gray;
color: black;
}
#marcador img {
float: left;
vertical-align: middle;
display: inline-block;
opacity: 0;
position: absolute;
visibility: hidden;
margin-left: -20px;
}
#marcador li:hover>a>img {
opacity: 1;
visibility: visible;
}
#marcador a:hover {
color: orange;
}
<aside>
<div id="marcador">
<ul>
<li>
<a><img src="Recursos/Select.png" />Inicio</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Juegos</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />Sega</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />Arcade</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Nintendo</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />NES</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Consolas</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES Mini</a>
</li>
<li>
<a><img src="Recursos/Select.png" />NES Mini</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />SEGA GENESIS</a>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Compras</a>
</li>
<li>
<a><img src="Recursos/Select.png" />DIY</a>
</li>
<li>
<a onclick="alert('Página en construcción')"><img id="info" src="Recursos/info.png" alt="INFO" /></a>
</li>
</ul>
</div>
</aside>
You can use transition instead of animation. My demo:
aside {
width: 25%;
display: inline-block;
vertical-align: top;
margin-top: 20px;
margin-bottom: 20px;
}
aside > div:not(#marcador) {
background-color: rgb(40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-top: 5px;
margin-right: -15px;
font-family: "Press Start 2P";
font-size: 0.7em;
line-height: 10px;
padding: 15px;
-moz-transition: opacity 0.4s ease-in-out;
-o-transition: opacity 0.4s ease-in-out;
-webkit-transition: opacity 0.4s ease-in-out;
transition: opacity 0.4s ease-in-out;
}
#marcador li> div {
opacity: 0;
margin-left: 300px;
-webkit-transition: all 0.5s;
transition: all 0.5s;
}
#marcador li:hover > div {
opacity: 1;
padding-left: 20px;
margin-left: 0;
}
#marcador li> div >ul >li {
max-height: 0;
transition: all 0.5s;
}
#marcador li:hover> div >ul >li {
max-height: 40px;
}
#marcador li:hover{
max-height: 500px !important;
}
#marcador li:hover > a {
display: block;
opacity: 1;
visibility: visible;
}
#marcador ul {
margin: 0;
padding: 0;
list-style-type: none;
position: static;
}
#marcador ul li > a {
background-color: rgb(40, 44, 47);
border-radius: 15px;
box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.055);
color: silver;
display: block;
margin-right: -15px;
font-family: "Press Start 2P";
font-size: 0.7em;
line-height: 10px;
padding: 15px;
padding-left: 35px;
}
#marcador ul ul {
padding: 0;
margin: auto;
}
#marcador ul ul a {
margin-left: 20px;
background-color: dimgray;
}
#marcador ul ul ul a {
margin-left: 40px;
background-color: gray;
color: black;
}
#marcador img {
float: left;
vertical-align: middle;
display: inline-block;
opacity: 0;
position: absolute;
visibility: hidden;
margin-left: -20px;
}
#marcador li:hover > a > img {
opacity: 1;
visibility: visible;
}
#marcador a:hover {
color: orange;
}
<aside>
<div id="marcador">
<ul>
<li>
<a><img src="Recursos/Select.png" />Inicio</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Juegos</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />Sega</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />Arcade</a>
</li>
<li>
<a><img src="Recursos/Select.png" />Nintendo</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />NES</a>
</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Consolas</a>
<div>
<ul>
<li>
<a><img src="Recursos/Select.png" />SNES Mini</a>
</li>
<li>
<a><img src="Recursos/Select.png" />NES Mini</a>
</li>
<li>
<a class=ult><img src="Recursos/Select.png" />SEGA GENESIS</a>
</li>
</ul>
</div>
</li>
<li>
<a><img src="Recursos/Select.png" />Compras</a>
</li>
<li>
<a><img src="Recursos/Select.png" />DIY</a>
</li>
<li>
<a onclick="alert('Página en construcción')"><img id="info" src="Recursos/info.png" alt="INFO" /></a>
</li>
</ul>
</div>
</aside>
I have a header consists of a website name (at the left part) and a horizontal navigation menu (at the right part). My objective is to add a slogan under the site name. Meanwhile, the bottom of site name should still completely match with the bottom of menu elements, the only change is adding slogan.
Here are my header and a picture with expected result: https://jsfiddle.net/1nc9ch3x/1/
Give me please a hint how to figure it out. Thank you in advance!
body {
background: url(http://i.imgur.com/Asbdvgw.png);
font-family: 'Open Sans', sans-serif;
}
header {
width: 950px;
margin: auto;
position: relative;
background: #fff;
overflow: hidden;
}
.wrapper {
width: 950px;
margin: 0 auto;
}
header .logo {
display: inline;
border-left: 1px dashed #333333;
padding: 0 0 25px 10px;
text-decoration: none;
float: left;
font-size: 30px;
color: #cc3333;
margin: 25px 0px;
}
header nav {
float: right;
margin: 25px 0px;
}
header nav ul {
margin-top: 0px;
}
header nav ul li {
display: block;
float: left;
}
header nav ul li a {
text-decoration: none;
color: #333333;
font-size: 17px;
padding-top: 15px;
padding-bottom: 15px;
transition: all .2s linear;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover {
color: #cc3333;
border-top: 1px dashed #cc3333;
border-bottom: 1px dashed #cc3333;
}
header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}
header li:first-child {
border: none;
}
<header>
<div class="wrapper">
<div class="logo">
Name
</div>
<nav>
<ul>
<li>Category 1
</li>
<li>Category 2
</li>
<li>Category 3
</li>
<li>Category 4
</li>
</ul>
</nav>
</div>
</header>
<br>
<br>
<center><font color="#fff">My goal:</font>
<br>
<br>
<img src="http://i.imgur.com/aW7k0QI.png">
This should do the trick : Fiddle : https://jsfiddle.net/1nc9ch3x/3/
HTML :
<div class="logo">
Name<span>Slogan</span>
</div>
CSS :
header .logo {
position:relative;
}
header .logo span {
white-space:nowrap;
color:black;
font-size:18px;
position:absolute;
bottom:0;
left:10px;
}
To achieve what you want is as easy as putting the following code inside <div class="logo">:
<p id = "slogan">Slogan should be right here</p>
Then, you can go in your CSS file and make the necessary changes for #slogan. Something like the following:
#slogan {
color: #0c0c0c;
font-size: 16px;
display: block;
margin-top: 5px;
}
You can check out this working demo or the following snippet.
Snippet:
body {
background: url(http://i.imgur.com/Asbdvgw.png);
font-family: 'Open Sans', sans-serif;
}
header {
width: 100%;
height: 100px;
margin: auto;
position: relative;
background: #fff;
overflow: hidden;
}
.wrapper {
width: 950px;
margin: 0 auto;
}
header .logo {
display: inline;
border-left: 1px dashed #333333;
padding: 0 0 25px 10px;
text-decoration: none;
float: left;
font-size: 30px;
color: #cc3333;
margin: 25px 0px;
}
header nav {
float: right;
margin: 25px 0px;
}
header nav ul {
margin-top: 0px;
}
header nav ul li {
display: block;
float: left;
}
header nav ul li a {
text-decoration: none;
color: #333333;
font-size: 17px;
padding-top: 15px;
padding-bottom: 15px;
transition: all .2s linear;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover {
color: #cc3333;
border-top: 1px dashed #cc3333;
border-bottom: 1px dashed #cc3333;
}
header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}
header li:first-child {
border: none;
}
#slogan {
margin-top: 5px;
color: #0c0c0c;
font-size: 16px;
display: block;
}
<header>
<div class="wrapper">
<div class="logo">
Name
<p id="slogan">Slogan should be right here</p>
</div>
<nav>
<ul>
<li>Category 1
</li>
<li>Category 2
</li>
<li>Category 3
</li>
<li>Category 4
</li>
</ul>
</nav>
</div>
</header>
Get your code:
html:
<header>
<div class="wrapper">
<div class="logo">
<h4>
Name
</h4>
<p>your slogan here</p>
</div>
<nav>
<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
</ul>
</nav>
</div>
</header>
<br><br>
<center><font color="#fff">My goal:</font><br><br>
<img src="http://i.imgur.com/aW7k0QI.png">
css:
body {
background: url(http://i.imgur.com/Asbdvgw.png);
font-family: 'Open Sans', sans-serif;
margin:0;
}
header {
width: 950px;
margin: auto;
position: relative;
background: #fff;
overflow: hidden;
}
.wrapper {
width: 950px;
margin: 0 auto;
}
header .logo{
border-left: 1px dashed #333333;
padding:5px 10px;
}
header .logo h4{
padding: 0px ;
text-decoration: none;
font-size: 30px;
color: #cc3333;
padding: 10px;
padding-bottom:0;
}
.logo h4{
margin:0;
padding:0;
}
.logo p{
color:rgba(0,0,0,0.7);
margin:0;
padding:0 10px;
}
header nav{
position:absolute;
right:0;
top:0;
margin: 0px 0px;
}
header nav ul{
margin: 0px;
}
header nav ul li{
display: block;
float: left;
margin: 0px;
}
header nav ul li a{
text-decoration: none;
color: #333333;
font-size: 17px;
padding-top: 15px;
padding-bottom: 15px;
transition: all .2s linear;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
-o-transition: all .2s linear;
}
header nav ul li a.active,
header nav ul li a:hover{
color: #cc3333;
border-top: 1px dashed #cc3333;
border-bottom: 1px dashed #cc3333;
}
header li {
display: inline;
border-left: 1px dashed #cc3333;
padding: 10px 25px 10px 25px;
}
header li:first-child {
border: none;
}
Here's an updated Fiddle.
Critical CSS:
header .slogan {
color: #000;
font-size: 20px;
display: block;
}
And HTML:
<div class="logo">
Name
<span class="slogan">Tagline here</span>
</div>
#menu {
width: 100%;
margin: 10px auto;
}
#menu ul,
#menu li {
margin: 0 auto;
padding: 0 0;
list-style: none
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
}
#menu li a {
border-right: 1px solid #e5e5e5;
}
#menu li a:hover {
color: #444;
background-color: #e5e5e5;
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 30px;
opacity: 0;
}
#menu label {
font-size: 20px;
display: none;
width: 35px;
height: 20px;
line-height: 20px;
text-align: center;
color: #77778b
}
#menu label span {
position: absolute;
left: 35px;
}
#menu ul.menus {
height: auto;
overflow: hidden;
width: 180px;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
position: absolute;
z-index: 99;
display: none;
left: -1px;
}
#menu ul.menus li {
display: block;
width: 100%;
}
#menu ul.menus a {
color: #77778b;
}
#menu li:hover ul.menus {
display: block
}
<nav id='menu'>
<input type='checkbox' />
<label><i class='icon-reorder' /><span>Menu</span>
</label>
<ul>
<li><a href='/'>Home</a>
</li>
<li><a class='dropdown' href='#'>Menu1</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
</ul>
</li>
<li><a class='dropdown' href='#'>Menu2</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
<li><a href='#'>Submenu3</a>
</li>
</ul>
</li>
</ul>
</nav>
How can I make the Dropdowns Fade in with only CSS? A bit noobish question but still trying to understand CSS Any one have any idea how to make it possible plz suggest it.
Thanks !
One possible solution is to use opacity: 0 instead of display: none and using transition on hover:
#menu {
width: 100%;
margin: 10px auto;
}
#menu ul,
#menu li {
margin: 0 auto;
padding: 0 0;
list-style: none
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
}
#menu li a {
border-right: 1px solid #e5e5e5;
}
#menu li a:hover {
color: #444;
background-color: #e5e5e5;
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 30px;
opacity: 0;
}
#menu label {
font-size: 20px;
display: block;
width: 35px;
height: 20px;
line-height: 20px;
text-align: center;
color: #77778b;
visibility: hidden;
}
#menu label span {
position: absolute;
left: 35px;
}
#menu ul.menus {
height: auto;
overflow: hidden;
width: 180px;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
position: absolute;
z-index: 99;
display: block;
left: -1px;
opacity: 0;
}
#menu ul.menus li {
display: block;
width: 100%;
}
#menu ul.menus a {
color: #77778b;
}
#menu li:hover ul.menus {
opacity: 1;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
<nav id='menu'>
<input type='checkbox' />
<label><i class='icon-reorder' /><span>Menu</span>
</label>
<ul>
<li><a href='/'>Home</a>
</li>
<li><a class='dropdown' href='#'>Menu1</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
</ul>
</li>
<li><a class='dropdown' href='#'>Menu2</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
<li><a href='#'>Submenu3</a>
</li>
</ul>
</li>
</ul>
</nav>
Also you can use transition same way to animate on mouse out:
#menu {
width: 100%;
margin: 10px auto;
}
#menu ul,
#menu li {
margin: 0 auto;
padding: 0 0;
list-style: none
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 35px;
padding: 0 14px;
text-decoration: none;
}
#menu li a {
border-right: 1px solid #e5e5e5;
}
#menu li a:hover {
color: #444;
background-color: #e5e5e5;
}
#menu input {
display: none;
margin: 0 0;
padding: 0 0;
width: 80px;
height: 30px;
opacity: 0;
}
#menu label {
font-size: 20px;
display: block;
width: 35px;
height: 20px;
line-height: 20px;
text-align: center;
color: #77778b;
visibility: hidden;
}
#menu label span {
position: absolute;
left: 35px;
}
#menu ul.menus {
height: auto;
overflow: hidden;
width: 180px;
border-top: 1px solid #e5e5e5;
border-left: 1px solid #e5e5e5;
border-bottom: 1px solid #e5e5e5;
position: absolute;
z-index: 99;
display: block;
left: -1px;
opacity: 0;
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
}
#menu ul.menus li {
display: block;
width: 100%;
}
#menu ul.menus a {
color: #77778b;
}
#menu li:hover ul.menus {
opacity: 1;
-webkit-transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-ms-transition: opacity 1s ease-in-out;
-o-transition: opacity 1s ease-in-out;
transition: opacity 1s ease-in-out;
}
<nav id='menu'>
<input type='checkbox' />
<label><i class='icon-reorder' /><span>Menu</span>
</label>
<ul>
<li><a href='/'>Home</a>
</li>
<li><a class='dropdown' href='#'>Menu1</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
</ul>
</li>
<li><a class='dropdown' href='#'>Menu2</a>
<ul class='menus'>
<li><a href='#'>Submenu1</a>
</li>
<li><a href='#'>Submenu2</a>
</li>
<li><a href='#'>Submenu3</a>
</li>
</ul>
</li>
</ul>
</nav>
I have the following HTML:
<div id="resultList">
<ul>
<li class="product"> Hevea fopspeentje Kroon
</li>
<li class="product"> BabyBjörn Babybord met babylepel 2-Pack
</li>
<li class="product"> Janod Scooter Vanilla
</li>
<li class="product"> Numi-Med Medicijnspeen met doseerschijf Wit (6-18 mnd)
</li>
</ul>
</div>
and CSS:
#resultList {
max-width: 557px;
margin-top: 13px;
padding: 20px;
border: 4px solid #c7c6c6;
border-radius: 4px;
background: #ffffff;
}
#resultList a {
padding: 8px 14px;
color: #072f49;
text-decoration: none;
display: block;
}
#resultList ul li {
margin-bottom: 10px;
color: #072f49;
list-style: none;
background: #f5f5f5;
display: inline-block;
-webkit-transition: background 0.3s ease;
-moz-transition: background 0.3s ease;
-o-transition: background 0.3s ease;
transition: background 0.3s ease;
}
#resultList .product {
width: 100%;
display: inline-block;
}
and the jsFiddle
I would like each product do be on a different line. That is why I set #resultList .product to width:100; However, I would like the background of the #resultList ul li to only be as long as the text itself.
Is there a way to do this?
Move the background-color to the <a> element inside the <li>.
http://jsfiddle.net/NicoO/7nR7T/4/
#resultList ul li {
margin-bottom: 10px;
list-style: none;
display: block;
}
#resultList .product A {
color: #072f49;
background: #f5f5f5;
display: inline-block;
}
add background css code for a and remove background in li. Demo
#resultList a {
background:#F5F5F5;
color: #072F49;
display: block;
float: left;
padding: 8px 14px;
text-decoration: none;
}
#resultList ul li {
margin-bottom: 10px;
list-style: none;
display: inline-block;
}
You can make the width:inherit instead of setting to 100% in #resultList .product.
Updated fiddle. DEMO.
I have this submenu and I would like it so that when the dropdown menu is out it has a width of 100% and covers the whole page. At the moment if I change the width to 100% it just makes it the same width as the main menu.
This is my current HTML:
<header>
<div class="header">
<div class="nav">
<ul>
<li> Services
<ul class="sub"> <a href="services.html#branddesign">
<li><img class="imgcenter" src="images/Brand-Design-Circle-Blue.png" width="100px" />
<br>
Brand Design
</li></a>
<a href="services.html#brandonline">
<li><img class="imgcenter" src="images/Brand-Online-Circle-Blue.png" width="100px" />
<br>
Brand Online
</li></a>
<a href="services.html#brandmarketing">
<li><img class="imgcenter" src="images/Brand-Marketing-Circle-Blue.png" width="100px" />
<br>
Brand Marketing
</li></a>
<a href="services.html#brandmanagement">
<li><img class="imgcenter" src="images/Brand-Management-Circle-Blue.png" width="100px" />
<br>
Brand Management
</li></a>
</ul>
</li>
<li> Clients
</li>
<li> About
</li>
<li> Contact Us
</li>
</ul>
</div>
</div>
</div>
and this CSS:
.header {
position: fixed;
display: block;
float: left;
width: 100%;
height: auto;
background-color: #666;
z-index: 9999;
}
.nav {
position: static;
float: left;
width: 500px;
height: 50px;
margin: 10px 5px;
}
.nav a {
text-decoration: none;
color: #FFFFFF;
}
.nav ul > li:first-child {
padding-bottom: 25px;
}
.nav a:hover {
text-decoration: none;
color: #6db6e5;
}
.nav li {
font-family: "eras_demi_itcregular", Arial, Helvetica;
list-style: none;
float: left;
margin-right: 50px;
}
.nav li:hover a:hover {
padding-bottom: 5px;
border-bottom: 2px solid #6db6e5;
color: #6db6e5;
}
.nav ul li:hover > ul {
height:150px;
}
.nav ul {
list-style: none;
position: absolute;
display: inline-block;
margin-top: 23px;
}
.nav ul ul {
width: 494px;
background: #7d7c7c;
height: 0px;
overflow: hidden;
padding-left:0;
margin-left:0;
font-size: 12px;
text-align: center;
-webkit-transition:all .5s ease-in-out;
-moz-transition:all .5s ease-in-out;
-o-transition:all .5s ease-in-out;
transition:all .5s ease-in-out;
}
.nav ul ul li {
padding: 10px;
margin-left: -1px;
margin-right: 0;
height: 129px;
}
.nav ul ul li:last-child {
}
.nav ul ul li:hover {
background: #666;
}
.nav li li {
height:130px;
-webkit-transition:all .3s ease-in-out;
}
Can anyone please tell me how I can make it so that the submenu can be wider than the main menu?
Try adding this to your CSS:
nav ul ul {
width: 100vw;
left: 0;
}
Fiddle: http://jsfiddle.net/9QE58/1/embedded/result/
That should keep it at 100% of the viewport width no matter what the pixel width is.