Align <div> with bottom-right of parent <div>? - html

I have a couple groups of links at the top of a layout page for an MVC app, and I'm having trouble getting these links positioned properly.
Here's what they SHOULD look like (I'm making some huge changes to this site, but keeping the layout intact):
Keep in mind that this photo is at the center-right of my page, that is to say, the page extends further to the right, but there's no content in that area.
After altering these image-based links to text-based, they lose their styling integrity and scramble.
Here's some code from my current links to give an idea of how they're contained:
<div class="top-links">
<div id="top-nav">
<a class="top-link" href="#" title="My Profile">
<span>MY PROFILE</span>
</a>
<a class="top-link" href="#" title="Account Profile">
<span>ACCOUNT PROFILE</span>
</a>
<a class="top-link" href="#" title="Sign Out">
<span>SIGN OUT</span>
</a>
</div>
</div>
<div class="links">
<div id="nav">
<a class="home-link home-link-left" href="#" title="My Component Books">
<span>MY COMPONENT BOOKS</span>
</a>
<a class="home-link" href="#" title="New Component Book">
<span>NEW COMPONENT BOOK</span>
</a>
<a class="home-link" href="#" title="System Logs">
<span>SYSTEM LOGS</span>
</a>
</div>
</div>
I left out pieces of the tags themselves for readability.
And finally, the relevant CSS:
/*----------- TOP NAVIGATION -----------*/
.top-links {
float: right;
height: 31px;
margin: 0 0 0 0;
width: auto
}
.top-link {
font: 7pt Georgia, serif;
color: #E1915C;
text-align:center;
text-decoration: none;
line-height: 34px;
padding: 10px;
}
#top-nav {
float: right;
margin: 0 0 0 0;
overflow: hidden;
}
/*----------- NAVIGATION -----------*/
.links {
float: right;
width: auto;
height: 36px;
overflow: hidden;
bottom: 0;
right: 0;
}
.home-link {
font: 7.25pt Georgia, serif;
color: #E1915C;
text-decoration: none;
font-weight: bold;
border-right: 1px solid #E1E1E1;
text-align: center;
line-height: 36px;
width: auto;
padding: 10px;
}
.home-link:hover {
color: #369AAA;
}
.home-link-left {
border-left: 1px solid #E1E1E1;
}
.home-link-right {
border-right: 1px solid #E1E1E1;
}
#nav {
position: absolute;
float: right;
overflow: hidden;
}
Sorry if it seems like a bit much, some of it isn't my original code and I'm not sure what I should/shouldn't include.
I'm not the best with CSS, so could any styling gurus give me some insight on how I can make the links lay out as they are in the screenshot?

Here is the jsFiddle: http://jsfiddle.net/FVjhQ/2/
CSS
#profile-nav {
margin-bottom: 25px;
}
.nav-container,
.nav-container li {
margin: 0;
padding: 0;
}
.nav-container {
clear: right;
float: right;
}
.nav-container li {
border-left: 1px solid #E1E1E1;
float: left;
list-style: none;
line-height: 36px;
}
.nav-container a {
font: 7.25pt Georgia, serif;
color: #E1915C;
text-decoration: none;
font-weight: bold;
padding: 10px;
text-transform: uppercase;
}
.nav-container a:hover {
color: #369AAA;
}
.nav-container .last-link {
border-right: 1px solid #E1E1E1;
}
.no-border li {
border: 0;
}
HTML
<ul id="profile-nav" class="nav-container no-border">
<li>
My Profile
</li>
<li>
Account Profile
</li>
<li>
Sign Out
</li>
</ul>
<ul id="component-nav" class="nav-container">
<li>
My Component Books
</li>
<li>
New Component Books
</li>
<li>
Notifications
</li>
<li class="last-link">
System Logs
</li>
</ul>

See if this is what you were going for: http://jsfiddle.net/derekstory/cHnXx/
/*----------- TOP NAVIGATION -----------*/
.top-links {
height: 31px;
margin: 0 0 0 0;
width: auto;
}
.top-link {
font: 7pt Georgia, serif;
color: #E1915C;
text-align:center;
text-decoration: none;
line-height: 34px;
padding: 10px;
}
#top-nav {
float: right;
margin: 0 0 0 0;
overflow: hidden;
}
/*----------- NAVIGATION -----------*/
.links {
whitespace: nowrap;
min-width: 120px;
float: right;
height: 36px;
}
.home-link {
font: 7.25pt Georgia, serif;
color: #E1915C;
text-decoration: none;
font-weight: bold;
border-right: 1px solid #E1E1E1;
text-align: center;
line-height: 36px;
width: auto;
padding: 10px;
}
.home-link:hover {
color: #369AAA;
}
.home-link-left {
border-left: 1px solid #E1E1E1;
}
.home-link-right {
border-right: 1px solid #E1E1E1;
}
#nav {
position: absolute;
float: right;
overflow: hidden;
}

