I'm trying to do a nav menu in a particular style, It needs to be a bunch of square buttons/list items, then when you hover over an item, the background behind the item changes color, a decent height above the item and behind the drop down list, as seen in the image below.
My issue is that Im curious if I'm doing it the most efficient way and also when I hover over the initial item, it is working but then you go to one of the drop down items and the main/parent item disappears into the background.
Code:
body {
background-color: #00aeef;
}
.navBG {
background-color: #fff;
}
nav {
padding-top: 100px;
padding-left: 100px;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
text-align: center;
}
li {
display: inline-block;
display: inline;
float: left;
background-color: #00aeef;
border: solid 4px #fff;
width: 150px;
}
li a {
display: block;
padding: 10px 5px;
color: #fff;
text-align: center;
}
li a:hover {
color: #fff;
border: solid 4px #00ee98;
border-top: solid 100px #00ee98;
margin-top: -100px;
}
.droplinks {
position: absolute;
background-color: #00aeef;
min-width: 150px;
display: none;
margin-left: -2px;
}
.droplinks a {
padding: 10px;
display: block;
border: solid 2px #00ee98;
}
.droplinks a:hover {
color: #fff;
}
.dropbutton:hover .droplinks {
display: block;
}
<div class="container-fluid navBG">
<nav>
<ul>
<li>Home
</li>
<li class="dropbutton">Products
<div class="droplinks">
Widgets
Cogs
Gears
</div>
</li>
<li class="dropbutton">
Services
<div class="droplinks">
Handshakes
Winks
Smiles
</div>
</li>
<li>Shop
</li>
<li>Contact
</li>
</ul>
</nav>
</div>
Then on hovering a menu item, it changes to this;
However, when I then go to a sub menu item the top level item messes up as in the example above. Would could be done to resolve this?
take a look at this fiddle,
and here is how you can properly show the sub menu on hovering on menu item:
li:hover .droplinks{
display: block;
}
body {
background-color: #00aeef;
}
.navBG {
background-color: #fff;
}
nav {
text-align:center;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
text-align: center;
vertical-align: middle;
}
li {
display: inline-block;
display: inline;
float: left;
background-color: #00aeef;
width: 150px;
position: relative;
}
li a {
display: block;
padding: 10px 5px;
color: #fff;
text-align: center;
border-width: 30px 5px;
border-color: #fff;
border-style: solid;
}
li:hover a {
color: #fff;
border-color:#00ee98;
}
.droplinks {
background-color: #00aeef;
top: 100%;
display: none;
margin-left: 0;
min-width: 150px;
position: absolute;
margin-top: -15px;
}
.droplinks a {
padding: 10px;
display: block;
border-width: 2px 4px;
border-style: solid;
border-color:#00ee98;
}
.droplinks a:hover {
color: #fff;
}
.dropbutton:hover .droplinks {
display: block;
}
<div class="container-fluid navBG">
<nav>
<ul>
<li>Home
</li>
<li class="dropbutton">Products
<div class="droplinks">
Widgets
Cogs
Gears
</div>
</li>
<li class="dropbutton">
Services
<div class="droplinks">
Handshakes
Winks
Smiles
</div>
</li>
<li>Shop
</li>
<li>Contact
</li>
</ul>
</nav>
</div>
Related
I am building a navbar with hover effects over the nav items and an inline button, however, the text in my button is not lining up with the other nav items. In addition I am having trouble figuring out how to get the red hover background to space itself evenly above and below the text of my nav items. What am I doing wrong?
<nav class="navbar">
<a id="header" href="#">Adopt <span class="me">Me</span> </a>
<ul >
<div id="rightitems">
<li>About Us</li>
<li>What we do</li>
<li>Benefits</li>
<li>Our Buddies</li>
<button class="btn">Contact Us</button>
</div>
</div>
</ul>
</nav>
.btn{
display: inline;
width: auto;
text-decoration: none;
margin: 0;
}
.btn a{
margin: 0;
}
body{
background-image: url(bulldog.jpg)
}
a{
text-decoration: none;
}
nav ul{
list-style-type: none;
margin: 0;
padding:0;
text-decoration: none;
display: flex;
position: relative;
}
nav a{
margin-right: 10px;
margin-left: 10px;
padding-top: 10px;
}
.navbar{
display: flex;
justify-content: space-between;
width: 100%;
}
#rightitems{
display: flex;
}
li{
width: auto;
}
li:hover{
width: auto;
}
li:hover {
background-color: #FF4850;
color: white;
border-radius: 10px;
}
nav li:hover{
color: white;
}
nav a:hover{
color: white;
}
Looks like some duplicate selectors and a bit of redundant styling. I've made some adjustments check out this fiddle:
nav a {
margin: 10px;
text-decoration: none;
}
nav a:not('me'):hover{
color: white;
}
.navbar #rightitems li{
padding: 10px 5px;
}
https://jsfiddle.net/cf2vd64y/2/
I'm trying to make a drop down component (in Reactjs), and I am having trouble on how to make it not pop up outside the browser width.
I have tried to set right: 0px, it works fine when the dropdown is at the rightmost of the panel, but if the dropdown is not then it gets messed up.
here is the codepen for the sample.
here is a sample css
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
here is a sample html
<li class="dropdown">
Dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
, you can notice that there is a scrollbar there.
What I want to achieve is that I can right align the drop down content, relative to the drop down header.
Thanks
You just need to adjust right side dropdown contents. One possible way is as follow
<div class="dropdown-content d2">
Link 1
Link 2
Link 3
</div>
.d2 {
right:0;
}
Ping me if you have any query.
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
float: right;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
div.dropbtn {
display: inline-block;
color: black;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
.d2 {
right:0;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<ul>
<li>Home</li>
<li>News</li>
<li class="dropdown">
Dropdown
<div class="dropdown-content d2">
Link 1
Link 2
Link 3
</div>
</li>
</ul>
<h3>Dropdown Menu inside a Navigation Bar</h3>
<p>Hover over the "Dropdown" link to see the dropdown menu.</p>
<div class="dropdown">
some other dropdown
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
</body>
</html>
This is driving me insane, and I just can't figure out the cause. I have a JSP application that is connected to bootstrap. First of all, I am by no means an expert in CSS, and am green in that area. My issue is that inline-block just will not work. My bootstrap is used for the collapse plugin that allows me to use a menu button instead of the regular menu in smartphones.
When I use a desktop-size, the menu items are displayed in block format (vertical), even though I have used display: inline-block. Here's my code, and if anyone has an idea why inline-block is not working please let me know.
The html:
<ul id="menu-items" class="navbar-collapse collapse menubar-items">
<li>
<a class="menuItems" href="home.jsp">Home</a>
</li>
<li>
<a class="menuItems" href="business.jsp">Business</a>
</li>
<li>
<a class="menuItems" href="new-form.jsp">New Order</a>
</li>
<li>
<a class="menuItems" href="logout.do">Logout</a>
</li>
</ul>
The css:
#menu-items {
min-width: 250px;
background: #CFC3F8;
box-shadow: 5px 5px 2px #888888;
padding: 0;
float: right;
}
#menu-items li {
height: 100%;
width: 100%;
margin-right: 10px;
text-decoration: none;
vertical-align: middle;
text-align: center;
line-height: 60px;
font-size: 16px;
border-left: solid white 2px;
color: #332419;
//The attempt
display: inline-block;
}
#menu-items li a.menuItems {
height: 100%;
width: 100%;
}
#menu-items li a.menuItems:hover {
color: #332419;
background-color: #f1f1f1;
}
//ensuring that bootstrap doesn't override it
.navbar-collapse li {
display: inline-block;
text-decoration: none;
}
.collapse li {
display: inline-block;
text-decoration: none;
}
ul li {
display: inline-block;
text-decoration: none;
}
I have created a small drop down menu.. the issue is I don't want it to be a 200px button link unless it needs to in order to make the text fit. example where it says drop downlink that will be a dynamic link if register has 7 letters but drop downlink has 12 I don't want register to be 200px wide.
<ul class="tactical-nav-isolate">
<li>Register</li>
<li>Login</li>
<li class="account-dropdown">
Dropdown Link<span class="glyphicon glyphicon-menu-down account-dropdown-icon"></span>
<ul class="account-dropdown-nav">
<li>My Profile</li>
<li>My Account</li>
<li>Logout</li>
</ul>
</li>
</ul>
* {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
ul {
list-style: none;
padding: 0;
margin: 0;
}
.tactical-nav-isolate {
text-align: center;
}
.account-dropdown-nav {
background: #000000;
text-align: left;
text-indent: 15px;
}
.tactical-nav-isolate {
float: right;
margin-top: 0px;
border-left: solid 1px #1e2a36;
}
.tactical-nav-isolate > li {
float: left;
border-left: solid 1px #1e2a36;
}
.tactical-nav-isolate li:first-child {
border-left: none;
}
.tactical-nav-isolate a {
color: #fff;
display: block;
line-height: 50px;
width: 200px;
text-decoration: none;
}
.account-dropdown {
position: relative;
}
.account-dropdown:after {
font-size: .5em;
display: block;
position: absolute;
top: 38%;
right: 12%;
}
.account-dropdown-icon {
text-indent: 5px;
}
.account-dropdown-nav {
position: absolute;
display: none;
}
.account-dropdown-nav li {
border-bottom: 1px solid rgba(255,255,255,.2);
}
.account-dropdown:hover > .account-dropdown-nav {
display: block;
background-image: url(../../media/opacityBG.png);
}
I am not one hundred percent sure what you are asking for, but if your question pertains to having a non-uniform width that fits your <a> tags then all you would need to do is uncomment the following:
.tactical-nav-isolate a {
//display: block;
}
look at this to see the difference between block and inline elements:
Bit new at CSS and been looking around at various sites and bits of code trying to get a centered drop down menu which I managed to get :).
However as soon as I added some images to make up the heading the menu shifted off to the left and I have not been able to budge it ever since, any help? Code is below.
<style type="text/css">
<!--
body {
background-image: url();
background-color: #0099FF;
}
.style1 {color: #FFCC00}
.style2 {color: #FF9900}
.style3 {
color: #FFCC00;
font-weight: bold;
font-size: 12px;
}
.style4 {
color: #000099;
font-weight: bold;
}
.style5 {color: #000099; font-weight: bold; font-size: 12px; }
.style6 {color: #000099}
* { padding: 0; margin: 0; }
body { padding: 5px; }
ul { list-style: none; margin: auto}
ul li { float: left; padding-right: 0px; position: relative; }
ul a { display: table-cell; vertical-align: middle; width: 100px; height: 50px; text-align: center; background-color: #0099EE; color: #000000; text-decoration: none; border: 1px solid #000000;}
ul a:hover { background-color: #0066FF; }
li > ul { display: none; position: absolute; left: 0; top: 100%; }
li:hover > ul { display: inline; }
li > ul li { padding: 0; padding-top: 0px; }
#menu-outer {
height: 84px;
background: url(images/bar-bg.jpg) repeat-x;
}
.table {
display: table;
margin: 0 auto;
}
ul#horizontal-list {
min-width: 696px;
list-style: none;
padding-top: 20px;
}
ul#horizontal-list li {
display:inline
}
-->
</style></head>
<body>
<div id="menu-outer"></div>
<div class="table"></div>
<div align="center"><img src="logo_with_words_3.jpg" width="172" height="145"><img src="heading.gif" width="557" height="69"><img src="logo_with_words_3.jpg" width="172" height="145">
</div>
<ul id="horizontal-list">
<li>
Home
</li>
<li>About Us
<ul>
<li>History</li>
<li>Guest Comments</li>
</ul>
<li>News</li>
<li>Accommodation
<ul>
<li>Rooms</li>
<li>Bedrooms</li>
<li>St Joseph's Annexe</li>
</ul>
<li>Visiting St Katharine's
<ul>
<li>Retreats</li>
<li>B&B</li>
<li>Events</li>
<li>Conferences</li>
<li>Catering</li>
</ul>
<li>Contact Us
<ul>
<li>Find Us</li>
</ul>
<li>Walled Garden</li>
<li>Sue Ryder Legacy
<ul>
<li>Sue Ryder</li>
<li>Prayer Fellowship</li>
<li>LRWMT</li>
</ul>
</ul>
</body>
You aren't really using a table, but you can add something like this: #horizontal-list {margin: auto; width: 850px;}
JS Fiddle with your code