.list li::after{
content:" ";
width:100%;
display: block;
position: absolute;
height: 2px;
background-color: green;
}
ul li a{
display: inline-block;
padding: 10px 20px;
line-height: 1.5;
font-size: 0.9em;
color: white;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
margin: 0 2.5px;
}
HTML
<ul>
<li>contact</li>
</ul>
When i get over mouse li tag, I want to have liner after it, but this liner should be the same width as his li. Also I don't know how to active ::after, after `:hover.
Use a simple gradient:
ul li a {
display: inline-block;
padding: 10px 20px;
line-height: 1.5;
font-size: 0.9em;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
margin: 0 2.5px;
background-image:linear-gradient(green,green);
background-size:0% 2px;
background-position:bottom left;
background-repeat:no-repeat;
transition:1s all;
}
a:hover {
background-size:100% 2px;
}
<ul>
<li>contact</li>
</ul>
What I would recommend is to make use of border-bottom on the <a> element. You can control how far away this underline is from the text with padding-bottom.
This avoids the need for ::after completely, and can be seen in the following:
body {
background: black;
}
ul li a {
display: inline-block;
/*padding: 10px 20px;*/
line-height: 1.5;
font-size: 0.9em;
color: white;
text-transform: uppercase;
font-weight: bold;
text-decoration: none;
margin: 0 2.5px;
padding-bottom: 10px;
border-bottom: 1px solid green;
}
<ul>
<li>contact</li>
</ul>
Note that the width of the line (the border) is controlled by the amount of horizontal padding on the element. I've commented this padding out in the above example to show the line at the exact same width as the link.
Related
Hey I'm trying to create a web with a nav bar. However when I hover one a tag(link) all the others moves for some reason and I can't find a solution , guess some play with css which I'm still learning.... any help for what's wrong here?
.container {
width: 85%;
margin: auto;
overflow: hidden;
}
header {
background-color: #262626;
color: white;
padding-top: 20px;
min-height: 70px;
}
header a {
color: white;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
transition: color 0.3s;
display: block;
padding: 8px 16px;
}
header a:hover {
padding: 8px 16px;
border-color: #2a2a2a;
color: #D52B1E;
letter-spacing: 1.5px;
border: none;
cursor: pointer;
outline: none;
display: block;
}
header li {
display: inline;
padding: 0 20px 0 20px;
display: inline-flex;
}
header #logo {
float: left;
}
header #logo h1 {
margin: 0;
font-family: 'Dancing Script', cursive;
}
header nav {
float: right;
margin-top: 10px;
}
<header>
<div class="container">
<div id="logo">
<h1>Coupon<span style="color:#D52B1E">System</span></h1>
</div>
<nav>
<ul>
<li><a routerLink="/home">Home</a></li>
<li><a routerLink="/about">About</a></li>
<li><a routerLink="/contact">Contact</a></li>
</ul>
</nav>
</div>
</header>
appreciate any help, thanks guys!
You should add letter-spacing: 1.5px; in your header a class not on hover thats why its moving when you hover a li.
If you really want to show a little movement on hover you can try below method.
.container {
width: 85%;
margin: auto;
overflow: hidden;
}
header {
background-color: #262626;
color: white;
padding-top: 20px;
min-height: 70px;
}
header a {
color: white;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
transition: color 0.3s;
display: block;
padding: 8px 16px;
letter-spacing: 1.5px;
position: relative;
}
header a:hover {
padding: 8px 16px;
border-color: #2a2a2a;
color: #D52B1E;
letter-spacing: 1.5px;
border: none;
cursor: pointer;
outline: none;
display: block;
right: 2px;
}
header li {
display: inline;
padding: 0 20px 0 20px;
display: inline-flex;
}
header #logo {
float: left;
}
header #logo h1 {
margin: 0;
font-family: 'Dancing Script', cursive;
}
header nav {
float: right;
margin-top: 10px;
}
<header>
<div class="container">
<div id="logo">
<h1>Coupon<span style="color:#D52B1E">System</span></h1>
</div>
<nav>
<ul>
<li><a routerLink="/home">Home</a></li>
<li><a routerLink="/about">About</a></li>
<li><a routerLink="/contact">Contact</a></li>
</ul>
</nav>
</div>
</header>
I found a solution:
letter-spacing: 1.5px;
I forgot this line in the a tag
You're adding letting spacing to the header a:hover. This means whenever you hover over the link, letter spacing will be added.
I'm trying to make the links in the navigation bar go in the centre, if someone can tell me how to do this is, i'd be grateful. I have included the HTML and CSS code below.
<div class="menu">
<ul>
<li>Home</li>
<li>Home two</li>
<li>About</li>
<li>Basket</li>
<div class="clear"></div>
</ul>
<div class="clear"></div>
</div>
.menu {
width: 100%;
background: url('img/menu-bg.png') repeat-x;
-webkit-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
height: auto;
display: block;
margin-top: 10px;
font-family: BentonSansBook, sans-serif;
position: relative;
padding: 10px;
display: block;
z-index: 10;
font-family: BentonSansBook, sans-serif;
-webkit-font-feature-settings: "liga" 0;
font-feature-settings: "liga" 0;
font-size: 12px;
line-height: 16px;
letter-spacing: .2em;
text-transform: uppercase;
font-weight: normal;
text-decoration: none;
cursor: pointer;
color: #000;
}
}
.menu ul {
list-style: none;
margin: 0;
}
.menu ul li {
list-style: none;
float: left;
display: block;
}
.menu ul li a {
color: #000;
display: block;
text-decoration: none;
font-weight: 700;
padding: 10px 15px;
text-transform: uppercase;
}
.menu ul li a:hover {
color: #fff;
background: #5d4442;
}
I think more useful CSS is:
.menu {
position: relative;
width: 100%;
margin-top: 10px;
padding: 10px;
background: url('img/menu-bg.png') repeat-x;
border-radius: 5px;
z-index: 10;
font: 400 12px/16px BentonSansBook, sans-serif;
-webkit-font-feature-settings: "liga" 0;
font-feature-settings: "liga" 0;
letter-spacing: .2em;
cursor: pointer;
}
.menu ul {
margin: 0;
display: flex;
flex-wrap: nowrap;
justify-content: center;
list-style: none;
}
.menu ul li a {
padding: 10px 15px;
font-weight: 700;
text-decoration: none;
text-transform: uppercase;
color: #000;
}
.menu ul li a:hover {
background: #5d4442;
color: #fff;
}
And delete CLEARFIX in html.
I'm relatively new to coding. I'm playing around with a page where I have the nav bar at the very top of the page. Directly underneath I'm wanting an image with the page logo and description on top of the image.
The problem I'm having is there is a blank space between the nav bar and the image.
If I delete the words from the header (the logo, description) the image becomes flush with the nav bar like I intend it to be. But if put the words back into the header the space separates my two elements again. I'm not sure why this is consider the words are with the larger container of the header.
Can anyone help me delete this space between the elements.
By the way, this is my first time posting a question, so I'm not sure if I'm doing this correctly. Below are my html and css codes. Thanks in advance.
HTML:
<body>
<div class='top-bar'>
<nav>
<ul>
<li><a href='#'>Home</a></li>
<li><a href='#'>Destinations</a></li>
<li><a href='#'>Languages</a></li>
<li><a href='project1-about.html'>About Us</a></li>
</ul>
</nav>
</div>
<header>
<h1><span>Project 1</span></h1>
<p class='kicker'>Traveling // Exploring // Coding</p>
</header>
CSS:
header {
height: 450px;
background: url('http://gratisography.com/pictures/17_1.jpg') center center;
background-size: cover;
margin: 0; }
header p {
font-family: Cinzel; }
.top-bar {
width: 100%;
height: 50px;
background-color: red;
margin: 0; }
nav {
float: right;
margin: 0px 30px 0 0;
height: 50px; }
nav li {
display: inline-block;
margin-left: 20px;
font-size: 16px;
font-weight: 700;
text-transform: uppercase; }
nav a {
text-decoration: none;
color: white;
font-family: Cinzel; }
nav a:hover {
color: grey; }
h1 {
text-align: center;
font-size: 72px;
font-family: Cinzel;
weight: 700;
color: white;
text-transform: uppercase;
letter-spacing: .05em;
clear: both;
padding-top: 100px; }
.kicker {
text-align: center;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5em;
color: white;
line-height: 1;
position: relative; }
span {
display: inline-block;
padding: 0.2em 0.5em;
border: white solid 10px; }
This is happening because you have not done the CSS reset. Your H1 tags and other elements still have the browser default CSS properties like margin and paddings which is causing this behaviour.
Fix:
header h1 {
margin: 0;
}
See my jsfiddle.
Please try this:
i have added margin-top: 0 to h1 .
h1 {
text-align: center;
font-size: 72px;
font-family: Cinzel;
weight: 700;
color: white;
text-transform: uppercase;
letter-spacing: .05em;
clear: both;
padding-top: 100px;
margin-top: 0
}
Add margin:0 in your h1 tag.In Markup, h1 tag take its default margin , so when you reset your css then it should be worked.Take a look in JSFIDDLE.
header {
height: 450px;
background: url('http://gratisography.com/pictures/17_1.jpg') center center;
background-size: cover;
margin: 0;
}
header p {
font-family: Cinzel;
}
.top-bar {
width: 100%;
height: 50px;
background-color: red;
margin: 0;
}
nav {
float: right;
margin: 0px 30px 0 0;
height: 50px;
}
nav li {
display: inline-block;
margin-left: 20px;
font-size: 16px;
font-weight: 700;
text-transform: uppercase;
}
nav a {
text-decoration: none;
color: white;
font-family: Cinzel;
}
nav a:hover {
color: grey;
}
h1 {
text-align: center;
font-size: 72px;
font-family: Cinzel;
weight: 700;
color: white;
text-transform: uppercase;
letter-spacing: .05em;
clear: both;
padding-top: 100px;
margin: 0
}
.kicker {
text-align: center;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5em;
color: white;
line-height: 1;
position: relative;
}
span {
display: inline-block;
padding: 0.2em 0.5em;
border: white solid 10px;
}
<div class='top-bar'>
<nav>
<ul>
<li><a href='#'>Home</a>
</li>
<li><a href='#'>Destinations</a>
</li>
<li><a href='#'>Languages</a>
</li>
<li><a href='project1-about.html'>About Us</a>
</li>
</ul>
</nav>
</div>
<header>
<h1><span>Project 1</span></h1>
<p class='kicker'>Traveling // Exploring // Coding</p>
</header>
For some reason, my drop down menu is being pushed to the right. It's supposed to open up directly below the link someone is hovering over, but it opens about 30px to the right and I can't figure out why. You can see the issue in action when you scroll over "Work" on my website: http://www.noellesnotes.com
My code:
CSS
ul.site-navigation {
text-align: center;
list-style: none;
}
ul.site-navigation li a{
padding: 50px 0 47px 0;
font-family: 'Arvo', serif, Georgia;
width: 125px;
float: left;
letter-spacing: 4px;
text-transform: uppercase;
-o-transition:.5s;
-ms-transition:.5s;
-moz-transition:.5s;
-webkit-transition:.5s;
transition:.5s;
color: rgb(82,82,82);
border-bottom: 3px solid transparent;
}
ul.site-navigation > li {
position: relative;
width: 125px;
float:left;
margin: 0;
}
ul.site-navigation a:hover{
font-weight: bold;
border-bottom: 3px solid rgb(4,141,195);
text-shadow: rgb(200, 200, 200) 1px 1px 0px;
padding: 97px 0 0 0;
}
ul.site-navigation ul {
list-style: none;
height: 50px;
left: 0;
z-index: 1000;
padding: 0;
display: none;
}
ul.site-navigation ul li {
float: none;
}
ul.site-navigation li:hover ul {
display: block;
position: absolute;
top: 100%;
left: 0;
}
ul.site-navigation ul li a {
font-weight: regular;
font-size: 16px;
text-shadow: none;
padding: 5px 10px;
width: auto;
height: auto;
text-transform: uppercase;
border: 2px solid #FFF;
color: #FFF;
margin: 5px 10px 0 0;
}
ul.site-navigation ul li a:hover {
font-weight: regular;
font-size: 16px;
text-shadow: none;
padding: 5px 10px;
width: auto;
height: auto;
text-transform: uppercase;
border: 2px solid #FFF;
color: #FFF;
}
.site-title a {
color: rgb(185,40,141);
font-family: 'Arvo', serif;
text-transform: uppercase;
font-size: 63px;
background-color: rgba(255,255,255,1);
text-align: center;
text-shadow: #FFF 1px 1px,#ccc 2px 2px;
width: 500px;
float: left;
padding-top: 13px;
font-weight: normal;
letter-spacing: normal;
}
.site-branding {
display: table;
width: 100%;
height: 400px;
font-family: 'Lato', verdana, san-serif;
font-size: 6em;
text-shadow:1px -1px rgba(242,141,89,0.2);
text-align: center;
text-transform: uppercase;
color: rgb(255,255,255);
background-image: url('http://www.noellesnotes.com/wp-content/themes/portfolio/images/lights.jpg');
background-attachment:fixed;
}
HTML:
<ul class="site-navigation">
<li>About</li>
<li>Work
<ul class="submenu">
<li>Seventeen.com</li>
<li>One Direction Connection</li>
</ul>
</li>
</ul>
You have a left margin on all uls that are direct children of lis. (li > ul {margin-left:1.5em})
Add Something like this to your css to override that for your menu:
ul.site-navigation > li > ul {
margin-left:-2.75em
}
I think its natural because li tag has ul tag
You can use margin-left:-2px to fix this
My website is on the local server right now however this will be a simple fix for those of you who know whats it's called.
I'm trying to get these lists (bordered in white) to float the the far left in the available space of the footer(bordered by black).
This is my CSS
#footer { width: 100%; height: 503px; background: url(img/FOOTER-bg.jpg) repeat-x; background-color: #821d20; position: relative; top: 100px;/*border: 1px solid #0C0;*/}
#footer a { text-decoration: underline; color: #c7bd89; }
#footer a:hover { text-decoration: none; color: #fff; }
#footer h6 { background: url(img/FOOTER-HR-BG.jpg) left center repeat-x; text-align: left;}
#footer h6 span { background: #8e2023; display: inline-block; padding-right: 5px; }
.footer-widgets { width: 960px; height: 503px; margin: 0px auto; padding: 0px; border: 1px solid #000;}
.footer-widgets li { width:280px; height: auto; list-style-image: none; list-style-position: outside; list-style-type: none; float: left; color: #fff; padding: 13px; margin-right: 10px; /*border: 1px solid #fff;*/ }
.footer-widgets li ul {color: red;}
.footer-widgets li ul li {color: #fff; margin-left: -50px; margin-top: -15px;}
.footer-widgets li p { font-size: 1em; line-height: 18px; text-align: left; /*border: 1px solid red;*/ }
.footer-widgets li h2 { font-size: 1.4em; font-weight: normal; letter-spacing: 1px; line-height: 30px; text-align: left;}
.footer-archives { position: relative; top: -210px;}
.footer-widgets li.last { position: relative; top: -210px;}
h6 { font-family:Verdana, Geneva, sans-serif; font-size: 1.2em; font-weight: normal; letter-spacing: 1px; margin-top: 15px; margin-bottom: 10px; color: #fff;}
.footer-copyright { position: absolute; width: 900px; left: 50%; margin-left: -450px; top: 400px; height: 100px; font-family: Tahoma, Geneva, sans-serif; line-height: 22px; font-size: 1em; color: #fff; text-align: center; text-transform: uppercase; }
.footer-copyright a { color: #fff !important; text-decoration: none !important; }
.footer-copyright a:hover { color: #c7bd89; text-decoration: underline !important; }
.copyright { margin-top: 27px; text-transform: uppercase; display: block; color: #cc9798;}
.copyright a { color: #cc9798 !important; text-decoration: underline; }
.footer-one, .footer-two, .footer-three, .footer-four { border: 1px solid #fff; float: left;}
I have the containing footer and within the 900px x 503px container I wish that all lists float left (and under each other if it's small enough). So "Archives" would flow under "Follow Us" and if I were to put a search bar under "Testimonials" it would fit.
What can I do with my CSS to have this happen?
Why no just create a column for each side (left, center, right) and simulate it that way, well atleast I think this is what you are trying to achieve
Fiddle http://jsfiddle.net/eEwdk/
Theres another workaround that would consist in making each li element absolute positioned and calculating it's position (yeah I know it's sound redundant)
As I understand it, you want each of the li elements underneath one another. To do that you want to float the ul element to the left, not each individual li element.