navigation bar arrow not showing under each tab CSS - html

I want to use css to get an arrow that points down from each tab of the navigation bar. This is what I have so far.
ul {
background: rgba(0,0,0,0.3);
list-style-type: none;
padding: 0;
overflow: hidden;
margin: 0;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 16px;
text-decoration: none;
-webkit-transition:color 0.5s ease-in;
}
li a:visited {
color: white;
}
li a:hover {
color: #df9fa2;
}
#menu a:hover:after {
content: "";
position: absolute;
top: 52px;
width: 0px;
left: 50%;
margin-left: -15px;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 15px solid rgba(0,0,0,0.3);
}
<div id="nav">
<ul id="menu">
<li><a class="link" href="#home">Home</a></li>
<li><a class="link" href="#about">About</a></li>
<li><a class="link" href="#skills">Skills</a></li>
<li><a class="link" href="#portfolio">Portfolio</a></li>
<li style="float:right"><a class="link" href="#contact">Contact</a></li>
</ul>
</div>
The arrow is always showing up in the middle of the navigation bar. This is because of the left: 50% code. I think it's doing this because it's getting 50% from the wrong element but I don't know how to fix it. Any help would be great.

Positioning can sometimes be a little tricky. You need to position the parent (<a>: position: relative;), so that the positioning of the arrow is calculated relative to the link.
To set the arrows down under the bar, you have to use bottom minus the height of the arrow: bottom: -15px;. I had to remove your overflow:hidden; and put an element with clear:both; after the <li> tags, to make them visible, because your <ul>s height was zero with only containing floating elements.
ul {
background: rgba(0, 0, 0, 0.3);
list-style-type: none;
padding: 0;
margin: 0;
}
li {
display: block;
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 16px;
text-decoration: none;
-webkit-transition: color 0.5s ease-in;
position: relative;
}
li a:visited {
color: white;
}
li a:hover {
color: #df9fa2;
}
#menu a:hover:after {
content: "";
position: absolute;
bottom: -15px;
width: 0px;
left: 50%;
margin-left: -15px;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 15px solid rgba(0, 0, 0, 0.3);
}
<div id="nav">
<ul id="menu">
<li><a class="link" href="#home">Home</a>
</li>
<li><a class="link" href="#about">About</a>
</li>
<li><a class="link" href="#skills">Skills</a>
</li>
<li><a class="link" href="#portfolio">Portfolio</a>
</li>
<li style="float:right;"><a class="link" href="#contact">Contact</a>
</li>
<br style="clear:both;" />
</ul>
</div>
Just read some examples about positioning in CSS:
http://www.w3schools.com/css/css_positioning.asp

Related

My drop down menu won't stay open on hover

I am facing a problem whereby my drop down menu will not stay open when I hover my cursor over it. It sometimes stay open for a while and disappears. I have been trying to find solutions but I can't really tell what is the problem. Can anyone help me? I am new to CSS and HTML...
.arrow {
background-image: url(arrow.png);
background-repeat: no-repeat;
background-position: 100px;
}
.menu-area ul {
text-transform: uppercase;
list-style: none;
width: 145px;
margin-left: 10px;
padding: 0px;
position: absolute;
display: block;
box-shadow: 10px 10px 5px rgba(96, 96, 96, 0.8);
}
.menu-area ul ul {
margin-left: 1px;
position: absolute;
display: none;
left: 100%;
top: 0px;
}
.menu-area ul li {
border-bottom: 1px solid white;
background: MediumVioletRed;
position: relative;
display: block;
margin-bottom: 0px;
}
.menu-area ul li a {
font-family: verdana;
font-size: 12px;
font-weight: bold;
text-align: left;
color: white;
text-decoration: none;
padding: 10px 20px;
display: block;
}
.menu-area ul li:hover {
background-color: hotpink;
}
.menu-area ul li:hover>ul {
display: block;
}
<div class="menu-area">
<ul>
<li>Home</li>
<li><a class="arrow" href="#">Soalan</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
<li><a class="arrow" href="#">Topic</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
Youre adding margin-left: 1px; on .menu-area ul ul which makes a 1px gap between the main ul and your submenu ul. If you hit that gap (which is pretty hard as its only 1px but still possible) the submenu closes.
Remove the margin so the ul's "touch" each other without gap for a safe transition between menu and submenu (You can add the same spacing as padding so you keep the 1px gap). Apart from this 1px gap everything runs smoothly.
In general i would recommend adding https://github.com/kamens/jQuery-menu-aim tho so the menu doesnt close when trying to reach for the last submenu item (where you most likely move out of the main-ul which makes the menu close instantly).
The hover style is not applied because of that 1px gap to the child elements. You could remove that margin and set a transparent border on the child ul
.arrow {
background-image: url(arrow.png);
background-repeat: no-repeat;
background-position: 100px;
}
.menu-area ul {
text-transform: uppercase;
list-style: none;
width: 145px;
margin-left: 10px;
padding: 0px;
position: absolute;
display: block;
box-shadow: 10px 10px 5px rgba(96, 96, 96, 0.8);
}
.menu-area ul ul {
margin-left: 0;
border-left: 1px solid transparent;
position: absolute;
display: none;
left: 100%;
top: 0px;
}
.menu-area ul li {
border-bottom: 1px solid white;
background: MediumVioletRed;
position: relative;
display: block;
margin-bottom: 0px;
}
.menu-area ul li a {
font-family: verdana;
font-size: 12px;
font-weight: bold;
text-align: left;
color: white;
text-decoration: none;
padding: 10px 20px;
display: block;
}
.menu-area ul li:hover {
background-color: hotpink;
}
.menu-area ul li:hover>ul,
.menu-area ul li>ul:hover {
display: block;
}
<div class="menu-area">
<ul>
<li>Home</li>
<li><a class="arrow" href="#">Soalan</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
<li><a class="arrow" href="#">Topic</a>
<ul>
<li>Add</li>
<li>Update</li>
<li>Delete</li>
<li>List</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

