I've almost got my dropdown menu working, but I can't get the dropdown content to appear underneath the head when it's clicked. It's moved off to the side. What's causing that? Is it improperly written position?
Fiddle: https://jsfiddle.net/kiddigit/8sxj3eeg/
* {
font-family: garamond;
line-height: 1.9em;
}
.dropdownwrapper {
padding-top: 2px;
}
.dropbtn {
color: black;
padding: 13px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown-content {
/* display: none;*/
position: absolute;
}
.dropdown-content a {
color: white;
padding: 0 27.5px ;
text-decoration: none;
display: block;
background-color: #3f3f3f;
}
.dropdown-content a:hover {
color: #a9a9a9;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: black;
color: white;
}
header {
border-bottom: 5px solid;
margin-bottom: 10px;
overflow: hidden;
}
header ul {
float: right;
list-style-type: none;
margin-top: 22px;
padding:0;
width: 50%;
}
header li {
float: right;
}
header li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
header li a:hover {
background-color: #111;
color: white;
}
header h1 {
float: left;
text-align: left;
line-height: 0;
font-size: 2em;
}
<header>
<h1>Father Bart Gage</h1>
<ul>
<li><a id="about" href="#">ABOUT</a></li>
<li>CONTACT</li>
<div class="dropdownwrapper">
<div class="dropdown">
<li><div class="dropbtn" onClick=”return true”>SCRIPTURE</div></li>
<div class="dropdown-content">
<a id="mark" href="#">Mark</a>
<a id="matthew" href="#">Matthew</a>
<a id="luke" href="#">Luke</a>
<a id="john" href="#">John</a>
</div>
</div>
</div>
</ul>
</header>
You have to move the dropdown-content element into the list item:
<div class="dropdown">
<li>
<div class="dropbtn" onClick=”return true”>SCRIPTURE</div>
<div class="dropdown-content">
<a id="mark" href="#">Mark</a>
<a id="matthew" href="#">Matthew</a>
<a id="luke" href="#">Luke</a>
<a id="john" href="#">John</a>
</div>
</li>
</div>
There's a couple things going on that probably need some attention.
First, a <div> element is not technically "legal" as a direct child of a ul element. The only direct child of a ul should be a li. To solve this, I've moved your dropdown divs inside the li.
Second, you may be suffering a bit of "div-itis". You probably (definitely?) don't need so many div elements to accomplish what you want. I've proposed alternate markup below your markup below.
Third, it's all about position: when you set position: absolute, the position (top, right, bottom, left) are relative to the nearest parent with position: relative. Therefore, you probably want to be sure your li elements have position: relative.
Your original markup, with the divs enclosed in the li
<header>
<h1>Father Bart Gage</h1>
<ul>
<li><a id="about" href="#">ABOUT</a></li>
<li>CONTACT</li>
<li>
<div class="dropdownwrapper">
<div class="dropdown">
<div class="dropbtn" onClick=”return true”>SCRIPTURE</div>
<div class="dropdown-content">
<a id="mark" href="#">Mark</a>
<a id="matthew" href="#">Matthew</a>
<a id="luke" href="#">Luke</a>
<a id="john" href="#">John</a>
</div>
</div>
</div>
</li>
</ul>
</header>
Alternate proposed markup
(note that this also requires altered styles - see the fiddle for those!)
<header>
<h1>Father Bart Gage</h1>
<ul>
<li><a id="about" href="#">ABOUT</a></li>
<li>CONTACT
<!-- nested ul for the dropdown, rather than divs -->
<li>
<div class="dropbtn" onClick=”return true”>SCRIPTURE</div>
<ul class="dropdown dropdown-content">
<li><a id="mark" href="#">Mark</a></li>
<li><a id="matthew" href="#">Matthew</a></li>
<li><a id="luke" href="#">Luke</a></li>
<li><a id="john" href="#">John</a></li>
</ul>
</li>
</ul>
</header>
Working Fiddle using the alternate proposed markup.
Related
Final HTML output that I have a problem with:
.navbar {
font-family: Cookie, cursive;
font-size: 40px;
text-align: center;
display: block;
}
a:link {
text-decoration: none;
}
.navbar li {
display: inline-block;
padding: 10px;
}
.navbar .cur {
color: black;
}
<nav>
<ul class="navbar">
<li><a href=index.html>Home</a></li>
<li><a href=photo.html>Photography</a></li>
<li><a href=blog.html>Blog</a></li>
<li><a href=work.html>Work With Me</a></li>
<li><a class="cur" href=about.html>About</a></li>
<li><img class="log" src="assets/link_logo.png" alt="logo" height="40px"></li>
</ul>
</nav>
Any suggestions to make the logo appear on the same baseline will be much appreciated.
I think this code can help you!
.navbar {
font-family: Cookie, cursive;
font-size: 20px;
text-align: center;
display: block;
}
a:link {
text-decoration: none;
}
.navbar li {
display: inline-block;
padding: 10px;
}
.navbar .cur {
color: black;
}
.mainDiv{
display: flex;
}
<div class='mainDiv'>
<div class='menuDiv'>
<nav>
<ul class="navbar">
<li><a href=index.html>Home</a></li>
<li><a href=photo.html>Photography</a></li>
<li><a href=blog.html>Blog</a></li>
<li><a href=work.html>Work With Me</a></li>
<li><a class="cur" href=about.html>About</a></li>
</ul>
</nav>
</div>
<div class='logoDiv'>
<span> <img src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/linkedin_circle-512.png" width="100px" height="100px"></span>
</div>
<div>
Make the .navbar a flex container with no-wrap attribute set. This way all the items will be on the same line. If you want to vertically position them in the center - set the align-items: center attr on the flex container
I am trying to follow a tutorial on YouTube to create a toolbar, but I am using Vuejs instead of regular HTML like on the video and the content of the views (.vue files) goes beside the toolbar instead of below it and another thing, I try to make center the toolbar.
<template>
<div id="app">
<div class="toolbar">
<ul>
<li>
Home
</li>
<li>
About
<ul>
<li>
<a href>Our Team</a>
</li>
<li>
<a href>Camp Sites</a>
</li>
<li>
<a href>Mission & Vision</a>
</li>
<li>
<a href>Resources</a>
</li>
</ul>
</li>
<li>
Things to do
<ul>
<li>
<a href>Activities</a>
</li>
<li>
<a href>Parks</a>
</li>
<li>
<a href>Shops</a>
</li>
<li>
<a href>Events</a>
</li>
</ul>
</li>
<li>
Contact
<ul>
<li>
<a href>Map</a>
</li>
<li>
<a href>Directions</a>
</li>
</ul>
</li>
<li>
News
</li>
</ul>
</div>
<div>
<router-view/>
</div>
</div>
</template>
#app {
margin: 0;
padding: 0;
}
body {
background-color: black;
background-size: none;
margin-left: 10%;
}
.toolbar ul {
margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
}
.toolbar ul li {
float: left;
width: 200px;
height: 40px;
background-color: black;
opacity: 0.8;
line-height: 40px;
text-align: center;
font-size: 20px;
}
.toolbar ul li a {
text-decoration: none;
color: white;
display: block;
}
.toolbar ul li a:hover {
background-color: green;
}
.toolbar ul li ul li {
display: none;
}
.toolbar ul li:hover ul li {
display: block;
}
Whatever what I tried today, either the view was correctly below the toolbar but then the submenus were unclickable, or the views were below and centered but with a big margin-top to make the menu clickable or just beside the toolbar.
I am trying to replicate this kind of toolbar with the views right below it.
I guess the problem is 'float'. You will need a div with clear:both style after the toolbar and before the div containing router-view.
...
div class="toolbar"
...
/div
div style="clear:both"/
div
router-view
...
I have a unordered list in my HTML with 5 lists that all had with links on them that were working fine. It was working fine until I added another unordered list, but i have no links inside it. I even gave it a separate class.
Here is my markup/CSS:
ul {
margin: 0;
list-style-type: none;
color: white;
diplay: block;
padding-top: 20px;
padding-left: 350px;
font-family: "Economica", sans-serif;
font-size: 28px;
text-decoration: none;
}
ul li {
padding-left: 45px;
padding-right:45px;
display: inline;
text-decoration: none;
}
ul li a:hover {
font-weight:bold;
color:grey;
}
a {
text-decoration: none;
color:white;
}
<div id="mainPage" >
<img src="http://xoio.de/al_by_xoio1.jpg" alt="concert stadium" style="width:100%; position:absolute; padding-top:70px; height:930px">
<div id="navBar">
<div id="Logo">
<h1 style="font-weight:bold;"> Ice Arena </h1>
</div>
<ul id="select">
<li>
<a style="color:#ffe700;" href="#">Home</a>
</li>
<li>
Gallery
</li>
<li>
Order Form
</li>
<li>
The Arena
</li>
<li>
Contact Us
</li>
</ul>
</div>
</div>
I've only added the code regarding the list and area of my problem.
Add position: relative; to ul, otherwise other elements are above it and prevent the link behavior.
ul {
margin: 0;
list-style-type: none;
color: white;
diplay: block;
padding-top: 20px;
padding-left: 350px;
font-family: "Economica", sans-serif;
font-size: 28px;
text-decoration: none;
/* added */
position: relative;
}
ul li {
padding-left: 45px;
padding-right: 45px;
display: inline;
text-decoration: none;
}
ul li a:hover {
font-weight: bold;
color: grey;
}
a {
text-decoration: none;
color: white;
}
<div id="mainPage">
<img src="http://xoio.de/al_by_xoio1.jpg" alt="concert stadium" style="width:100%; position:absolute; padding-top:70px; height:930px">
<div id="navBar">
<div id="Logo">
<h1 style="font-weight:bold;">Ice Arena</h1>
</div>
<ul id="select">
<li><a style="color:#ffe700;" href="#">Home</a></li>
<li>Gallery</li>
<li>Order Form</li>
<li>The Arena</li>
<li>Contact Us</li>
</ul>
</div>
</div>
Try deleting the CSS property (position:absolute;) in line 3.
I am building a horizontal menu using unordered lists. 4 items are links and then there's an image in the center. Currently the links are centered on the middle of the image, but the I would rather the text vertically align lower than middle. The image is 140px tall and I would like the text to be at 50px. I've tried playing with vertical-align and line-height, but no joy. Padding doesn't work. I'm sure this is obvious and I'm just missing it. Any help would be appreciated.
Code:
.menu {
text-align: center;
}
.menu ul {
display: inline-table;
}
.menu ul li {
display: inline;
line-height: 0px;
}
.menu .link {
padding: 15px;
}
.menu a {
text-decoration: none;
font-size: 17px;
font-weight: 400;
color: #131313;
}
.menu a:hover {
color: #330000;
}
<div class="container">
<div class="row menu">
<ul>
<li class="link">MENU
</li>
<li class="link">ABOUT
</li>
<li class="link">
<a href="index.html">
<img class="center logo" src="https://placehold.it/140x140" />
</a>
</li>
<li class="link">BLOG
</li>
<li class="link">CONTACT
</li>
</ul>
</div>
</div>
Using bootstrap 3.3.6 as well.
You mean like this fiddle?
.menu { text-align:center; }
.menu ul { display:inline-table;}
.menu ul li {display:inline; line-height:0px;}
.menu .link {
padding: 15px;
}
img{
width: auto;
height: 140px;
vertical-align: -50px;
}
.menu a {
text-decoration: none;
font-size: 17px;
font-weight: 400;
color: #131313;
}
.menu a:hover {
color: #330000;
}
<div class="container">
<div class="row menu">
<ul>
<li class="link">MENU</li>
<li class="link">ABOUT</li>
<li class="link"><img class="center logo" src="https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300"/></li>
<li class="link">BLOG</li>
<li class="link">CONTACT</li>
</ul>
</div>
Give the text LI's a different class, and then apply vertical-align: 50px.
.menu {
text-align: center;
}
.menu ul {
display: inline-table;
}
.menu ul li {
display: inline;
line-height: 0px;
}
.menu .link {
padding: 15px;
}
.menu .link.align {
vertical-align: 50px;
}
.menu a {
text-decoration: none;
font-size: 17px;
font-weight: 400;
color: #131313;
}
.menu a:hover {
color: #330000;
}
<div class="container">
<div class="row menu">
<ul>
<li class="link align">MENU
</li>
<li class="link align">ABOUT
</li>
<li class="link">
<a href="index.html">
<img class="center logo" src="https://placehold.it/140x140" />
</a>
</li>
<li class="link align">BLOG
</li>
<li class="link align">CONTACT
</li>
</ul>
</div>
</div>
Not sure if you want the text to be vertical-align: top or vertical-align: middle but you can adjust it as you please with this codepen!
I made the li's inline-block which enables them to be adjusted by the vertical-align property and still be horizontal across your navigation.
I gave the background some color so that the stock image wouldn't blend in as much and you'd be able to see the alignment.
HTML:
<div class="container">
<div class="row menu">
<ul>
<li class="link">MENU</li>
<li class="link">ABOUT</li>
<li class="link"><img class="center logo" src="http://lorempixel.com/140/200/"/></li>
<li class="link">BLOG</li>
<li class="link">CONTACT</li>
</ul>
</div>
CSS:
body {
background: #BBB;
}
.menu {
text-align:center;
}
.menu ul {
display:inline-table;
}
.menu ul li {
display: inline-block;
vertical-align: middle;
}
.menu .link {
padding: 1em;
}
.menu a {
text-decoration: none;
font-size: 3.125em;
color: #131313;
}
.menu a:hover {
color: #330000;
}
i am trying to create a nav bar for my website. the drop down is giving me trouble. how do i align the submenu so that it shows as a proper drop down?
<div id="mainhead">
<div id="title">
<h1>StudiousEnough </h1>
</div>
<li>Home</li>
<li><a href="" >class</a>
<ul>
<li> Class XI </li>
<li> CLass XII </li>
</ul>
</li>
<li><a href="#" >jee</a></li>
<li><a href="aboutus.html" >about us</a></li>
</ul>
and here is the css:
#mainhead #mainnav ul {
list-style-type: none;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#mainhead #mainnav li {
display: block;
width: 25%;
background-color: #4D4D4D;
color: #FFFFFF;
text-align: center;
text-transform: uppercase;
float: left;
padding-bottom: 4px;
padding-top: 4px;
font-family: averia-libre;
font-style: normal;
font-weight: 700;
}
#mainhead #mainnav {
position: absolute;
width: 100%;
left: 0%;
right: 0%;
}
#mainhead #mainnav a{
display:block;
color: #ffffff;
text-decoration: none;
}
#mainhead #mainnav li:hover,#mainhead #mainnav li:focus,#mainhead #mainnav li:active {
background-color: #2535F3;
text-decoration: none;
}
#mainhead #mainnav ul li ul{
display: none;
}
#mainhead #mainnav ul li:hover ul{
display:block;
}
See the fiddle
I've added the following CSS to your CSS
CSS
#mainhead #mainnav ul li ul li{
width:100%;
clear:both;
}
First things first - check your html; you have some problems here. The list item tags need to be enclosed inside the unordered list parent tags. Also I don't see some of the ids and classes existing in the html that is used in your css.
If you always format your code, indenting enclosed blocks, that will help you spot all errors more quickly.
I went ahead and added a parent div with id = 'mainnav' and cleaned up your HTML, and it mostly renders as you'd expect. To get the submenu list items to 'stack' just make width 100%.
Clear is not necessary.
Check out the example on jsfiddle here:
https://jsfiddle.net/pianopaul/r3bb8k24/5/
<div id="mainhead">
<div id="title">
<h1>StudiousEnough </h1>
<div id="mainnav">
<ul class="menu">
<li>Home</li>
<li><a href="" >class</a>
<ul class="submenu">
<li> Class XI </li>
<li> CLass XII </li>
</ul>
</li>
<li><a href="#" >jee</a></li>
<li><a href="aboutus.html" >about us</a></li>
</ul>
</div>
</div>
</div>