I have a ul list and there i have given hover effect using :after this is working fine on hover, but now i want to it will be start from center instead of left.
My Code:
ul.my-list{ margin: 20px; padding: 0px; width: 200px;}
ul.my-list li{ list-style: none; position: relative; display: inline;}
ul.my-list li a{ color:#333; text-decoration: none;}
ul.my-list li:after{ content: ''; position: absolute; left: 0px; bottom: -2px; width:0px; height: 2px; background: #333; transition: all 0.45s;}
ul.my-list li:hover:after{ width: 100%;}
ul.my-list li a:hover{ text-decoration: none;}
<ul class="my-list">
<li>Welcome to my website</li>
</ul>
Quick solution:
Move the original position to left:50% and then, on hover, move it to left:0.
ul.my-list {
margin: 20px;
padding: 0px;
width: 200px;
}
ul.my-list li {
list-style: none;
position: relative;
display: inline;
}
ul.my-list li a {
color: #333;
text-decoration: none;
}
ul.my-list li:after {
content: '';
position: absolute;
left: 50%;
bottom: -2px;
width: 0px;
height: 2px;
background: #333;
transition: all 0.45s;
}
ul.my-list li:hover:after {
width: 100%;
left: 0;
}
ul.my-list li a:hover {
text-decoration: none;
}
<ul class="my-list">
<li>Welcome to my website</li>
</ul>
You can simplify your code using background like below
ul.my-list {
margin: 20px;
padding: 0px;
width: 200px;
}
ul.my-list li {
list-style: none;
display: inline-block;
padding-bottom:2px; /*the space for the gradient*/
background: linear-gradient(#333,#333) center bottom; /*OR bottom right OR bottom left*/
background-size: 0% 2px; /*width:0% height:2px*/
background-repeat:no-repeat; /* Don't repeat !!*/
transition: all 0.45s;
}
ul.my-list li a {
color: #333;
text-decoration: none;
}
ul.my-list li:hover {
background-size: 100% 2px; /*width:100% height:2px*/
}
<ul class="my-list">
<li>Welcome to my website</li>
</ul>
This is simple, you call the element after left 50% that means this it's the goon left to the middle when you hover the element after the width 100% and left 0, you already added some transition So, it looks middle to left and right. here the code;
ul.my-list{ margin: 20px; padding: 0px; width: 200px;}
ul.my-list li{ list-style: none; position: relative; display: inline;}
ul.my-list li a{ color:#333; text-decoration: none;}
ul.my-list li:after{
content: '';
position: absolute;
left: 50%; /* change this code 0 to 50%*/
bottom: -2px;
width:0px;
height: 2px;
background: #333;
transition: all 0.45s;
}
ul.my-list.rtl li:after { right: 0; left: inherit; }
ul.my-list li:hover:after{ left:0; width: 100%;} /* add poperty left 0 */
ul.my-list li a:hover{ text-decoration: none;}
<ul class="my-list">
<li>Welcome to my website</li>
</ul>
<h2>left start and end right</h2>
<ul class="my-list rtl">
<li>Welcome to my website</li>
</ul>
= = =
Thank you
= = =
Related
I have a nav bar and below text I am putting a thin line using :after.
I want that line in the middle of the li tag.
ul {
background: black;
}
ul li {
display: inline-block;
padding: 20px 10px;
cursor: pointer;
}
ul li a {
text-decoration: none;
color: #FFFFFF;
}
ul li:hover {
background: #5249FF;
}
ul li:after {
content: '';
width: 10px;
height: 3px;
background: #fff;
position: absolute;
top: 20%;
left: 15px;
}
<ul>
<li>
HOME
</li>
<li>
WORLD
</li>
<li>
SPORTS
</li>
</ul>
I want white thin line in the center of each li tag.
Any help would be great.
Thank You.
I think you want to like this
ul {
background: black;
}
ul li {
display: inline-block;
padding: 20px 10px;
cursor: pointer;
position: relative;
}
ul li a {
text-decoration: none;
color: #FFFFFF;
}
ul li:hover {
background: #5249FF;
}
ul li::after {
background: #fff;
bottom: 10px;
content: "";
height: 3px;
left: 0;
margin: auto;
position: absolute;
right:0;
width: 10px;
}
<ul>
<li>
HOME
</li>
<li>
WORLD
</li>
<li>
SPORTS
</li>
</ul>
to position: absolute; something relative to it's parent - you need a positioned parent.
Let's use position:relative; for the a elements:
body{background:#444;}
ul {
background: black;
padding: 0;
}
ul li {
display: inline-block;
cursor: pointer;
/*padding: 20px 10px;*/
}
ul li a {
position:relative; /* add */
display: block; /* add */
padding: 20px 10px; /* add */
text-decoration: none;
color: #FFFFFF;
}
ul li a:hover { /* anchor hover! */
background: #5249FF;
}
ul li a:after { /* anchor after! */
content: '';
width: 10px;
height: 3px;
background: #fff;
position: absolute;
/*top: 20%; 20% of what*/
top: 40px;
/*left: 15px; 15px is not centering*/
left: 0;
right: 0;
margin: 0 auto /* center */
}
<ul>
<li>
HOME
</li>
<li>
WORLD
</li>
<li>
SPORTS
</li>
</ul>
Don't use paddings on LI elements - think about accessibility, rather set your paddings to the Anchor elements, that way their clickable size is expanded.
position:absolute elements are "absolute" relatively to the first position:relative parent, at your example, there is no relative parent, therefore they become relative to body.
What you need to do is to add position:relative to your li element.
You need to use left: 50%; transform:translateX(-50%); inside ul li:after and position:relative; inside ul li
ul {
background: black;
}
ul li {
display: inline-block;
padding: 20px 10px;
cursor: pointer;
position:relative;
}
ul li a {
text-decoration: none;
color: #FFFFFF;
}
ul li:hover {
background: #5249FF;
}
ul li:after {
content: '';
width: 10px;
height: 3px;
background: #fff;
position: absolute;
top: 20%;
left: 50%;
transform:translateX(-50%);
}
<ul>
<li>
HOME
</li>
<li>
WORLD
</li>
<li>
SPORTS
</li>
</ul>
I am using simple HTML and CSS to create horizontal menu using unordered list.
This is HTML & CSS code:
.nav_bar{
margin-left: 700px;
margin-top: 40px;
position: absolute;
}
.nav_bar ul{
list-style-type: none;
}
.nav_bar ul li{
display: inline-block;
text-align: center;
float: left;
}
.nav_bar ul li a{
text-decoration: none;
padding: 12px;
margin: 8px;
font-size: 20px;
color: #fff;
}
.nav_bar ul li a::after{
content: '';
display: inline-block;
width: 0px;
height: 4px;
background: #ff6600;
transition: width .4s;
}
.nav_bar ul li a:hover::after{
width: 100%;
}
<div class="nav_bar">
<ul>
<li>Services</li>
<li>Solution</li>
<li>Support</li>
<li>Partners</li>
<li>Contacts</li>
</ul>
</div>
I don't know where is the problem and why it is occurring?
Please help me out with good reason..
Ive fixed your code and ive got something like this.
.nav_bar ul li a{
text-decoration: none;
padding: 12px;
margin: 8px;
font-size: 20px;
color: orange;
position: relative;
}
.nav_bar ul li a::after{
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
height: 4px;
background: #ff6600;
transition: width .4s;
width: 0;
}
the problem is your after element is displayed inline-block so it rendered inline with your achor tag. and since your achor tag doesnt have enough width to display the ::after inline, your ::after element wrapped after your anchor tag.
see this: https://jsfiddle.net/pm68Lzmv/
Try this:
Add position:absolute; to :after selector for a tag
Remove margin-left from .nav_bar and add right:0
.nav_bar{
margin-top: 40px;
position: absolute;
right:0;
}
.nav_bar ul{
list-style-type: none;
}
.nav_bar ul li{
display: inline-block;
text-align: center;
float: left;
}
.nav_bar ul li a{
text-decoration: none;
padding: 12px;
margin: 0;
font-size: 20px;
color: #aaa;
display:block;
position:relative;
}
.nav_bar ul li a::after{
content: '';
display: inline-block;
width: 0px;
height: 4px;
background: #ff6600;
transition: width .4s;
position:absolute;
left:50%;
bottom:0;
transform: translateX(-50%);
}
.nav_bar ul li a:hover::after{
width: 100%;
}
<div class="nav_bar">
<ul>
<li>Services</li>
<li>Solution</li>
<li>Support</li>
<li>Partners</li>
<li>Contacts</li>
</ul>
</div>
Remove .nav_bar{ margin-left:0px}
Add .nav_bar ul li a position:relative;
add .nav_bar ul li a:after position:absolute;
.nav_bar ul{
list-style-type: none;
}
.nav_bar ul li{
display: inline-block;
text-align: center;
}
.nav_bar ul li a{
text-decoration: none;
padding: 12px;
margin: 0;
font-size: 20px;
color: #aaa;
display:block;
position:relative;
}
.nav_bar ul li a::after{
content: '';
display: inline-block;
width: 0px;
height: 4px;
background: #ff6600;
transition: width .4s;
position:absolute;
left:50%;
bottom:0;
transform: translateX(-50%);
}
.nav_bar ul li a:hover::after{
width: 100%;
}
<div class="nav_bar">
<ul>
<li>Services</li>
<li>Solution</li>
<li>Support</li>
<li>Partners</li>
<li>Contacts</li>
</ul>
</div>
Can someone help me what is wrong with my code why the "admin's" tab drop down menu does not stay on place where it should be. It should be below the admin tab, however when you put the mouse on the admin tab the drop down goes on the tab beside the admin. I tried to designate an id for the admin's ul however, nothing works. Stays the same. Thank you very much!!
HTML code
<div id="navbar">
<ul>
<li> Home</li>
<li> About us</li>
<li> Games
<ul>
<li> All Games</li>
<li> Outdoor Games</li>
<li> Indoor Games</li>
<li> Games in Groups </li>
<li> Games in Pair</li>
</ul>
</li>
<li>Admin
<ul id="list">
<li>Add entry</li>
<li>Passwor request / suggestions</li>
</ul>
</li>
<li> Contact us</li>
<li> Log out</li>
</ul>
</div>
CSS code:
/*CSS Naigation Bar*/
#navbar {
width: 100%;
height: 100%; }
#navbar ul {
width: 90%;
position: fixed;
list-style: none;
padding: 0;
margin: 0;
top: 0;
left: 12.5%;
right: 0;
z-index: 1;}
#navbar ul li {
background-color: black;
opacity: 0.7;
float: left;
height: 25%;
width: 16.5%;
padding: 0;
margin: 0;
font-family: Arial;
font-weight: bold;
font-size: 16.5px;
text-align: center;
line-height: 20px;}
#navbar ul li a {
display: block;
padding: 7% 10%;
text-decoration: none;
color: #E4E4E4;}
#navbar ul li a:hover {
background-color: transparent;
color: white;
text-shadow: 0px 0px 2px white, 0px 0px 2px white, 0px 0px 2px white;}
#navbar ul li ul {
list-style: none;
width: 20%;
padding: 0;
margin: 0;
position: absolute;
display: none;
top: 100%;
left: 32%;
right: 40%;
z-index: 1;}
#navbar ul li ul li {
width: 100%;
float: none;
background-color: black;
opacity: 10;
text-align: center;}
#navbar ul li:hover ul {
display: block;}
#navbar ul li ul #list{
list-style: none;
width: 20%;
padding: 0;
margin: 0;
position: absolute;
display: none;
top: 100%;
left: 50%;
right: 40%;
z-index: 1;}
/*end*/
Add position: relative to the parent list item.
#navbar ul li {
position: relative;
}
And you might want to add a width to the child list item, so it is readable.
#navbar ul li ul li {
width: 150px; /* for example */
}
Think that was your issue? Here's the fiddle I created
Remove list id; you don't need it; and replace this one css :
#navbar ul li ul {
list-style: none;
width: 100%;
padding: 0;
margin: 0;
position: relative;
display: none;
top: 100%;
left: 0;
right: 0;
z-index: 1;
}
Remove left right from #navbar ul li ul
add top padding to #navbar ul li ul
Set width 100% #navbar ul li ul
add position relative to #navbar ul li
#navbar ul li {
background-color: black;
opacity: 0.7;
float: left;
height: 25%;
width: 16.5%;
padding: 0;
margin: 0;
font-family: Arial;
font-weight: bold;
font-size: 16.5px;
text-align: center;
line-height: 20px;
position:relative;}
#navbar ul li ul {
list-style: none;
width: 100%;
padding: 0;
margin: 0;
padding-top:10px;
position: absolute;
display: none;
top: 100%;
z-index: 1;}
Fiddle:
http://jsfiddle.net/f3sokdxt/
refer https://jsfiddle.net/95rqykjx/
CSS changes are follows,
#navbar ul li ul, remove width: 20%; and left: 32%;
#navbar ul li add position: relative;
Add position: relative to #navbar ul li and
left: 0; width: 100%; to #navbar ul li ul
Hope this will solve your problem.
#navbar {
width: 100%;
height: 100%;
}
#navbar ul {
width: 90%;
position: fixed;
list-style: none;
padding: 0;
margin: 0;
top: 0;
left: 12.5%;
right: 0;
z-index: 1;
}
#navbar ul li {
background-color: black;
opacity: 0.7;
float: left;
height: 25%;
width: 16.5%;
padding: 0;
margin: 0;
font-family: Arial;
font-weight: bold;
font-size: 16.5px;
text-align: center;
line-height: 20px;
position: relative;
}
#navbar ul li a {
display: block;
padding: 7% 10%;
text-decoration: none;
color: #E4E4E4;
}
#navbar ul li a:hover {
background-color: transparent;
color: white;
text-shadow: 0px 0px 2px white, 0px 0px 2px white, 0px 0px 2px white;
}
#navbar ul li ul {
list-style: none;
width: 100%;
padding: 0;
margin: 0;
position: absolute;
display: none;
top: 100%;
left: 0;
right: 40%;
z-index: 1;
}
#navbar ul li ul li {
width: 100%;
float: none;
background-color: black;
opacity: 10;
text-align: center;
}
#navbar ul li:hover ul {
display: block;
}
#navbar ul li ul #list {
list-style: none;
width: 20%;
padding: 0;
margin: 0;
position: absolute;
display: none;
top: 100%;
left: 50%;
right: 40%;
z-index: 1;
}
<div id="navbar">
<ul>
<li> Home</li>
<li> About us</li>
<li>
Games
<ul>
<li> All Games</li>
<li> Outdoor Games</li>
<li> Indoor Games</li>
<li> Games in Groups </li>
<li> Games in Pair</li>
</ul>
</li>
<li>
Admin
<ul id="list">
<li>Add entry</li>
<li>Passwor request / suggestions</li>
</ul>
</li>
<li> Contact us</li>
<li> Log out</li>
</ul>
</div>
When I zoom my website the logo and text tend to not resize with the same proportionals as the div itself. The div is set up with % in the css to appear as the same size all the time. How do I make them resize equal when zooming?
I've tried to set the font size in %, but that doesn't work. The image is already the perfect size so I haven't resized that in the css.
Live example on the jsFiddle
HTML:
<div id=nav>
<div id="logo">
<img src="50.png">
</div>
<div id="menu">
<ul>
<li>Home</li>
<li>Music</li>
<li>Spotlight</li>
<li>Blog</li>
<li>What is ?</li>
</ul>
</div>
</div>
CSS:
#logo{
position: absolute;
left: 10px;
top: -2px;
}
#nav{
height: 7%;
background-color: #fbfbfb;
list-style-type: none;
position: fixed;
z-index: 100;
top: 0px;
width: 100%;
left: 0%;
border-bottom: 1px solid;
border-color: #02ddfe;
}
#menu{
width: 960px;
margin: 0 auto;
text-align: left;
position: fixed;
left: 2%;
font-size: 100%;
top: -2%;
}
#menu ul{
list-style-type: none;
text-align: center;
vertical-align: middle;
line-height: 47px;
position: absolute;
}
#menu ul ul{
display: none;
}
#menu ul a{
color: #bbbbbb;
text-decoration: none;
-webkit-transition: color 0.4s;
-moz-transition: color 0.4s;
transition: color 0.4s;
}
#menu ul li{
display: inline-block;
text-align: center;
}
#menu ul li a,visited{
color: #bbbbbb;
display: block;
padding: 0px;
padding-left: 20px;
text-decoration: none;
}
#menu ul li a:hover{
color: #4ebbe8;
text-decoration: none;
}
#menu ul li:hover ul{
display: block;
}
#menu ul ul{
background-color: #ffffff;
position: absolute;
display: none;
margin: 0px;
padding: 0px;
}
try this one : http://jsfiddle.net/rfv2h3m5/1/
code change :
HTML:
<div id="menu">
<ul>
<li>Home</li>
<li>Music</li>
<li>Spotlight</li>
<li>Blog</li>
<li>What is ?</li>
</ul>
</div>
css:
#logo{
position: absolute;
left: 10px;
top: 10px;
background:url("http://www.fnordware.com/superpng/pnggrad8rgb.png") no-repeat;
width:8%;
height:72%;
background-size: 100%;
}
#nav{
height: 40%;
background-color: #fbfbfb;
list-style-type: none;
position: fixed;
z-index: 100;
top: 0px;
width: 100%;
left: 0%;
border-bottom: 1px solid;
border-color: #02ddfe;
font-size : 100%;
}
#menu{
width: 90%;
margin: 0 auto;
text-align: left;
position: fixed;
left: 2%;
font-size: 100%;
top: -2%;
}
#menu ul{
list-style-type: none;
text-align: center;
vertical-align: middle;
}
#menu ul ul{
display: none;
}
#menu ul a{
color: #bbbbbb;
text-decoration: none;
-webkit-transition: color 0.4s;
-moz-transition: color 0.4s;
transition: color 0.4s;
}
#menu ul li{
display: inline-block;
text-align: center;
}
#menu ul li a,visited{
color: #bbbbbb;
display: block;
padding: 0px;
padding-left: 20px;
text-decoration: none;
}
#menu ul li a:hover{
color: #4ebbe8;
text-decoration: none;
}
#menu ul li:hover ul{
display: block;
}
#menu ul ul{
background-color: #ffffff;
position: absolute;
display: none;
margin: 0px;
padding: 0px;
}
Is there a particular way to make a <ul> a height? I have this structure:
<ul class="dropdown">
<li></li>
<li></li>
<li></li>
<li>
<ul id="sub_menu1"> // I have 4 of these
<li></li>
<li></li>
</ul>
</li>
</ul>
CSS:
ul.dropdown {
font-family: 'CapsuulaRegular', Arial, sans-serif;
position: relative;
padding: 0;
margin: 0;
z-index: 1;
}
ul.dropdown li a {
color: #b38201;
font-size: 18px;
}
ul.dropdown li {
display: block;
float: left;
color: #b38201;
font-weight: normal;
text-transform: uppercase;
padding: 38px 10px 12px 7px;
margin-left: 2px;
}
ul.dropdown a:hover {
color: #002565;
background-image: url(../images/menu-hover.png);
background-position: 50% 100%;
background-repeat: no-repeat;
}
.navSelected {
color: #002565;
background-image: url(../images/menu-hover.png);
background-position: 50% 100%;
padding:0;
margin:0;
background-repeat: no-repeat;
}
ul.dropdown a:active {
color: #ffa500;
}
ul.dropdown li a {
padding: 38px 7px 12px 7px;
}
ul.dropdown li:last-child a {
border-right: none;
}
/* Doesn't work in IE */
ul.dropdown li.hover, ul.dropdown li:hover {
color: black;
position: relative;
}
ul.dropdown li.hover a {
color: black;
}
/* LEVEL TWO */
#sub_menu1 {
width: 175px;
position: absolute;
left: -175px;
}
#sub_menu2 {
width: 175px;
position: absolute;
left: 0px;
}
#sub_menu3 {
width: 175px;
position: absolute;
left: 175px;
}
#sub_menu4 {
width: 175px;
position: absolute;
left: 200px;
}
ul.dropdown ul {
visibility: hidden;
position: relative;
top: 100%;
left: 0px;
font-size: 10px !important;
padding: 0;
margin: 0;
display: block;
}
ul.dropdown ul li {
background: #ccc;
}
ul.dropdown ul li {
font-weight: normal;
background: #f1f3f7;
color: #000;
/*border-bottom: 1px solid #ccc;*/
float: none;
padding: 10px;
margin: 0;
text-transform: none;
}
I having trouble making the <ul> that are hovered the same height. The go depending on what content is in them.
I want all the menus to be the same height, or within a wrapper of fixed height/width..
does this solve your question?
ul { height: 150px; }
if you apply this, all of your ul's will have the height of 150 pixels.
Edit
Well, you're using floating. Floating elements are ignored in the flow of the document. To overcome this problem you should add a overflow: hidden; to your ul.dropdown