Why won't CSS hover effect cover only my dropdown menu?

In the first photo, my cursor is hovering over the slogan in the top right corner. If someone could tell me the adjustments I need to make so that my dropdown menu only comes down when I hover over it, it would be much appreciated.
HTML:
<ul class="dropdown">
<li>Menu</li>
<ul class="dropdownElements">
<li><a href="About.html"/>About</li>
<li><a href="Vintage.html"/>Vintage Products</li>
<li><a href="Antique.html"/>Antique Products</li>
<li><a href="Collectibles.html"/>Collectibles</li>
<li><a href="Contact.html"/>Contact Information</li>
</ul>
</ul>
CSS:
* {
margin: 0px;
padding: 0px;
}
div.header ul.dropdown {
position: absolute;
margin: auto;
list-style: none;
margin-left: 190px;
position: relative;
top: 40px;
}
div.header ul.dropdown li {
background-color: white;
height: 45px;
width: 135px;
line-height: 45px;
border-radius: 5px;
box-shadow: 1px 3px 5px black;
text-align: center
}
ul.dropdownElements li {
list-style: none;
}
div.header ul.dropdown li:hover {
background-color: #C5A06D;
transition: background linear 0.2s;
}
div.header ul ul {
visibility:hidden;
}
div.header ul:hover ul {
visibility:visible;
}
a:link {
text-decoration: none;
color: black;
}
See below. I have removed div.header at a few places because that element isn't in the HTML and stops the CSS from working.
Essential changes: list items of the top level menu positioned relative, submenu positioned absolute.
* {
margin: 0px;
padding: 0px;
}
ul.dropdown {
position: relative;
margin: auto;
list-style: none;
margin-left: 190px;
position: relative;
top: 40px;
}
div.header ul.dropdown li {
background-color: white;
height: 45px;
width: 135px;
line-height: 45px;
border-radius: 5px;
box-shadow: 1px 3px 5px black;
text-align: center
}
ul.dropdownElements {
display: none;
position: absolute;
top: 1em;
left: 0;
}
ul.dropdownElements li {
list-style: none;
}
div.header ul.dropdown li:hover {
background-color: #C5A06D;
transition: background linear 0.2s;
}
ul.dropdown li:hover ul.dropdownElements {
display: inline-block;
}
a:link {
text-decoration: none;
color: black;
}
<ul class="dropdown">
<li>Menu
<ul class="dropdownElements">
<li><a href="About.html" />About</li>
<li><a href="Vintage.html" />Vintage Products</li>
<li><a href="Antique.html" />Antique Products</li>
<li><a href="Collectibles.html" />Collectibles</li>
<li><a href="Contact.html" />Contact Information</li>
</ul>
</li>
</ul>

Anchor tags seemingly linked to ids properly but not working

