CSS Dropdown Same Width - css

function myFunction() {
var x = document.getElementById("primaryNavigation");
if (x.className === "show") {
x.className = "hide";
} else {
x.className = "show";
}
}
/* NAVIGATION - MENU */
nav {
background-color: #0000ff;
}
nav button {
display: block;
position: absolute;
top: .5rem;
right: 2%;
}
nav ul {
padding: 0;
margin: 0;
display: flex;
flex-wrap: wrap;
}
nav ul.show {
display: flex;
}
nav ul.hide {
display: none;
}
nav ul li {
width: 100%;
list-style: none;
}
nav ul li a {
display: block;
color: white;
text-decoration: none;
font-size: 1.1rem;
font-weight: 450;
padding: 1rem 0;
text-align: center;
border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}
nav ul li.active a {
background-color: #f52c39;
}
nav ul li a:hover {
background-color: #4c9bff;
}
.clearfix:after,
.row:after {
content: "";
display: table;
clear: both;
}
/* DROP DOWN MENU */
ul ul {
position: absolute;
display: none;
background-color: #0000ff;
}
li:hover ul {
display: block;
background-color: #0000ff;
}
nav ul ul li a:hover {
background-color: #4c9bff;
}
<nav class="clearfix">
<button onclick="myFunction()">☰</button>
<ul class="hide" id="primaryNavigation">
<li class="active">Home</li>
<li>Adventures
<ul>
<li>White Water Rafting</li>
<li>Hiking & Zipline</li>
<li>Camping</li>
</ul>
</li>
<li>Guides</li>
<li>Booking</li>
<li>Contact</li>
</ul>
</nav>
I want my dropdown menu to be the same width as the parent. (FYI: It is responsive and changes into a hamburger). I realize this is probably so easy for someone (but I'm just learning). I've tried all the solutions I've seen listed here and other place to no avail. THANK YOU for any help.

Related

My navbar (hamburger) menu disaapear while :hover

im trying to make some navbar in hamburger style, and while I :hover that hamburger the ul (the menu actually) open, but while trying to choose one of my li it disappear . I would like to get some help im new with css/html. thank you very much <3 peace
* {
padding: 0;
margin: 0;
box-sizing: border-box;
list-style: none;
}
nav {
height: 80px;
width: 100%;
position: relative;
}
nav .logo {
line-height: 2;
margin-left: 50px;
}
nav img {
width: 2em;
position: absolute;
right: 2em;
top: 1.5em;
cursor: pointer;
}
nav ul {
position: absolute;
padding: 20px;
width: 100%;
top: 0;
display: none;
}
nav ul li {
margin-top: 30px;
text-align: center;
line-height: 5;
}
nav ul li a {
font-size: 1.3em;
}
nav ul li a:hover {
border-bottom: 2px solid black;
}
img:hover+.openw {
display: block;
}
<nav class="nav">
<label for="" class="logo">DesignX</label>
<img src="240.png" alt="">
<ul class="openw">
<li>a</li>
<li>a</li>
<li>a</li>
<li>a</li>
<li>a</li>
</ul>
</nav>
</body>

display menu bar on displayed file content in jsp

I am displaying PDF file in a jsp page. I want to display menu bar at the top on the same page. I have written code to display menu bar as well as to display PDF file. But the menu bar is not visible on the page. Menu bar is covered up the PDF file. How to make menu bar visible? Please help. Thank you.
<style>
body
{
background:url('C:\\Users\\workspace3\\elearning\\openbook.jpg') no-repeat center center fixed;
background-size: cover;
margin: 0;
padding: 0;
}
div ul ul {
display: none;
}
div ul li:hover > ul {
display: block;
}
div ul {
background: #7c0c0c;
font-size: 16px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
text-shadow: 3px 2px 3px #333333;
list-style: none;
position: relative;
}
div ul:after {
content: ""; clear: both; display: block;
}
div ul li {
float: left;
}
div ul li:hover {
background: #ebd3d3;
}
div ul li:hover a {
color: #4f9dd5;
}
div ul li a {
display: block; padding: 25px 30px;
color:#ebd3d3; text-decoration: none;
}
div ul ul {
background:#7c0c0c; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
div ul ul li {
float: none;
border-top: 1px solid #4f9dd5;
border-bottom: 1px solid #4f9dd5;
position: relative;
}
div ul ul li a {
padding: 15px 40px;
color: #ebd3d3;
}
</style>
<body>
<div>
<ul>
<li><span>Content</span>
<ul>
<li><span>Text Content</span></li>
<li><span>Video</span></li>
<li><span>PPT</span></li>
</ul></li>
<li><span>Quiz</span></li>
<li><span>Assignment</span>
<ul>
<li><span>Assignment Questions</span></li>
<li><span>Upload Assignment</span></li>
</ul></li>
<li> <span>Forum</span></li>
<li> <span>Logout</span></li>
</font></ul></div>
<%
File temp=new File("C:\\Users\\Desktop\\content\\o.pdf");
response.setHeader("Content-Disposition", "attachement; filename=\""+temp+"\"");
InputStream isStream = null;
ServletOutputStream sosStream = null;
try
{
response.flushBuffer();
isStream =new FileInputStream(temp);
sosStream =response.getOutputStream();
int ibit = 250;
while ((ibit) >= 0)
{
ibit = isStream.read();
sosStream.write(ibit)
}
}catch (IOException e)
{
out.println(e);
}
sosStream.flush();
sosStream.close();
isStream.close();%>
</body>
</html>

css anchor fill entire list element

I have this menu that I have been working on for a while. I am using the CSS table displays to accomplish it. When the text inside of my links take up two lines, the ones that are only one line will not fill the parent li on hover. Is there any way I am missing that can accomplish this?
http://jsfiddle.net/g7jmh567/
css
.menu {
background-color: #687c9e;
display: table;
}
.menu-list {
display: table-row;
}
.menu-list > li {
display: table-cell;
height: 100%;
overflow: hidden;
line-height: 1.125rem;
overflow: auto;
}
.menu-list > li > a {
display: block;
color: #fff;
text-decoration: none;
padding: 1.25rem 1.25rem 1.25rem 0;
box-sizing: border-box;
height: 100%;
min-height: 2.25rem;
}
.menu-list > li > a:hover {
background-color: #7889a8;
}
.dropdown-list {
display: none;
}
.hidden {
display: none;
}
html
<nav class="content menu">
<ul class="menu-list">
<li>Home</li>
<li>A really long</li>
<li>Some really long word</li>
<li>Special Events</li>
<li>Newsletter</li>
<li>Photo Gallery</li>
</ul>
</nav>
Simply remove the padding from your li, and add it to your menu-list, check out the link below;
Nav
the reason why it didn't fill the entire li 'coz you're just filling the anchor
hover the li instead of the anchor
.menu-list > li:hover {
background-color: #7889a8;
}
JSFIDDLE DEMO
See This link: this may help you: https://jsfiddle.net/guruWork/8fwo0r06/2/
<nav class="content menu">
<ul class="menu-list">
<li><span>Home</span></li>
<li><span>A really long</span></li>
<li><span>Some really long word</span></li>
<li><span>Special Events</span></li>
<li><span>Newsletter</span></li>
<li><span>Photo Gallery</span></li>
</ul>
</nav>
And CSS
.menu {
background-color: #687c9e;
}
.menu-list {
display: table;padding:0; margin:0;width:100%;
}
.menu-list > li {
display: table-cell;
height: 100%;
overflow: hidden; vertical-align: top;
overflow: auto;
}
.menu-list > li > a {
display: table;
color: #fff;
text-decoration: none;
padding: 0;
box-sizing: border-box;
height: 100%;
min-height:53px; text-align:center;
}
.menu-list > li > a span{display: table-cell;padding: 5% .5rem;vertical-align: middle;}
.menu-list > li > a:hover {
background-color: #7889a8;
}
.dropdown-list {
display: none;
}
.hidden {
display: none;
}

a:first-child over writing all of the <a> tags within parent <div>?

<header>
<div class="container">
Research Concepts | Satellite Antenna Controllers
<nav class="main-navigation">
<ul>
<li>Home</li>
<li>Products/Support</li>
<li>About Us</li>
<li>Contact Us</li>
<li>News/Events</li>
<li>Search</li>
</ul>
<a href="#" class="mobile-navigation">
<div class="icon-bar"></div>
<div class="icon-bar"></div>
<div class="icon-bar"></div>
</a>
</nav>
</div>
</header>
nav {
float: right;
ul {
margin: 0;
padding: 0;
&:after {
content: "";
display: block;
clear: both;
}
li {
float: left;
a {
margin-left: 2.813em;
text-decoration: none;
line-height: 36px;
color: $black;
&:hover {
color: $maroon;
}
&:first-child {
margin-left: 0;
}
}
}
}
}
I can't see what I am doing wrong here. I've used the :first-child pseudo element before and had no problems with it overriding all the other elements like it is currently doing.
Here is the HTML that a couple of you requested. I hope that this helps.
As I already stated, all of your a elements are the first child of their parent element. You need to select the first li element instead:
nav {
float: right;
ul {
margin: 0;
padding: 0;
&:after {
content: "";
display: block;
clear: both;
}
li {
float: left;
a {
margin-left: 2.813em;
text-decoration: none;
line-height: 36px;
color: $black;
&:hover {
color: $maroon;
}
&:first-child {
color: green;
}
}
&:first-child a {
margin-left: 0;
color: pink;
}
}
}
}
http://sassmeister.com/gist/37042db81ea407c76098
However, it would be more efficient to place the margin on the li instead.
nav {
float: right;
ul {
margin: 0;
padding: 0;
&:after {
content: "";
display: block;
clear: both;
}
li {
float: left;
a {
text-decoration: none;
line-height: 36px;
color: $black;
&:hover {
color: $maroon;
}
}
~ li {
margin-left: 2.813em;
color: pink;
}
}
}
}
http://sassmeister.com/gist/2138cffab2129c5eded1

Responsive css menu with multiple levels

am having a problem getting multiple levels working on a responsive css menu, the base of the menu i have followed this tutorial on tuts.com
I need more than 2 sub levels on this menu for my site, though when i add the extra 's to the html, the extra level is not working as it should, am sure its possible to add an extra level to the original menu, but i cant figure out what extra css i need, i had tried adding extra css code for li li li li but thats not working for me.
the extra level displays wwith the 2nd sublevel, where it should only display for the hover of the 2nd sub-menu.
i have created a jsfiddle (my first one) here: http://jsfiddle.net/DizzyHigh/Bpubu/4/
html:
<div id="left_container"></div>
<div class="container">
<a class="toggleMenu" href="#">Menu</a>
<ul class="nav">
<li class="test"> HOME
</li>
<li> LOCATIONS
<ul class="nav">
<li> Boroughs
<ul class="nav">
<li> Enfield
<ul>
<li>E-Locations
</li>
<li>E-Unit Bases
</li>
<li>E-Parking
</li>
</ul>
</li>
<li> Barnet
<ul>
<li>B-Locations
</li>
<li>B-Unit Bases
</li>
<li>B-Parking
</li>
</ul>
</li>
</ul>
</li>
<li> Maps
<ul class="nav">
<li> Enfield map
<ul>
<li>ME-Locations
</li>
<li>ME-Unit Bases
</li>
<li>ME-Parking
</li>
</ul>
</li>
<li> Barnet Map
<ul>
<li>MB-Locations
</li>
<li>MB-Unit Bases
</li>
<li>MB-Parking
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li> CONTACT
</li>
<li> LINKS
</li>
</ul>
</div>
<div id="right_container"> </div>
css:
body, nav, ul, li, a {margin: 0; padding: 0;}
body {font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
a {text-decoration: none;}
.container {
width: 90%;
max-width: 900px;
margin: 10px auto;
}
.toggleMenu {
display: none;
background: #666;
padding: 10px 15px;
color: #fff;
}
.nav {
list-style: none;
*zoom: 1;
background:#175e4c;
}
.nav:before,
.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav ul {
list-style: none;
width: 9em;
}
.nav a {
padding: 10px 15px;
color:#fff;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
border-top: 1px solid #104336;
}
.nav > li > .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: right;
}
.nav > li > a {
display: block;
}
.nav li ul {
position: absolute;
left: -9999px;
}
.nav > li.hover > ul {
left: 0;
}
.nav li li.hover ul {
left: 100%;
top: 0;
}
.nav li li a {
display: block;
background: #1d7a62;
position: relative;
z-index:100;
border-top: 1px solid #175e4c;
}
.nav li li li a {
background:#249578;
z-index:200;
border-top: 1px solid #1d7a62;
}
#media screen and (max-width: 768px) {
.active {
display: block;
}
.nav > li {
float: none;
}
.nav > li > .parent {
background-position: 95% 50%;
}
.nav li li .parent {
background-image: url("images/downArrow.png");
background-repeat: no-repeat;
background-position: 95% 50%;
}
.nav ul {
display: block;
width: 100%;
}
.nav > li.hover > ul , .nav li li.hover ul {
position: static;
}
}
JS:
$(document).ready(function() {
var ww = document.body.clientWidth;
$(".nav li a").each(function() {
if ($(this).next().length > 0) {
$(this).addClass("parent");
};
})
$(".toggleMenu").click(function(e) {
e.preventDefault();
$(this).toggleClass("active");
$(".nav").toggle();
});
adjustMenu();
var adjustMenu = function() {
if (ww < 768) {
$(".toggleMenu").css("display", "inline-block");
if (!$(".toggleMenu").hasClass("active")) {
$(".nav").hide();
} else {
$(".nav").show();
}
$(".nav li").unbind('mouseenter mouseleave');
$(".nav li a.parent").unbind('click').bind('click', function(e) {
// must be attached to anchor element to prevent bubbling
e.preventDefault();
$(this).parent("li").toggleClass("hover");
});
}
else if (ww >= 768) {
$(".toggleMenu").css("display", "none");
$(".nav").show();
$(".nav li").removeClass("hover");
$(".nav li a").unbind('click');
$(".nav li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
// must be attached to li so that mouseleave is not triggered when hover over submenu
$(this).toggleClass('hover');
});
}
}
$(window).bind('resize orientationchange', function() {
ww = document.body.clientWidth;
adjustMenu();
});
})
can any css gurus point me in the right direction?
Bryn try the follwing code:
I use 'NormalMenu' class for css hover event on normal menu
Java Script
var adjustMenu = function() {
if (ww < 768) {
$(".toggleMenu").css("display", "inline-block");
if (!$(".toggleMenu").hasClass("active")) {
$(".nav").hide();
} else {
$(".nav").show();
}
$('.nav').removeClass('NormalMenu').find('ul').hide();
$(".nav li a").unbind('click').bind('click', function(e) {
// must be attached to anchor element to prevent bubbling
e.preventDefault();
var _sub = $(this).siblings('ul')
if($(_sub).is(':visible')){
$(_sub).hide();
$(_sub).find('ul').hide();
}else{
$(_sub).show();
}
});
}
else if (ww >= 768) {
$(".toggleMenu").css("display", "none");
$(".nav li a").unbind('click');
$(".nav").show().addClass('NormalMenu').find('ul').removeAttr('style');
}
}
CSS
body, nav, ul, li, a {margin: 0; padding: 0;}
body {font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
a {text-decoration: none;}
.container {
width: 90%;
max-width: 900px;
margin: 10px auto;
}
.toggleMenu {
display: none;
background: #666;
padding: 10px 15px;
color: #fff;
}
.nav {
list-style: none;
*zoom: 1;
background:#175e4c;
}
.nav:before,
.nav:after {
content: " ";
display: table;
}
.nav:after {
clear: both;
}
.nav ul {
list-style: none;
width: 9em;
}
.nav a {
padding: 10px 15px;
color:#fff;
}
.nav li {
position: relative;
}
.nav > li {
float: left;
border-top: 1px solid #104336;
}
.nav > li > .parent {
/* background-image: url("images/downArrow.png");*/
background-repeat: no-repeat;
background-position: right;
}
ul.NormalMenu ul{
width: 100%;
display:none;
position: absolute;
}
ul.NormalMenu li{
line-height:40px;
}
ul.NormalMenu li:hover > ul{
width: 100%;
display:block;
left:0;
}
ul.nav ul li{
background: #1d7a62;
}
ul.NormalMenu li li:hover> ul{
width: 100%;
display:block;
top:0;
left:100%;
}
ul.nav ul li li{
background: #1d7a00;
}
#media screen and (max-width: 768px) {
.active {
display: block;
}
.nav > li {
float: none;
}
.nav > li > .parent {
background-position: 95% 50%;
}
.nav li li .parent {
/*background-image: url("images/downArrow.png");*/
background-repeat: no-repeat;
background-position: 95% 50%;
}
ul.nav ul{
margin-left:5%;
width: 95%;
}
ul.nav li{
line-height:30px;
}
}
See Demo: http://jsfiddle.net/ducwidget/Bpubu/21/
you can check this out ...I have made this menu in Plain html5 and css https://github.com/Saransh27/Dashboard. You can always extend it to you needs and let me know if you have any questions.

Resources