Related

How to shift one element of an <li> list to the right

I have an unordered linked list. I'm trying to shift one of the items in the navigation all the way to the right (Order) as if it had text-align: right;. I tried using float: right; and text-align: right;, but none of them seemed to work. If I set the margin-left to a really high number (such as 100px) it does shift to the right, but if I resize my window then I can't see it anymore or it's not on the right side of the page. Here is the HTML:
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
Any help would be greatly appreciated. Thanks!
Assuming you're looking to move your .order element, you'll want to apply the float: right rule to the parent (<li>) element. I've added a class to this, .order-container, to make this easier to achieve in the following example.
Note also that once you float to the right, it will be off the screen by default. You'll want to set a negative margin-right to circumvent this. I've gone with margin-right: -10em in the following, to match the offset from the image on the left.
Ultimately, you may wish to consider using a framework to achieve responsive design, ensuring that the offset is correct regardless of screen size.
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
float: right;
}
.order-container {
float: right;
margin-right: 10em;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="order-container">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
MDN still advises that <div> is not a valid child of <ul>. Furthermore float adds a whole heap of side effects by removing the items from the natural flow of the document. To modernize this we can make use of display:flex
/*Normalise body*/
body {
margin:0;
}
/*Set flex on the nabar top position logo and links*/
.navbar {
display: flex;
}
/*Ad a maring to the logo link*/
.navbar > a:first-of-type {
margin-left: 5em;
}
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
/*Ad flex to the nav link element*/
display: flex;
/*Vertically center the links*/
align-items:center;
}
/*Push the last element right but give it a little margin to the right*/
.navbar ul>li:last-of-type {
margin-left: auto;
margin-right:1em;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
}
.navbar a {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
You should use media queries for making navbar responsive.
a {
text-decoration: none;
color: black;
}
.navbar {
width: 100%;
overflow: hidden;
position: fixed;
top: 0;
display: flex;
justify-content: space-between;
border-bottom: solid 1px black;
}
.div-links {
display: flex;
align-items: center;
width: 70%;
}
.nav-links {
width: 100%;
display: flex;
justify-content: end;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.nav-links li {
padding: 2rem;
}
.nav-items {
width: 30%;
display: flex;
justify-content: space-around;
}
.order {
overflow: hidden;
color: #ffffff !important;
background: #1419e2;
text-decoration: none;
padding: 0.8rem;
border-radius: 5px;
}
<div class="navbar">
<a href="glacier_hills.html">
<img
src="Images/Glacier-Hills-Logo.svg"
alt=""
width="182"
height="90"
/>
</a>
<div class="div-links">
<ul class="nav-links">
<div class="nav-items">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="btn">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
</div>

How to move a specific element?

An element won't move to my intended position. I want to have some white space between the right of "Register" and the browser but don't know how to do it. I have tried padding but it seem to be kind of wrong thinking.
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
font-family: sans-serif;
color: black;
}
.firstpart {
background-color: #eee;
height: 30vh;
}
.navbar li {
list-style: none;
display: inline;
}
.navbar-left {
float: left;
padding: 20px 20px 0 20px;
}
.navbar-right {
float: right;
padding: 20px 20px 0px 20px;
}
.badge {
background-color: black;
color: white;
height: 35px;
width: 80px;
}
<div class="firstpart">
<div class="navbar">
<ul>
<li class="navbar-left">ABOUT</li>
<li class="navbar-left">CONTACT</li>
<li class="navbar-left">FAQS</li>
<div class="navbar-right badge">
<li>REGISTER</li>
</div>
<li class="navbar-right">SIGN IN</li>
<li class="navbar-right">MANAGE BOOKING</li>
</ul>
</div>
</div>
You just need to add:
.navbar {
padding-right: 10px;
}
You can also remove the div inside of your unordered list as this isn't valid HTML. Replace it with:
<li class="navbar-right badge">REGISTER</li>
Code (open in "Full page" view as otherwise "Manage Booking" gets wrapped):
/* Add this */
.navbar {
padding-right: 10px;
}
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body{
font-family: sans-serif;
color: black;
}
.firstpart{
background-color:#eee;
height: 30vh;
}
.navbar li{
list-style: none;
display: inline;
}
.navbar-left{
float: left;
padding: 20px 20px 0 20px;
}
.navbar-right{
float: right;
padding: 20px 20px 0px 20px;
}
.badge{
background-color: black;
color:white;
height: 35px;
width: 80px;
}
<body>
<div class="firstpart">
<div class="navbar">
<ul>
<li class="navbar-left">ABOUT</li>
<li class="navbar-left">CONTACT</li>
<li class="navbar-left">FAQS</li>
<li class="navbar-right badge">REGISTER</li> <!-- Use an li element instead -->
<li class="navbar-right">SIGN IN</li>
<li class="navbar-right">MANAGE BOOKING</li>
</ul>
</div>
</div>
</body>
I think you could simply set a width for .navbar div to say, 98%
.navbar {
width:98%;
}

Including an Icon inside the <input> tag

.Main {
width: 100%;
height: 100%;
}
// css to show the navigation bar top and the image of westminister
h1 {
text-align: center;
font: italic bold 50px Georgia, serif;
}
#navbar ul {
margin: 0;
padding-left: 0;
padding-right: 0;
overflow: hidden;
background-color: black;
font-size: 15px;
width: 100%;
}
#navbar li {
float: left;
list-style-type: none;
}
li a {
display: inline;
color: #d9d9d9;
padding: 25px 20px;
text-decoration: none;
list-style-type: none;
}
.topnavbar {
text-align: right;
font: size 19px;
padding: 18px 20px;
margin-right: 10px;
float: right;
}
#searchbar {
text-align: right;
text-decoration-color: #ffffff;
font: size 15px;
padding: 10px;
padding-right: 20px;
margin-top: 18px;
margin-right: 20px;
float: right;
background: #2f3640;
transform: translate3d(-50%, 50%);
border-radius: 40px;
outline: none;
transition: 0.4s;
width: 150px;
}
.search-btn {
text-decoration: none;
}
#btn {
margin-top: 30px;
color: white;
display: flex;
}
li a:hover:not(.active) {
opacity: 1;
color: #ffffff;
}
.active {
text-decoration: none;
color: #4da6ff;
outline: none;
}
I'm trying to make this web application using AngularJS and I am fairly new to it. I am making a navigation bar for a page to start with and I think I have done the normal bar properly. However I want to also add a search bar (haven't done the functioning yet since I have no idea how to) which will appeal when the mouse hovers over the <a> tag . I'm referring to a video which will be linked below. The difference is he is not using a navigation bar instead doing it in the middle of the video
The css and html is shown below.
The video I am referring to is this: https://www.youtube.com/watch?v=v1PeTDrw6OY
PS: what I want to do is include the icon inside the gray padding area so I can set the padding to zero and it would have the icon inside the padding alone and on hover I could expand the search bar field and let the user type. Any input regarding this is highly appreciated. Thank you
You need to have a common parent element to make it easier on yourself. With your HTML the most straightforward way would be to include the <a> into the <li>, instead of having it after. So turn this
<li><input type="text" id="searchbar" placeholder="Search Here"> </li>
<a class="search-btn" href="#"> <i id="btn" class="fas fa-search"></i> </a>
Into this:
<li>
<input type="text" id="searchbar" placeholder="Search Here">
<a class="search-btn" href="#"> <i id="btn" class="fa fa-search"></i> </a>
</li>
Then you can use position: absolute and easily place the icon where you want by adding this CSS:
li {
position: relative;
}
li input + a {
position: absolute;
top: 4px; /* change this */
left: 5px; /* change this */
}
using search-bar class, you can get what you want
.Main {
width: 100%;
height: 100%;
}
// css to show the navigation bar top and the image of westminister
h1 {
text-align: center;
font: italic bold 50px Georgia, serif;
}
#navbar ul {
margin: 0;
padding-left: 0;
padding-right: 0;
overflow: hidden;
background-color: black;
font-size: 15px;
width: 100%;
}
#navbar li {
float: left;
list-style-type: none;
}
li a {
display: inline;
color: #d9d9d9;
padding: 25px 20px;
text-decoration: none;
list-style-type: none;
}
.topnavbar {
text-align: right;
font: size 19px;
padding: 18px 20px;
margin-right: 10px;
float: right;
}
#searchbar {
text-align: left;
text-decoration-color: #ffffff;
font: size 15px;
padding: 10px;
padding-right: 20px;
float: right;
background: #2f3640;
transform: translate3d(-50%, 50%);
border-radius: 40px;
outline: none;
transition: 0.4s;
width: 150px;
}
.search-btn {
text-decoration: none;
background: transparent;
outline: 0;
border: 0;
color: #fff;
position: absolute;
right: 10px;
top: 38px;
bottom: 0;
margin: auto 0;
line-height: 100%;
display: inline-block;
line-height: 100%;
display: block;
height: 22px;
}
li a:hover:not(.active) {
opacity: 1;
color: #ffffff;
}
.active {
text-decoration: none;
color: #4da6ff;
outline: none;
}
.search-bar{
position: relative;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<div class="Main">
<div id="navbar">
<ul>
<li><img src="assets/img/xyz.png" alt="logo" width="180px" height="80px" style="float:left"></li>
<li> <a class="topnavbar active" [routerLink]="['page6']">Display Items </a> </li>
<li> <a class="topnavbar" [routerLink]="['page2']">Add Items </a> </li>
<li> <a class="topnavbar" [routerLink]="['page3']"> Delete Items </a> </li>
<li> <a class="topnavbar" [routerLink]="['page4']">Borrow Items </a> </li>
<li> <a class="topnavbar" [routerLink]="['page5']">Return Items</a> </li>
<li> <a class="topnavbar" [routerLink]="['page6']">Generate Report </a> </li>
<li> <a class="topnavbar" [routerLink]="['page6']">Generate Report </a> </li>
<li>
<div class="search-bar">
<input type="text" id="searchbar" placeholder="Search Here">
<button class="search-btn"><i id="btn" class="fas fa-search"></i></button>
</div>
</li>
</ul>
</div>
</div>

li tag when hover won't underline

Hi guys i'm having a small issue with my li tags when using a link as i'm trying to make it underline when hovering over them but for some reason I can't seem to get it working. Can anyone see where i'm going wrong here?
Thanks
body {
margin: 0;
background-color: #f6f4fb;
}
p {
margin: 0;
}
#header {
margin: 0;
padding: 0;
width: 100%;
height: 80px;
background-color: #fff;
border-bottom: 2px solid #e1dfe1;
}
#logo {
float: left;
padding-left: 30px;
padding-top: 15px;
}
#name {
float: left;
font-family: Arial, Helvetica, sans-serif;
font-size: 30px;
padding-top: 25px;
padding-left: 30px;
}
#name a {
text-decoration: none;
color: #666;
}
#headerButtons {
float: right;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
color: #999;
}
#headerButtons ul {
margin: 0;
}
#headerButtons li {
float: right;
list-style-type: none;
padding-right: 40px;
padding-top: 30px
}
#headerButtons a {
text-decoration: none;
color: #999;
}
#headerButtons a:hover {
text-decoration: underline;
}
<div id="header">
<div id="logo">
<img src="IMAGES/Logo.svg" width="50px" height="50px">
</div>
<div id="name">
<a href="index.php">
<p>Project Archive</p>
</a>
</div>
<div id="headerButtons">
<ul>
<a href="Login.php">
<li>Register</li>
</a>
<a href="Register.php">
<li>Login</li>
</a>
</ul>
</div>
</div>
According to HTML specification its not valid to add anchor inside the
ul tag
Correct way would be, You put all the anchor tag inside the li tag. So, that your css get applied to the text node properly.
Although the above reason is not why your style is not applied.
Below is the explaination why the browser is not adding the style.
Your HTML structure has li tag inside anchor tag
<a href="Login.php">
<li>Register</li>
</a>
and you are trying to underline the text in your css on hover of anchor tag.
#headerButtons a:hover {
text-decoration: underline;
}
This will not work. As, your anchor tag have li node and not a text node so the css text-decoration: underline; style is not applied.
You have to select the li tag on hover of the anchor node to apply the css to the text node.
To do this Add this css (I won't recommend using this approach.)
#headerButtons a:hover>li {
text-decoration: underline;
}
SNIPPET
(you should not use this snippet use the next one below).
This snippet is just to demonstrate that style can be applied. You should use the next snippet.
body {
margin: 0;
background-color: #f6f4fb;
}
p {
margin: 0;
}
#header {
margin: 0;
padding: 0;
width: 100%;
height: 80px;
background-color: #fff;
border-bottom: 2px solid #e1dfe1;
}
#logo {
float: left;
padding-left: 30px;
padding-top: 15px;
}
#name {
float: left;
font-family: Arial, Helvetica, sans-serif;
font-size: 30px;
padding-top: 25px;
padding-left: 30px;
}
#name a {
text-decoration: none;
color: #666;
}
#headerButtons {
float: right;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
color: #999;
}
#headerButtons ul {
margin: 0;
}
#headerButtons li {
float: right;
list-style-type: none;
padding-right: 40px;
padding-top: 30px
}
#headerButtons a {
text-decoration: none;
color: #999;
}
#headerButtons a:hover>li {
text-decoration: underline;
}
<div id="header">
<div id="logo">
<img src="IMAGES/Logo.svg" width="50px" height="50px">
</div>
<div id="name">
<a href="index.php">
<p>Project Archive</p>
</a>
</div>
<div id="headerButtons">
<ul>
<a href="Login.php">
<li>Register</li>
</a>
<a href="Register.php">
<li>Login</li>
</a>
</ul>
</div>
</div>
But correct solution according to html specification would be you put
all anchor inside the li tag as shown below.
<div id="header">
<div id="logo">
<img src="IMAGES/Logo.svg" width="50px" height="50px">
</div>
<div id="name">
<a href="index.php">
<p>Project Archive</p>
</a>
</div>
<div id="headerButtons">
<ul>
<li>
<a href="Login.php">
Register
</a>
</li>
<li>
<a href="Register.php">
Login
</a>
</li>
</ul>
</div>
</div>
Here is a snippet
body {
margin: 0;
background-color: #f6f4fb;
}
p {
margin: 0;
}
#header {
margin: 0;
padding: 0;
width: 100%;
height: 80px;
background-color: #fff;
border-bottom: 2px solid #e1dfe1;
}
#logo {
float: left;
padding-left: 30px;
padding-top: 15px;
}
#name {
float: left;
font-family: Arial, Helvetica, sans-serif;
font-size: 30px;
padding-top: 25px;
padding-left: 30px;
}
#name a {
text-decoration: none;
color: #666;
}
#headerButtons {
float: right;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
color: #999;
}
#headerButtons ul {
margin: 0;
}
#headerButtons li {
float: right;
list-style-type: none;
padding-right: 40px;
padding-top: 30px
}
#headerButtons a {
text-decoration: none;
color: #999;
}
#headerButtons a:hover>li {
text-decoration: underline;
}
<div id="header">
<div id="logo">
<img src="IMAGES/Logo.svg" width="50px" height="50px">
</div>
<div id="name">
<a href="index.php">
<p>Project Archive</p>
</a>
</div>
<div id="headerButtons">
<ul>
<a href="Login.php">
<li>Register</li>
</a>
<a href="Register.php">
<li>Login</li>
</a>
</ul>
</div>
</div>
You can't use li tag inside a tag, li must be inside ul tags
body {
margin: 0;
background-color: #f6f4fb;
}
p {
margin: 0;
}
#header {
margin: 0;
padding: 0;
width: 100%;
height: 80px;
background-color: #fff;
border-bottom: 2px solid #e1dfe1;
}
#logo {
float: left;
padding-left: 30px;
padding-top: 15px;
}
#name {
float: left;
font-family: Arial, Helvetica, sans-serif;
font-size: 30px;
padding-top: 25px;
padding-left: 30px;
}
#name a {
text-decoration: none;
color: #666;
}
#headerButtons {
float: right;
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
color: #999;
}
#headerButtons ul {
margin: 0;
}
#headerButtons li {
float: right;
list-style-type: none;
padding-right: 40px;
padding-top: 30px
}
#headerButtons a {
text-decoration: none;
color: #999;
}
#headerButtons a:hover {
text-decoration: underline;
}
<div id="header">
<div id="logo">
<img src="IMAGES/Logo.svg" width="50px" height="50px">
</div>
<div id="name">
<a href="index.php">
<p>Project Archive</p>
</a>
</div>
<div id="headerButtons">
<ul>
<li>
<a href="Login.php">
Register
</a>
</li>
<li>
<a href="Register.php">
Login
</a>
</li>
</ul>
</div>
</div>