I haven't been able to figure out why this is happening, i have my navigation bar working fine and the anchor links themselves are actual links, but when i click them the page either reloads or goes completely white screen.
Here's a link to the page, only included the ul itself and the attached css
http://s.codepen.io/boomerang/7e523d9a7efa11d1199da37a32c176ac1483413552850/index.html
.menu {
position: fixed;
z-index: 999;
left: 50%;
transform: translate(-50%, 0);
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #3f2e38;
border-radius: 0px 0px 30px 30px;
box-shadow: 0px 2px 4px #3f2e38;
}
ul.menu li a {
width: 100px;
height: 40px;
font-family: dosis;
display: inline-block;
color: #e6e1ea;
text-align: center;
transition: .3s;
font-size: 20px;
}
ul.menu li {
float: left;
}
ul.menu li a:hover {
background-color: #59404f;
}
/*header text*/
.texttwo {
font-family: dosis;
font-size: 72px;
}
<header>
<nav>
<ul class="menu">
<li><a href "#home">Home</a>
</li>
<li><a href "#gallery">Gallery</a>
</li>
<li><a href "#portfolio">Portfolio</a>
</li>
<li><a href "#contact">Contact</a>
</li>
</ul>
</nav>
</header>
<div>
<h1 class="texttwo" id="gallery">Gallery</h1>
</div>
<div>
<h1 class="texttwo" id="portfolio">Portfolio</h1>
</div>
<div>
<h1 class="texttwo" id="contact">Contact</h1>
</div>
You are missing = sign
.menu {
position: fixed;
z-index: 999;
left: 50%;
transform: translate(-50%, 0);
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #3f2e38;
border-radius: 0px 0px 30px 30px;
box-shadow: 0px 2px 4px #3f2e38;
}
ul.menu li a {
width: 100px;
height: 40px;
font-family: dosis;
display: inline-block;
color: #e6e1ea;
text-align: center;
transition: .3s;
font-size: 20px;
}
ul.menu li {
float: left;
}
ul.menu li a:hover {
background-color: #59404f;
}
/*header text*/
.texttwo {
font-family: dosis;
font-size: 72px;
}
<header>
<nav>
<ul class="menu">
<li>Home
</li>
<li>Gallery
</li>
<li>Portfolio
</li>
<li>Contact
</li>
</ul>
</nav>
</header>
<div>
<h1 class="texttwo" id="gallery">Gallery</h1>
</div>
<div>
<h1 class="texttwo" id="portfolio">Portfolio</h1>
</div>
<div>
<h1 class="texttwo" id="contact">Contact</h1>
</div>

Text next to the menu moving the menu when more text is added

i want to make my text on the left side of the menu not interact with my menu. Every time I add text to it, it moves my menu bars to the side. Any idea how to fix it? I tried fixed position for the text but its buggy and doesn't work in Mozilla Firefox.
JsFiddle: https://jsfiddle.net/3vetp3y3/
HTML:
<nav>
<span class="nadpis"> BUR </span>
<ul class="nav">
<li class="prve">PSI
<ul>
<li>Simoncik</li>
<li>Kodrla</li>
<li>Vajs</li>
<li>Hrebicek</li>
</ul>
</li>
<li class="druhe">&#9776
<ul>
<li> RPO </li>
<li> FLV
<ul>
<li>Simoncik</li>
<li>Kodrla</li>
<li>Vajs</li>
<li>Hrebicek</li>
</ul>
</li>
<li> FLC
<ul>
<li>Bednarikova</li>
<li>Dobrikova</li>
<li>Duracka</li>
</ul>
</li>
<li> QUA
<ul>
<li>Klco</li>
<li>Cisar</li>
</ul>
</li>
<li> HFX
</li>
<li> PDT
</li>
<li> RSH
</li>
<li> BUR
</li>
<li> SUHRN </li>
<li> INCI </li>
<li> JIRA </li>
<li> CHGT </li>
<li> TASK </li>
<li> VRS </li>
</div>
</ul>
</li>
</ul>
</nav>
CSS:
body,
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav {
display: inline-block;
position: fixed;
width: 100%;
text-align: center;
background-color: #111;
vertical-align: top;
top: -1px;
opacity: 1;
transition: 0.3s;
}
nav:hover {
opacity: 1!important;
background-color: #111;
transition: 0.3s;
}
span {
float: left;
margin-left: 3px;
}
span a {
text-decoration: none;
color: #2670CF;
background-color: #111;
font-family: 'Helvetica Neue', sans-serif;
font-size: 30px;
font-weight: bold;
}
.nav a {
display: block;
background: #111;
color: #fff;
text-decoration: none;
padding: 0.7em 1.7em;
text-transform: uppercase;
font-size: 85%;
letter-spacing: 3px;
position: relative;
}
.nav {
vertical-align: top;
display: inline-block;
width: 250px;
}
.nav li {
position: relative;
}
.nav > li {
display: inline-block;
}
.nav li:hover > a {
transition: 0.3s;
background-color: #3a3939;
color: #40d23b;
}
.nav ul {
position: absolute;
white-space: nowrap;
z-index: 1;
left: -99999em;
background-color: #000;
border: 2px solid #81D4FA;
border-top: none;
}
.nav > li:hover > ul {
left: auto;
min-width: 100%;
}
.nav > li li:hover > ul {
left: 100%;
top: -1px;
}
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
right: 10px;
}
.prve {
max-width: 125px;
min-width: 90px;
border: 2px solid #81D4FA;
border-bottom: none;
border-top: none;
}
.druhe {
max-width: 14px;
min-width: 110px;
border-right: 2px solid #81D4FA;
}
use position: absolute instead of float
span.nadpis {
position: absolute;
left: 0;
}
with float, the element will still own an amount of space which will affect its sibling elements
with position: absolute, the element would position itself separately from its sibling elements

