I'm pretty new to coding so please keep that in mind.
So I'm working on a little website, and I'm trying to stylise the header and nav bar. I'm trying to do some diagonal lines to seperate the different items in it, but I can't seem to make them appear.
I'd like to do something like this, with a simple drop shadow.
So here's my HTML and CSS
<nav>
<div class="logo"></div>
<ul>
<li>Home</li>
<li>Game</li>
<li>Infos</li>
<li>Contact</li>
<li><a class="active" href="#help">Help</a></li>
</ul>
</nav>
And
nav ul{
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
list-style: none;
}
nav ul li a {
line-height: 80px;
color: #151515;
padding: 12px 30px;
text-decoration: none;
text-transform: uppercase;
transition: .3s;
}
nav ul li a:hover{
color: #F16918;
text-shadow: 2px;
}
To be clear, everything in the image is already done and coded, except for the diagonal lines that I painted over in Photoshop.
My header switch to black when scrolling (white on top over the image), so that's why the text never says its black, but it is in the image.
So I was wondering if anyone could help me get those diagonal lines?
Thanks a lot!
Try this (using pseudo element)..adjust at your needs.
CSS
nav ul{
list-style: none;
float: right;
margin: 0;
padding: 0;
display: flex;
}
nav ul li {
list-style: none;
position: relative;
}
nav ul li:after {
position: absolute;
content:"";
width: 1px;
height:100%;
background: #000;
transform: rotate(-45deg);
top:0;
left:0;
}
nav ul li a {
line-height: 80px;
color: #151515;
padding: 12px 30px;
text-decoration: none;
text-transform: uppercase;
transition: .3s;
}
nav ul li a:hover{
color: #F16918;
text-shadow: 2px;
}
CSS WITH SHADOW
nav ul li:after {
position: absolute;
content:"";
width: 1px;
height:100%;
background: transparent;
transform: rotate(-45deg);
top:0;
left:0;
box-shadow: -4px 0 1px rgba(0,0,0,0.2);
}
HTML
<nav>
<div class="logo"></div>
<ul>
<li>Home</li>
<li>Game</li>
<li>Infos</li>
<li>Contact</li>
<li><a class="active" href="#help">Help</a></li>
</ul>
</nav>
DEMO HERE
Related
I have a simple navbar and i have few menu items via ul and what I'm trying to do is that whenever i hover over the li a border-bottom appears in center of the text but im having a few problems first is that the border-bottom's width is leaving the text and sometimes it doesn't it cover the full width of the text above it
body{
margin: 0px;
padding: 0px;
background: #2c3e50;
}
.header__middle ul{
list-style-type: none;
display: flex;
}
.header__middle ul li a{
margin-right: 10px;
text-decoration: none;
font-size: 1.2em;
color: black;
text-align: center;
}
.header__middle ul li {
position: relative;
}
.header__middle ul li:hover ::after{
content: "";
position: absolute;
left: 4%;
bottom: -13%;
width: 40px;
border-bottom: 2px solid black;
}
<div class="header__middle">
<ul>
<li >Home</li>
<li>Join</li>
<li>FAQs</li>
<li>About Us</li>
</ul>
</div>
HTML
Here, try this. The only issue I see is that your 40px border is too wide for some items like "Join". (Notes are in the code)
body {
margin: 0px;
padding: 0px;
background: #2c3e50;
}
.header__middle ul{
list-style-type: none;
display: flex;
}
/* Remove your margin here and re-add it as a padding on the parent li */
.header__middle ul li a{
text-decoration: none;
font-size: 1.2em;
color: black;
text-align: center;
}
.header__middle ul li {
position: relative;
padding-right: 10px;
}
/* Change to display block and position relative */
.header__middle ul li:hover ::after{
content: "";
display: block;
position: relative;
left: calc(50% - 20px); /* To center, set your left for 50% minus half of your bar's width */
width: 40px;
border-bottom: 2px solid black;
}
<div class="header__middle">
<ul>
<li >Home</li>
<li>Join</li>
<li>FAQs</li>
<li>About Us</li>
</ul>
</div>
Edit: Sorry, I may have misunderstood. I thought you were wanting your 40px bar to be centered on each object.
If you want your bar to be the same width as each item, just remove the left and width properties from my code above, as shown here:
.header__middle ul li:hover ::after{
content: "";
display: block;
position: relative;
border-bottom: 2px solid black;
}
I have a menu and submenu from one of the elements. The code is here: http://jsfiddle.net/mq5g6upe/ . I would like you to tell me how to implement vertical dropdown menu from element My project because now it not seem ok.
header.html
<header>
<div class="main">
<ul>
<li>Home</li>
<li>My projects
<ul class="my-projects-dropdown">
<li>Endless Blow
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li>My Google Play link</li>
<li>About</li>
<li><input type="submit" class="a-login" value="Login" (click)="navigateToLogin()"></li>
</ul>
</div>
</header>
header.css
#container {
margin: 0 auto;
}
ul {
float: right;
list-style-type: none;
margin-top: 25px;
margin-right: 115px;
}
ul li {
display: inline-block;
vertical-align: middle;
}
ul li a {
text-decoration: none !important;
padding: 5px 20px;
border: 1px solid #000;
color: #000;
transition: 0.4s ease;
font-size: 20px !important;
}
ul li a:hover {
background-color: cyan;
}
ul li a.li-login {
text-decoration: none !important;
position: relative;
margin-left: 10px;
padding: 5px 10px;
color: #000;
transition: 0.4s ease;
font-size: 16px !important;
border: none;
vertical-align: middle;
line-height: normal;
}
ul li:hover > ul {
visibility: visible;
opacity: 1;
display: block;
}
ul li:nth-child(5){
margin-left: 20px;
vertical-align: middle;
line-height: normal;
}
ul ul {
display: none;
position: absolute;
}
ul ul li {
float:none;
display:list-item;
position: relative;
}
Now there are three problems. First the submenu of items seems to overlap on another elements. Second there is a distance between the menu element My projects and first element of submen. Third outside jsfiddle in production (https://jakuwegiel.web.app/home) also submenu is moved a bit to right.
I forked your fiddle. check this https://jsfiddle.net/wrtxkz0d .
Made these changes in your css. Dropdown is working.
ul li:hover > ul {
visibility: visible;
opacity: 1;
display: block;
margin:0;
padding: 0;
}
ul ul li {
float:none;
display:list-item;
position: relative;
margin: 13px 0;
}
I have created a menu with a submenu which can be seen here: JSFIDDLE.
I created a triangle on top of my submenu but due to the fact that the submenu is shown when the menu item is hovered, undesired behaviour is shown.
If you want to click on one of the submenu's the submenu will be set to: display:none due to the fact that there is no hover detection anymore.
I think it is a quite simple fix and perhaps there is already a related question on this topic. but i would really appreciate any help.
*{
margin:0;
padding:0;
}
.menu nav{
text-align:center;
}
.menu nav ul{
list-style-type:none;
}
.menu nav ul li{
display:inline-block;
padding:80px 15px 0px 15px;
font-family: Titillium Web;
font-weight:700;
font-size:16px;
color:#00adef;
text-transform: uppercase;
}
.menu nav ul li a{
color:#00adef;
}
.menu nav ul li:hover{
border-bottom:4px solid #00adef;
}
.menu nav ul li .submenu{
display:none;
position: absolute;
background-color:#1A98C8;
margin-top:15px;
z-index:10;
opacity:0.9;
left:38%;
}
.menu nav ul li .submenu:before{
content: '';
position: absolute;
left: 75px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #1A98C8;
}
.menu nav ul li .submenu li{
color:#fff;
display:block;
padding-top:0px;
padding-left:0px;
height:40px;
border-bottom:1px solid #fff;
opacity:1;
line-height:40px;
width:150px;
}
.menu nav ul li:hover .submenu{
display:block;
}
<div class="menu">
<nav>
<ul class="default-menu">
<li>Home</li>
<li>about</li>
<li>
submenu <i class="fa fa-angle-right" aria-hidden="true"></i>
<ul class="submenu">
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
</li>
<li>Testimonials</li>
<li>Contact</li>
</ul>
</nav>
</div>
What you need to do here is basically add a delay for your .submenu to open so that when you navigate from your li to the .submenu, the .submenu is still open.
You can add that delay using the transition property as in:
.menu nav ul li .submenu {
transition: all .1s;
}
Since you would be using transition, you can't use the display property since it does not reflect a state change. Use a combination of visibility and opacity to achieve the hide and show behaviour of display.
Refer code:
* {
margin: 0;
padding: 0;
}
.menu nav {
text-align: center;
}
.menu nav ul {
list-style-type: none;
}
.menu nav ul li {
display: inline-block;
padding: 80px 15px 0px 15px;
font-family: Titillium Web;
font-weight: 700;
font-size: 16px;
color: #00adef;
text-transform: uppercase;
}
.menu nav ul li a {
color: #00adef;
}
.menu nav ul li:hover {
border-bottom: 4px solid #00adef;
}
.menu nav ul li .submenu {
visibility: hidden;
opacity: 0;
position: absolute;
background-color: #1A98C8;
margin-top: 15px;
z-index: 10;
opacity: 0.9;
left: 38%;
transition: all .1s;
}
.menu nav ul li .submenu:before {
content: '';
position: absolute;
left: 75px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #1A98C8;
}
.menu nav ul li .submenu li {
color: #fff;
display: block;
padding-top: 0px;
padding-left: 0px;
height: 40px;
border-bottom: 1px solid #fff;
opacity: 1;
line-height: 40px;
width: 150px;
}
.menu nav ul li:hover .submenu {
visibility: visible;
opacity: 1;
}
<div class="menu">
<nav>
<ul class="default-menu">
<li>Home</li>
<li>about</li>
<li>
submenu <i class="fa fa-angle-right" aria-hidden="true"></i>
<ul class="submenu">
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
</li>
<li>Testimonials</li>
<li>Contact</li>
</ul>
</nav>
</div>
Instead of using
display: none;
Try using
visibility:hidden
display:none means that the tag in question will not appear on the page at all (although you can still interact with it through the dom). There will be no space allocated for it between the other tags.
visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn't seen on the page.
Found this on this question on stackoverflow. I think this could solve your issue of not being able to detect the :hover event (because 'display: none' removes the element)
Whenever I move my mouse to submenu, the list disappears suddenly.
I tried using z-index also, but it's not working. Most probably there is some other element overlapping my navigation menu.
here is Code Snippet for menu part:-
.nav {
background: url(images/bgnav.jpg);
clear: both;
height: 40px;
font-size:11px;
text-shadow:0 1px 1px #fff;
line-height: 40px;
}
.nav li {
float: left;
list-style-type: none;
text-transform:uppercase;
}
.nav li a {
color: #676767;
text-decoration: none;
padding:10px 8px;
}
.nav li:hover {
color: #fff;
text-decoration: none;
background:url(images/nav-hover.png);
text-shadow:0 1px 1px #000;
}
.nav li ul {
display: none;
height: auto;
margin: 0;
padding: 0;
}
.nav li:hover ul {
display: block;
position: absolute;
transition-delay: 0s;
}
.nav li ul li {
background: url(images/bgnav.jpg);
}
.nav li ul li a:hover {
background:url(images/nav-hover.png);
}
.submenu li{
transition: 0.2s 1s;
text-shadow:0 1px 1px #fff;
}
<div class="nav">
<div class="mainbody"><!-- #BeginLibraryItem "/Library/nav.lbi" --><ul>
<li>Home </li>
<li>About us</li>
<li>Company Profile</li>
<li>Babbitt Bearing Manufacturing</li>
<li>Rebabbitt Bearing
<ul class="submenu">
<li>White Bearing</li>
</ul>
</li>
<li> Quality</li>
<li> Reverse Engineering</li>
<li> in Situ Services</li>
<li> Contact us </li>
</ul><!-- #EndLibraryItem --></div>
</div>
Can anybody tell me what should I do to solve my problem?
Thank You
Try following css it's overlapping with your absshadow block apply z-index along with position property
This will solve your issue
.nav li {
float: left;
list-style-type: none;
text-transform: uppercase;
/* padding-bottom: 10px; */
z-index: 999;
position: relative;
}
I hope this will solve your problem
I have made a few attempts at this and they ended up just getting confusing. The current HTML and CSS seems to be working fine for a simple horizontal CSS menu. I am struggling with dropping subitems off the current <li> elements.
I am trying to making them show up exactly below the current menu items with the same hovering effects as I have in place now. Any assistance would be appreciated. I am admittedly no CSS pro.
Current HTML:
<div class="MenuTop">
<ul class="Nav">
<li>Home</li>
<li>Vehicles
<ul>
<li>SubItemOne</li>
</ul>
</li>
<li>About</li>
<li>Contact</li>
<li>News</li>
</ul>
</div>
Current CSS:
.MenuTop
{
width: 960px;
background-color: Black;
color: #fff;
margin: auto auto 0px auto;
padding: 5px;
height:auto;
font-family: Segoe UI, Arial;
font-weight:bold;
min-height:15px;
}
.MenuTop ul
{
float: left;
list-style: none;
margin: -5px ;
padding: 0px;
}
.MenuTop li
{
float: left;
font-size:12px;
font-family: Segoe UI, Arial;
margin: 0;
padding: 0;
}
.MenuTop a
{
background-color: Black;
color: #fff;
display: block;
float: left;
margin: 0;
padding: 4px 12px 4px 12px;
text-decoration: none;
}
.MenuTop a:hover
{
background-color: #404040;
color: #fff;
padding: 4px 12px 4px 12px;
}
You were close, but you're forgetting about positioning your submenu items absolutely to your parent li menu item and hiding it as well, by using display:none and then showing it on hover, so try something like this to achieve that effect:
CSS
.Nav li {
position:relative;
}
.Nav li ul {
display:none;
position:absolute;
top:30px;
}
.Nav li:hover ul {
display:block;
}
Also, your submenu ul is not properly closed so go ahead and close it.
Ninja Edit: demo, by the way you can greatly benefit from properly targeting your menu by using the class you have given it, .Nav, instead of its parent class of its container, .MenuTop, that way you can target your menu and your menu alone and not any other element you might place inside that container,
I have created a working example for you on jsFiddle.
The HTML is as follows:
<nav>
<ul class="cf">
<li>Home</li>
<li>Vehicles
<ul>
<li>Sub-menu Item 1</li>
<li>Sub-menu Item 2</li>
<li>Sub-menu Item 3</li>
</ul>
</li>
<li>About</li>
<li>News</li>
</ul>
</nav>
and the CSS:
nav ul {
background: #ddd;
list-style: none;
margin: 0;
padding: 0;
width: 100%;
}
nav li {
float: left;
margin: 0;
padding: 0;
position: relative;
min-width: 25%;
}
nav a {
font-family: Lucida Grande;
background-color: #666666;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: rgba(255,255,255,0.5) 0px 3px 3px;
display: block;
font: bold 14px sans-serif;
padding: 0 25px;
text-align: center;
text-decoration: none;
}
nav li ul {
float: left;
left: 0;
opacity: 0;
position: absolute;
top: 1em;
visibility: hidden;
z-index: 1;
}
nav li:hover ul {
opacity: 1;
top: 1em;
visibility: visible;
}
nav li ul li {
float: none;
width: 100%;
}
.cf:after, .cf:before {
content:"";
display:table;
}
.cf:after {
clear:both;
}
.cf {
zoom:1;
}