Dropdown Menu on hover image

W3Schools
Hello,
I've been trying to integrate a drop down menu based upon the hover over function of an image. I've gone to the above website which gives an example, but I cannot figure it out. Below is my current HTML. The image I would like to have the hover over function work on and from that have a drop down menu is the Logo.png file. I simply cannot figure out how to integrate this into my code. Any direction or help would be appreciated.
::-webkit-scrollbar {
display: none;
}
body {
margin: 0;
background-color: #808080;
}
#menu {
position: fixed;
width: 100%;
height: 140px;
background-color: #555555;
}
#logopic {
height: 100px;
width: 140px;
}
#logo {
float: left;
margin: 1%;
width: 160px;
}
.menuoptions {
border: 1px solid white;
border-radius: 50px;
padding: 14px;
float: left;
letter-spacing: 2px;
list-style-type: none;
color: #FFFFFF;
margin-top: 30px;
margin-left: 45px;
font-size: 125%;
font-weight: bold;
}
.menuoptions:hover {
color: #00b9f1;
background-color: #FFFFFF;
}
#topsection {
padding-top: 150px;
}
ul li {
list-style-position: inside;
}
<div id="menu">
<div id="logodiv">
<a href="index.html">
<img id="logo" src="images/Logo.png">
</a>
</div>
<div id="menulinks">
<ul id="options">
<a href="#income">
<li class="menuoptions">INCOME</li>
</a>
<a href="#expenses">
<li class="menuoptions">EXPENSES</li>
</a>
<a href="#incomedistribution">
<li class="menuoptions">INCOME DISTRIBUTION</li>
</a>
<a href="#spending">
<li class="menuoptions">SPENDING</li>
</a>
<a href="#sidemenu">
<li class="menuoptions">SIDE MENU</li>
</a>
</ul>
</div>
</div>
Use the sibligns selector "+"
::-webkit-scrollbar {
display: none;
}
body {
margin: 0;
background-color: #808080;
}
#menu {
position: fixed;
width: 100%;
height: 140px;
background-color: #555555;
}
#logopic {
height: 100px;
width: 140px;
}
#logo {
float: left;
margin: 1%;
width: 160px;
}
.menuoptions {
border: 1px solid white;
border-radius: 50px;
padding: 14px;
float: left;
letter-spacing: 2px;
list-style-type: none;
color: #FFFFFF;
margin-top: 30px;
margin-left: 45px;
font-size: 125%;
font-weight: bold;
}
.menuoptions:hover {
color: #00b9f1;
background-color: #FFFFFF;
}
#topsection {
padding-top: 150px;
}
ul li {
list-style-position: inside;
}
#menulinks {
display: none;
}
#logodiv:hover + #menulinks {
display: block
}
<div id="menu">
<div id="logodiv">
<a href="index.html">
<img id="logo" src="images/Logo.png">
</a>
</div>
<div id="menulinks">
<ul id="options">
<a href="#income">
<li class="menuoptions">INCOME</li>
</a>
<a href="#expenses">
<li class="menuoptions">EXPENSES</li>
</a>
<a href="#incomedistribution">
<li class="menuoptions">INCOME DISTRIBUTION</li>
</a>
<a href="#spending">
<li class="menuoptions">SPENDING</li>
</a>
<a href="#sidemenu">
<li class="menuoptions">SIDE MENU</li>
</a>
</ul>
</div>
</div>
Germano Plebani > I believe it won't work, because when you stop hovering the logo, the menu will disappear again.
I changed your code a bit to make it a bit more simple (at least, in my opinion) :
<div id="menu">
<ul>
<li id="logo"><img src="your_path"></li>
<li class="menuoptions">INCOME</li>
<li class="menuoptions">EXPENSES</li>
<li class="menuoptions">INCOME DISTRIBUTION</li>
<li class="menuoptions">SPENDING</li>
<li class="menuoptions">SIDE MENU</li>
</ul>
::-webkit-scrollbar {
display: none;
}
body {
margin: 0;
background-color: #808080;
}
#menu {
position: fixed;
width: 100%;
height: 140px;
background-color: #555555;
}
#logo {
height:140px;
}
#logo img{
width:160px;
}
ul{
height:inherit;
width:160px; /* Your menu has the size of your logo */
}
ul:hover {
width:auto; /* when you hover your menu, it will take 100% of the width of it's container */
}
ul li {
float: left;
list-style:none;
}
ul:hover .menuoptions {
display:block;
}
.menuoptions {
border: 1px solid white;
border-radius: 50px;
padding: 14px;
letter-spacing: 2px;
list-style-type: none;
color: #FFFFFF;
margin-top: 30px;
margin-left: 45px;
font-size: 125%;
font-weight: bold;
display:none;
}
.menuoptions:hover {
color: #00b9f1;
background-color: #FFFFFF;
}
I didn't go for optimization neither, but it works fine.