Arrow under navigation

Hi I've looked up ways to place an arrow under my navigation but I can't get to work on my navigation bar. Any help would be much appreciated.
<nav>
<div class="hello"></div>
<ul>
<li class="icon-home"><span>Home</span></li>
<li class="arrow"> <a class="star" href="#">England</a>
<ul>
<li>Premiership
</li>
<li>Championship
</li>
<li>League 1
</li>
<li>League 2
</li>
</ul>
</li>
<li class="arrow"> France
<ul >
<li id="r">Ligue 1
</li>
</ul>
</li>
<li class="arrow"> Germany
<ul>
<li>Bundesliga
</li>
</ul>
</li>
<li class="arrow"> Italy
<ul>
<li>Serie A
</li>
</ul>
</li>
<li class="arrow"> Spain
<ul>
<li>La Liga
</li>
</ul>
</li>
</ul>
<div class="handle"> Menu </div>
</nav>
I thought that is css would work but it hasn't
li a:after {
content: '';
display: none;
width: 0;
height: 0;
border-top: 6px solid #333;
border-right: 6px solid transparent;
border-left: 6px solid transparent;
position: absolute;
z-index: 1;
top: 100%;
left: 50%;
margin-left: -6px
}
my code https://jsfiddle.net/jzqv6kr0/
In your case, the arrow is there it's just that the overflow:hidden on the ul means you can't see it.
I've adapted your code a little (see the snippet below) but it requires some tweaks to get it exactly as you might like. I've colored the arrow red for simplicity.
nav ul {
/* overflow:hidden; REMOVE */
}
nav ul li.arrow:after {
content: '';
width: 0;
height: 0;
border-top: 6px solid red;
border-right: 6px solid transparent;
border-left: 6px solid transparent;
position: absolute;
z-index: 1;
top: 100%;
left: 50%;
margin-left: -6px
}
nav ul {
background-color: #43a286;
color: white;
padding: 0;
text-align: center;
margin: 0;
-webkit-transition: max-height 0.4s;
-ms-transition: max-height 0.4s;
-moz-transition: max-height 0.4s;
-o-transition: max-height 0.4s;
transition: max-height 0.4s;
}
nav ul li {
display: inline-block;
padding: 20px;
width: 12.3%;
text-align: center;
position: relative;
}
nav ul li:hover {
background-color: #399077;
}
nav ul li.arrow:after {
content: '';
width: 0;
height: 0;
border-top: 6px solid red;
border-right: 6px solid transparent;
border-left: 6px solid transparent;
position: absolute;
z-index: 1;
top: 100%;
left: 50%;
margin-left: -6px
}
nav ul ul {
display: none;
position: absolute;
background-color: #399077;
margin-left: -3%;
z-index: 150;
}
nav ul ul li {
display: block;
width: 75%;
text-align: center;
}
nav ul li:hover ul {
margin-top: 2%;
display: block;
border-bottom-left-radius: 5%;
border-bottom-right-radius: 5%;
width: 165px;
}
nav ul li a,
visited {
color: white;
font-family: 'CFJackStory-Regular', Helvetica, Arial, sans-serif;
display: block;
text-decoration: none;
}
nav ul ul li a:hover {
color: white;
font-size: 20px;
}
<nav>
<div class="hello"></div>
<ul>
<li class="icon-home"><span>Home</span>
</li>
<li class="arrow"> <a class="star" href="#">England</a>
<ul>
<li>Premiership
</li>
<li>Championship
</li>
<li>League 1
</li>
<li>League 2
</li>
</ul>
</li>
<li class="arrow"> France
<ul>
<li id="r">Ligue 1
</li>
</ul>
</li>
<li class="arrow"> Germany
<ul>
<li>Bundesliga
</li>
</ul>
</li>
<li class="arrow"> Italy
<ul>
<li>Serie A
</li>
</ul>
</li>
</ul>
</nav>