I have a screenshot as shown below which I have replicated in HTML, CSS and JS.
I have created the fiddle for the above screenshot. The above screen-shot portion is at the extreme right in the fiddle. On clicking three dots, the drop-down menu appears.
The HTML and CSS codes which I have used in order to create the drop-down is:
HTML:
<div class="nav-top-searchbar">
<form>
<span class="fa fa-search searchicon fa-lg" aria-hidden="true"></span>
<input type="text" name="search">
<div style="">
<img tabindex="1" src="https://s9.postimg.org/d6s4xvykv/Ellipsis.png" id="ellipsis">
<div class="dropdown">
<li>View Status<i class="fa fa-angle-down" aria-hidden="true"></i></li>
<li>Release Bills</li>
<li>Add Attendee</li>
<li>Export as</li>
<li>View in Google Sheets</li>
<li>Send Notifications</li>
</div>
</div>
</form>
</div>
CSS:
// General CSS
.nav-top-searchbar {
position: relative;
}
#ellipsis {
top: 12px;
position: absolute;
right: 43px;
cursor: pointer;
}
#ellipsis:focus {
outline: none;
}
#ellipsis:focus+.dropdown {
display: block;
}
input[type=text] {
width: 100%;
background: #10314c;
}
.dropdown {
background-color: #FFFFFF;
display: none;
padding-left: 2%;
position: absolute;
/* height: 150px; */
right: 0;
width: 200px;
z-index: 10;
list-style-type: none;
padding-top: 25px;
padding-bottom: 25px;
box-shadow: 0 0 15px #888;
top: 2px;
}
.searchicon {
float: left;
margin-top: -20px;
position: relative;
top: 26px;
left: 8px;
color: white;
border: 1px solid #FFFFFF;
z-index: 2;
padding: 3px;
}
.dropdown a {
color: #676767;
font-weight: bold;
font-size: 14px;
}
.dropdown li:hover {
background-color: #EDEDED;
}
Problem Statement:
In my fiddle, the hover doesn't cover the entire row. It only covers 80% of the row. I am wondering what changes do I need to make in the above CSS codes so that the hover covers the entire row.
You have padding on your dropdown container:
.dropdown{
padding-left: 2%;
}
This space is unusable by the child list items. Put the padding on the list items instead:
.dropdown li{
padding-left: 2%;
}
https://jsfiddle.net/nc2djn5p/94/
This should do the trick: https://jsfiddle.net/hp0hxoL3/
.dropdown {
background-color: #FFFFFF;
display: none;
padding-left: 2%;
position: absolute;
/* height: 150px; */
right: 0;
width: 200px;
z-index: 10;
list-style-type: none;
padding-top:25px;
padding-bottom:25px;
box-shadow: 0 0 15px #888;
top: 2px;
list-style: none;
padding: 0;
margin: 0;
}
.searchicon {
float: left;
margin-top: -20px;
position: relative;
top: 26px;
left: 8px;
color: white;
border: 1px #FFFFFF;
z-index: 2;
}
.dropdown a
{
color: #676767;
font-weight: bold;
font-size: 14px;
}
.dropdown li {
padding: 8px;
}
.dropdown li:hover
{
background-color: #EDEDED;
}
It doesn't match exactly the example, but it's close enough.
Your div class="dropdown" has a left padding of 2%. You will need to set it to 0.
As David said, set the padding in .dropdown li, instead of .dropdown
Related
I am designing a simple website using html/css/javascript/bootstrap.
But i am having weird kind of problem.
I want my menu and showcase first and after that i have another section called 'about' but about section is coming at first and menu is going down as show in pic
Here is my code
home.html
<section id="home">
<div id="menu">
<a id="toggle" (click)="openMenu()">
<i *ngIf="showMenu" class="fa fa-bars menu-bar" aria-hidden="true"></i>
</a>
<a id="close-btn" (click)="closeMenu()">
<i *ngIf="!showMenu" class="fa fa-times close-btn" aria-hidden="true"></i>
</a>
<ul class="menu-items bg-white rounded" #menuItems>
<li>
Intro
</li>
<li>
About
</li>
<li>
Projects
</li>
<li>
Contact
</li>
</ul>
</div>
<div id="heading">
<div id="logo-tagline" class="container">
<p id="logo">A Webdeveloper</p>
<p id="tagline">
Hey! I`m Narayan &
<br> this is my website,
<br> feel free to have a
<br> look around.
</p>
</div>
</div>
</section>
<section id="about">
<div class="about container">
<h1 id="about-me">About</h1>
<p>
Koa is a new web framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust
foundation for web applications and APIs. By leveraging async functions, Koa allows you to ditch callbacks and greatly
increase error- handling. Koa does not bundle any middleware within its core, and it provides an elegant suite of methods
that make writing servers fast and enjoyable.
</p>
</div>
</section>
style.scss
/* You can add global styles to this file, and also import other style files */
#import "~bootswatch/dist/lux/_variables.scss";
#import "~bootstrap/scss/bootstrap.scss";
#import "~bootswatch/dist/lux/_bootswatch.scss";
$primary-color: #F4F4F4;
$secondary-color: #FFFFFF;
body {
background-color: $primary-color;
}
//navbar
#menu {
position: fixed;
top: 35px;
right: 42px;
z-index: 50;
}
#menu a#toggle {
position: absolute;
top: 0;
right: 0;
padding: 15px;
background: transparent;
border-radius: 2px;
border: 1px solid transparent;
z-index: 5;
font-size: 1.3rem;
color: black;
cursor: pointer;
}
#menu a#close-btn {
position: absolute;
top: 0;
right: 0;
padding: 15px;
background: transparent;
border-radius: 2px;
border: 1px solid transparent;
z-index: 5;
font-size: 1.3rem;
color: black;
cursor: pointer;
}
#menu ul {
display: none;
position: absolute;
top: 45px;
right: 0;
margin: 0;
border: 1px solid #efefef;
border-bottom: 1px solid #ddd;
border-radius: 2px;
padding: 35px;
box-shadow: 0 1px 3px 0 #eee;
}
#menu ul li {
list-style-type: none;
}
#menu ul li a {
display: block;
text-decoration: none;
padding: 3px 0;
color: inherit;
}
#menu ul li a:hover {
text-decoration: underline;
color: black;
}
/*sidenav
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: $secondary-color;
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 10%;
width: 100%;
text-align: left;
margin-top: 30px;
}
.overlay a {
padding-left: 10px;
text-decoration: none;
font-size: 26px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover,
.overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 35px;
right: 40px;
font-size: 1.3rem;
color: black !important;
}
#media screen and (max-height: 450px) {
.overlay a {
font-size: 20px
}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
*/
//heading or showcase
#heading {
position: absolute;
top: 70%;
margin-top: -150px;
text-align: left;
width: 100%;
}
#logo {
font: 27px 'Italiana', sans-serif;
text-transform: uppercase;
letter-spacing: 14px;
color: white;
background-color: black;
width: 60%;
padding: 14px 10px 10px 10px;
}
#tagline {
font-size: 22px;
}
//about section
#about {
background-color: $secondary-color;
}
Your problem is you are using absolute positioning for everything which removes the element from the normal page flow. Learn to use relative positioning and then elements will generally fall in the order they appear in the code.
I am making dropdown menu for my main menu, there is username where user clicks and then it shows the content (dropdown menu), This was made by checkbox type input for the button.
Unfortunately, menu doesn't seem to show at all, and disappears at the end of the menu.
Menu:
HTML:
<div class="profilebar">
<div class="dropdown" style="cursor: pointer;">
<input type="checkbox" id="droptoggle" class="toggled">
<label for="droptoggle" class="profilename" style="cursor: pointer;">{{ username }}<span class="caret">▾</span></label>
<ul class="dropdown-menu" role="menu">
<li class="sub-menu">
Link1
Link2
Link3
<a href-"/">Link4t</a>
</li>
</ul>
</div>
<img class="profilepicture" src="url here"></img>
<p class="balance" style="text-decoration:none">${{ balance }}</p>
</div>
</div>
CSS:
.profilebar {
float: right;
width: 150px;
height: 7%;
margin-top: 0.5%;
margin-right: 1.5%;
min-width: 70px;
}
.profilename {
position: relative;
font-family: 'Lato', sans-serif;
font-weight: 400;
width: 0.5%;
font-size: 11pt;
color: white;
text-decoration: none;
}
.caret {
margin-left: 3.5%;
font-size: 8pt;
}
.dropdown {
position: relative;
display: inline-block;
margin-top: 0%;
margin-left: 4%;
}
.dropdown-menu {
display: none;
position: absolute;
margin: 2px;
width: 10px;
min-width: 10px;
background-color: white;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 99;
}
.dropdown-menu a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-menu + a:hover {
background-color: #C90205
}
.toggled {
visibility: hidden;
display: none;
}
.profilepicture {
position: absolute;
margin-left: 1.2%;
border-style: groove;
border-width: 1.5px;
}
.balance {
position: relative;
margin-top: 2.3%;
color: red;
font-family: 'Lato', sans-serif;
font-weight: 400;
font-size: 12pt;
color: #C90205;
margin-left: 44.5%;
}
.toggled:checked ~ .dropdown-menu {
display: block;
z-index: 99;
}
Fiddle ( Don't look at image, it is placeholder anyway ).
So what can the problem be? i have tried z-index on positioned elements which didn't seem to work out, how can i make dropdown menu overlay every other element so it can be fully seen?
The menu has overflow: hidden, so it will hide when going beyond the content, removing the overflow: hidden from the menu class shows the dropdown menu.
Fiddle
<style>
.profilebar {
/* float: right;
width: 150px;
height: 7%;
margin-top: 0.5%;
margin-right: 1.5%;
min-width: 70px; */
position: absolute;
top: 0.5%;
right: 1.5%;
width: 150px;
height: 7%;
border: 1px solid #777;
}
.profilename {
position: relative;
font-family: 'Lato', sans-serif;
font-weight: 400;
width: 0.5%;
font-size: 11pt;
color: white;
text-decoration: none;
}
.caret {
margin-left: 3.5%;
font-size: 8pt;
}
.dropdown {
position: relative;
display: inline-block;
margin-top: 0%;
margin-left: 4%;
}
.dropdown label {
color: #333;
}
.dropdown-menu {
display: none;
position: absolute;
margin: 2px;
width: 100px;
min-width: 10px;
background-color: white;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 99;
}
.dropdown-menu a {
color: #333;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-menu + a:hover {
background-color: #C90205
}
.toggled {
visibility: hidden;
display: none;
}
.profilepicture {
position: absolute;
margin-left: 1.2%;
border-style: groove;
border-width: 1.5px;
}
.balance {
position: relative;
margin-top: 2.3%;
color: red;
font-family: 'Lato', sans-serif;
font-weight: 400;
font-size: 12pt;
color: #C90205;
margin-left: 44.5%;
}
.toggled:checked ~ .dropdown-menu {
display: block;
z-index: 99;
}
</style>
<body>
<div class="profilebar">
<div class="dropdown" style="cursor: pointer;">
<input type="checkbox" id="droptoggle" class="toggled">
<label for="droptoggle" class="profilename" style="cursor: pointer;">USERNAME<span class="caret">▾</span></label>
<ul class="dropdown-menu" role="menu">
<li class="sub-menu">
Link1
Link2
Link3
Link4
</li>
</ul>
</div>
<img class="profilepicture" src="url here"></img>
<p class="balance" style="text-decoration:none">BALANCE</p>
</div>
</div>
So I'm working on a CSS drop down menu where the div container is revealed by a radio button and I have that working as I'd like.
However, I'd like to add a second level to my drop-down just like it (same width, positioning beneath parent, ect..) I have it revealing the second level when you click on the input, however, If the input is in the middle (in between two links) my first level's links move beneath my first level of sub-menu. Please help? I can't figure out how to keep it looking the same way it's just if that input has another sub menu I would like for it to drop down below the first.
My code:
/*CSS for Menu */
.menu {
position: fixed;
top: 0;
left: 0;
height: 20px;
width: 100%;
z-index: 10000;
display: inline-block;
background-image: black url(../images/glossyback.gif);
background-color: #0066CC;
text-align: center;
font-family: Arial, Geneva, sans-serif;
}
/*CSS for main menu labels */
input + label {
color: #FFFFFF;
display: inline-block;
padding: 6px 8px 10px 24px;
background-image: black url(../images/glossyback2.gif);
height: 8px;
margin: 0;
line-height: 12px;
position: relative;
}
input:hover + label:hover {
background: #3385D6;
}
input + label + div {
margin: 0;
margin-top: 2px;
padding: 16px;
border: 1px solid;
width: 100%;
height: auto;
position: absolute;
top: 20px;
display: none;
}
input:checked + label + div {
display: block;
}
/*CSS for main menu labels within menu class*/
.menu input {
display: none;
opacity: .3;
margin-right: -.7em;
margin-left: 0em;
overflow: visible;
}
.menu a {
text-decoration: none;
color: #FFFFFF;
}
.menu label span {
z-index: 1000;
font-size: 12px;
line-height: 9px;
padding: 6px 1em 12px 1em;
display: block;
margin-top: -1px;
background-image: url(../images/glossyback.gif) repeat-x bottom left;
}
.menu label span a:hover {
background-image: black url(../images/glossyback2.gif);
}
.menu input:checked + label {
background-color: #AFCEEE;
border-color: #6696CB;
z-index: 1000;
}
div.menu input + label {
z-index: 1000;
padding: 0;
border-color: #ccc;
border-width: 0 1px;
height: 19px;
margin: 0 -.23em;
}
/*CSS for submenu container */
.menu input + label + div {
position: absolute;
border: 1px solid #808080;
right: 0;
background: #F0F6FC;
text-align: center;
width: 100%;
margin: 0 auto;
}
.menu input + label + div > div {
z-index: 1000;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 1px solid #ABABAB;
padding: 16px;
padding-top: 5px;
}
/*CSS for sub menu items*/
.sub-menu {
font-size: 14px;
display: inline-block;
}
.sub-menu a {
text-decoration: none;
color: #EEEEEE;
}
.sub-menu ul {
list-style-type: none;
}
.sub-menu li {
width: 175px;
color: #F0F0F0;
background-color: #9CB9D7;
display: inline-block;
}
.sub-menu li:hover {
color: #FFFFFF;
text-decoration: none;
background-color: #3385D6;
}
/*CSS for sub-menu second level */
.sub-menu input[type=radio] {
display: none;
}
.sub-menu input[type=radio]:checked ~ .remove-check {
display: none;
}
.sub-menu input[type=radio]:checked ~ #second-level {
display: block;
}
#second-level {
display: none;
}
/* The styling of items, ect...*/
.sub-menu input[type=text] {
width: 225px;
padding: 12px 14px;
}
.sub-menu div {
border: 1px solid #808080;
right: 0;
background: #F0F6FC;
text-align: center;
width: 100%;
margin: 0 auto;
}
.sub-menu div div {
top: 90%;
z-index: 1000;
position: absolute;
border: 1px solid #ABABAB;
padding: 16px;
padding-top: 5px;
}
.sub-menu .second-level-items {
width: 175px;
color: #F0F0F0;
background-color: #9CB9D7;
display: inline-block;
}
<div class="menu">
<input type="radio" name="UItab" id="tabf">
<label for="tabf"><span>Styles</span>
</label>
<div>
<div>
<ul class="sub-menu">
<a href="">
<li id="linkj">First Link</li>
</a>
<label for="reveal-email">
<li>Tab in submenu</li>
</label>
<input type="radio" id="reveal-email">
<div id="second-level">
<div>
<a href="">
<li>Links2.0</li>
</a>
</div>
</div>
<label for="reveal-email">
<li>Tab in submenu</li>
</label>
<input type="radio" id="reveal-email">
<div id="second-level">
<div>
<a class="second-level-items" href="">
<li>Links2.0</li>
</a>
</div>
</div>
<a href="">
<li id="linkj">First Link</li>
</a>
</div>
</div>
</div>
I am trying to move an LI Nav bar to the top right of a page, however when I position: absolute; and top: 0; on my <li> I get my list which is also display: inline; all stacked on top of each other. They go to the part of the screen I want because I'm also float: right; but they won't stay in a line.
Any ideas?
HTML(html and doctype and link tags left out, they're there):
<div id="search">Google Search</div>
<div id="lucky">I'm feeling lucky</div>
<form>
<input id="search_box" type="text" name="">
</form>
<ul>
<li class='nav'>+You</li>
<li class='nav'>Gmail</li>
<li class='nav'>Images</li>
</ul>
CSS:
#search {
font-family: Arial;
font-size: 10;
font-weight: bold;
border: 1px solid black;
width: 7.2em;
white-space: nowrap;
padding-left: 4px;
padding-top: 3px;
padding-right: 4px;
padding-bottom: 4px;
margin: 240px 14px 100px 225px;
display: inline-block; }
#lucky {
font-family: Arial;
font-size: 10;
font-weight: bold;
padding-left: 4px;
padding-top: 3px;
padding-right: 4px;
padding-bottom: 4px;
border: 1px solid black;
display: inline-block; }
#search_box {
width: 600px;
position: absolute;
left: 65px;
top: 212px; }
ul {
list-style-type: none;
margin: 0;
padding: 0; }
.nav {
display: inline-block;
float: left;
padding: 20px;
position: absolute; }
The li's are stacked on top of each other because you are absolute positioning them to the same place. You want to make the ul absolute positioned instead. Include the code below in your css and for good measure you should also tell include something that it is positioned relative to.
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
top: 0;
right: 0;
}
.nav {
display: inline-block;
/* float: left;*/
padding: 20px;
/*position: absolute;*/ }
body{position: relative;}
Try this http://jsfiddle.net/csdtesting/oe55maf0/2/
Added #header :
#header{
float:right;
}
and removed position:absolute; from .nav class .Also added #content :
#content{
position:absolute;
}
to contain the form .
Now the structure is clear.
Hope this helps!
I have the following menu, the <a>'s are not clickable, i believe it is a z-index problem but haven't been able to fix it. Also does the html make sense, trying to make a circle with a connected rectangle on the right. Then when it drops down it will be fully connected and filled in. I am using bootstrap 2.3.2.
jsfiddle link
html
<div class="row-fluid">
<div class="span2"></div>
<div class="span7 center"></div>
<div class="span3">
<div class="rightMenu visible-desktop">
<div class="scoreBadge">--</div>
<div class="userBadge"> username ▼
</div>
<ul>
<li> settings
</li>
<li> log out
</li>
</ul>
</div>
</div>
</div>
css
.rightMenu{
position: absolute;
right: 0;
top: 8px;
margin-top: 10px;
min-width: 65px;
}
.rightMenu ul {
display: none;
list-style: none;
text-align: left;
position: relative;
left: -10px;
top: -30px;
background-color: #4b86a1;
color: white;
z-index: -2;
margin-left: 10px;
padding: 20px 10px 10px 10px;
}
.rightMenu ul li {
}
.rightMenu:hover ul {
display: block;
}
.rightMenu ul a {
color: white;
}
.scoreBadge {
display: inline-block;
background: white;
color: #4B86A1;
height: 30px;
width: 30px;
border: 2px solid #fcdf05;
border-radius: 50%;
text-align: center;
line-height: 30px;
vertical-align: middle;
font-size: 18px;
}
.userBadge {
display: inline-block;
background-color: #4b86a1;
vertical-align: middle;
padding-left: 10px;
line-height: 30px;
min-width: 49px;
position: relative;
left: -10px;
-webkit-border-top-right-radius: 8px;
-webkit-border-bottom-right-radius: 8px;
-moz-border-radius-topright: 8px;
-moz-border-radius-bottomright: 8px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
text-align: right;
z-index: -1;
}
.userBadge > a {
padding: 0 5px 0 5px;
line-height: 25px;
}
#usrName {
color: white;
font-size: 10pt;
font-weight: normal;
text-transform: uppercase;
}
In your css you have
.rightMenu ul {
display: none;
list-style: none;
text-align: left;
position: relative;
left: -10px;
top: -18px;
background-color: #4b86a1;
color: white;
z-index: -2; /* this is the problem */
margin-left: 10px;
padding: 20px 10px 10px 10px;
}
Just remove the - from z-index: -2; and it'll work. Also, without z-index: 2; it seems working fine, so why not just remove the z-index property ? An example here (with z-index:2) and another example (without z-index property).
I solved for you the problem see the change the z-index to 2 in the Class .rightMenu ul