CSS Drop Down Selection Issue - css

The problem I am having is that once I have selected a menu option, there is no drop down for that menu option that is currently selected. I can't seem to find the right answer nor able to Google the right question to get an answer.
The whole drop down works perfectly fine otherwise, except if I select a drop down menu item like "Drivers" then if I re-highlight "Drivers" once it's already selected, there is now no drop down there. I would have to select say.. "Home" first then the unselected "Drivers" option now has the drop down menu appear.
I hope I have made what I'm asking clear enough, now here is my code.
CSS:
/***** Begin Menu CSS *****/
ul {
width: 100%;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn{
display: inline-block;
font-size: 15px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-right: 1px solid #bbb;
}
/* Color of the main menu text when hovering */
li a:hover {
background-color: red;
}
/* Once the mouse has moved off the main menu button and is now highlighting a sub menu button, this defines what that main menu button color is */
.dropdown:hover{
background-color: red;
}
/* Color of main menu button when not selected */
.dropbtn {
background-color: 333;
}
li .dropdown {
position:relative;
display: inline-block;
}
li:last-child {
border-right: none;
}
.dropdown-content{
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a{
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
background-color: #f6f6f6; /* Sets background color of the drop down menu (not selected) */
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ccc}
.dropdown:hover .dropdown-content{
display: block;
}
/* I have no idea what this does as it appears nothing...
li a:hover:not(.active) {
background-color: #blue;
} */
.active {
background-color: #990000;
}
.active dropdown-content{
display: none;
position: absolute;
min-width: 160px;
box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.active dropdown-content a{
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/***** End Menu CSS *****/
And here is my HTML:
//PHP Function
function Active($menuselection, $page){
if($page == "$menuselection"){
echo "active";
}else{
echo "dropdown";
}
}
(HTML)
<table width="100%">
<tr>
<td>
<ul>
<li>
<a class="<?=Active("menu.php", $webpage); ?>" href="menu.php">Home</a>
</li>
<li class="<?=Active("tms.php", $webpage); ?>">
Territory Manager
<div class="dropdown-content">
Add TM
Search TM
</div>
</li>
<li class="<?=Active("sales.php", $webpage); ?>">
Sales
<div class="dropdown-content">
Add Sales Person
Search Sales
</div>
</li>
<li class="<?=Active("drivers.php", $webpage); ?>">
Drivers
<div class="dropdown-content">
Add Driver
Search Drivers
</div>
</li>
<li class="<?=Active("passengers.php", $webpage); ?>">
Passengers
<div class="dropdown-content">
Add Passenger
Search Passengers
</div>
</li>
</ul>
</td>
</tr>
</table>
Any help would be greatly appreciated.
Here is the HTML rendered when I select "Drivers" (no PHP)
<table width="100%">
<tr>
<td>
<ul>
<li>
<a class="dropdown" href="menu.php">Home</a>
</li>
<li class="dropdown">
Territory Manager
<div class="dropdown-content">
Add TM
Search TM
</div>
</li>
<li class="dropdown">
Sales
<div class="dropdown-content">
Add Sales Person
Search Sales
</div>
</li>
<li class="active">
Drivers
<div class="dropdown-content">
Add Driver
Search Drivers
</div>
</li>
<li class="dropdown">
Riderz
<div class="dropdown-content">
Add Passenger
Search Passengers
</div>
</li>
</ul>
</td>
</tr>
</table>

Try adding this to your code:
.active:hover .dropdown-content{
display: block;
}

Related

Clicking on the background of collapsible header collapses the content but main icon not changed

I am currently using collapsible contents from Bootstrap. So this is the actual visualization when I clicked on the background of collapsible-header.
1st part ( not yet collapsed)
2nd part (After collapsed)
As you noticed, the icon wasn't changed when I clicked on the collapsible-header background. The lists collapsed but I want the icon to be changed along by pressing the background afterwards.
However, there is no problem if i clicked on the icon itself and i will have the icon changed to plus sign and the contents will be collapsed as well.
But I would like to have my collapsible-header background to be responsive along with the icon as well. Please do help. Here's the sample code but I cant have proper visualization and I would like to apologize for the inconvenience.
<div class="col-md-12" style="margin:20px 0 0 0">
<ul class="collapsible collapsible-landing" data-collapsible="accordion">
<li>
<div class="collapsible-header">
<span class="pull-left"><h3>Categories</h3></span>
<span class="pull-right">
<i class="zmdi zmdi-plus"></i>
<i class="zmdi zmdi-minus"></i>
</span>
</div>
<div class="collapsible-body">
<ul class="collapsible-list">
<li> Sample 1 </li>
<li> Sample 2 </li>
<li> Sample 3 </li>
<li> Sample 4 </li>
<li> Sample 5 </li>
<li> Sample 6 </li>
<li> Sample 7 </li>
<li> Sample 8 </li>
<li class="clearfix"></li>
</ul>
</div>
</li>
</ul>
</div>/
Heres the css part
.catehide2, .cateshow2 {
float: right;
font-size: 20px;
color: #000000;
text-align: center;
padding:0;
}
.catehide2:hover, .cateshow2:hover {
color: #9e9e9e;
text-decoration: none;
opacity: 1;
}
.categorybox1 ul{
list-style-type:none;
margin:0;
padding:0;
display:none;
height:auto;
font-family: 'Roboto', sans-serif;
font-weight:450;
font-size:15px;
color:#424242;
border:0;
}
.categorybox1 ul li{
float: left;
width: 25%;
padding: 0 0 15px 40px;
}
.categorybox1 ul li a:link, .categorybox1 ul li a:visited {
color:#424242;
text-decoration: none;
}
.categorybox1 ul li a:hover, .categorybox1 ul li a:active {
color:#9e9e9e;
text-decoration: none;
}
.collapsible-landing {
border-top: none;
border-right: none;
border-left: none;
border-bottom: none;
margin: 0.5rem 0 1rem 0;
box-shadow: none;
}
.collapsible-landing .collapsible-header {
display: block;
cursor: pointer;
height: 60px;
line-height: 60px;
padding: 0 24px;
background-color: #fff;
border-bottom: none;
}
.collapsible-landing .collapsible-header h3 {
font-size: 16px;
font-weight: 500;
padding:0;margin: 0;
line-height: 60px;
}
.collapsible-landing .collapsible-header i {
width: auto;
font-size: 1.6rem;
line-height: 60px;
display: block;
float: left;
text-align: center;
margin-right: 0;
}
.collapsible-landing .collapsible-body {
background: #ffffff;
display: none;
border-bottom: none;
box-sizing: border-box;
}
.collapsible-list li a {
width:25%;
padding:10px 24px;
float:left;
color:#424242;
}
.collapsible-list li a:hover {
text-decoration: none;
border-bottom: none;
color:#9e9e9e;
}
.collapsible-list li.clearfix {
clear:both;
padding: 0 0 20px 0;
}
UPDATED
Pure CSS Way
Problem of icon change on expand and collapse of accordion has been resolved.
Check example code at CODEPEN
HTML:
<div class="col-md-12 " style="margin:20px 0 0 0">
<ul class="collapsible collapsible-landing">
<li>
<div class="panel-heading collapsed" data-toggle="collapse" data-target="#test">
<h3 class="panel-title accordion-toggle">Categories</h3>
</div>
<div class="collapsible-body collapsible-body panel-collapse collapse" id="test">
<ul class="collapsible-list">
<li> Sample 1 </li>
<li> Sample 2 </li>
<li> Sample 3 </li>
<li> Sample 4 </li>
<li> Sample 5 </li>
<li> Sample 6 </li>
<li> Sample 7 </li>
<li> Sample 8 </li>
<li class="clearfix"></li>
</ul>
</div>
</li>
</ul>
</div>
CSS:
ul {
list-style: none;
margin: 0;
padding: 0;
height: auto;
font-family: 'Roboto', sans-serif;
font-weight: 450;
font-size: 15px;
color: #424242;
border: 0;
}
.collapsible-landing {
border-top: none;
border-right: none;
border-left: none;
border-bottom: none;
margin: 0.5rem 0 1rem 0;
box-shadow: none;
}
.collapsible-list {
background: #efefef;
}
.collapsible-list li a {
width: 25%;
padding: 10px 24px;
float: left;
color: #424242;
}
.collapsible-list li a:hover {
text-decoration: none;
border-bottom: none;
color: #9e9e9e;
}
.collapsible-list li.clearfix {
clear: both;
padding: 0 0 20px 0;
}
.accordion-toggle:after {
/* symbol for "opening" panels */
font-family: 'Material-Design-Iconic-Font';
content: "\f273";
float: right;
color: inherit;
}
.panel-heading.collapsed .accordion-toggle:after {
/* symbol for "collapsed" panels */
content: "\f278";
}
you have a lot of css while a small jquery function just solve your problem easily.
Hoping it will help you!
$(function(){
$('#collapse1').on('hide.bs.collapse', function () {
$('#button').html('<span class="glyphicon glyphicon-chevron-down"></span> Show');
})
$('#collapse1').on('show.bs.collapse', function () {
$('#button').html('<span class="glyphicon glyphicon-chevron-up"></span> Hide');
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h2>Collapsible Panel</h2>
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a id="button" data-toggle="collapse" data-target="#collapse1">
<span class="glyphicon glyphicon-chevron-down"></span> show
</a>
</h4>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">Panel Body</div>
<div class="panel-footer">Panel Footer</div>
</div>
</div>
</div>
</div>

how to make each drop down menu align according to the button hovered over

I am new to coding and have managed to make a navbar with the first two buttons as dropdown menus. However, I have noticed that while hovering over the first button works fine, when I hover over the second dropdown button, the dropdown menu displays directly under the first button, whilst displaying the right information. Here is a photo to explain what I mean.
And here is my code, what I have tried to do here is to reuse all the code I have written for the first dropdown menu and then added a class to the second dropdown to slightly alter what is necessary to make the menu align to the second dropdown button:
#NavBar {
width: 100%;
margin: 0;
padding: 0;
position: relative;
}
#NavBar ul {
margin: 0;
padding: 0;
height:25px;
}
#NavBar ul li {
list-style-type: none;
width: 25%;
display: inline-block;
float: left;
background-color: #eecbff;
margin: 0;
padding: 0;
}
.DropBtn {
width: 100%;
font-size: 25px;
border: 0;
background-color: #eecbff;
}
.DropBtn:hover {
background-color: #ffd4e5;
border: 0;
border-radius: 8px 8px 0 0;
}
.Dropdown {
position: relative;
display: block;
}
.DropContent {
display: none;
margin: 0;
padding: 0;
position: absolute;
background-color: #ffd4e5;
width: 25%;
top: 31px;
border: 0;
border-radius: 0 0 8px 8px;
}
.Dropdown:hover .DropContent {
display: block;
border-radius: 0 0 8px 8px;
}
.DropContent a {
text-decoration: none;
display: block;
color: black;
height: 30px;
text-align: center;
}
.Dropdown:hover .DropBtn {
background-color: #ffd4e5;
border-radius: 8px 8px 0 0;
}
.DropContent a:hover {
background-color: #feffa3;
border-radius: 0 0 8px 8px;
}
.Second .DropContent{
position: absolute;
left: 25%;
}
<div id="NavBar">
<ul>
<div class="Dropdown">
<li><button class="DropBtn">Dropdown 1</button></li>
<div class="DropContent">
Link 1
Link 2
Link 3
</div>
</div>
<div class="Dropdown">
<li><button class="DropBtn Second" >Dropdown 2</button></li>
<div class="DropContent">
Link 4
Link 5
Link 6
</div>
</div>
<li><button class="DropBtn">Dropdown 3</button></li>
<li><button class="DropBtn">Dropdown 4</button></li>
</ul>
</div>
I'm very sorry if my code is very long winded, I am sure there are parts that aren't even necessary, any tips or comments about my code in general would be greatly appreciated.
Don't wrap your list item in a div. Using your current styles, I would drop the <div class="Dropdown"> and just apply that class to the list item specifically. If you do this, your dropdown will work as intended. See my edited HTML below.
I imagine the reason for this is, your Dropdown div doesn't really have a width or height, because its children are either floated or positioned absolutely. It's also unnecessary to do this, because the list item itself is perfectly capable of being a parent for your dropdown content, and it already has the positioning that you need.
Changes made: Wrapped the .DropContent div inside the li tag with the button. Removed the parent .Dropdown div and added the .Dropdown class to the li.
<div id="NavBar">
<ul>
<li class="Dropdown">
<button class="DropBtn">Dropdown 1</button>
<div class="DropContent">
Link 1
Link 2
Link 3
</div>
</li>
<li class="Dropdown">
<button class="DropBtn" >Dropdown 2</button>
<div class="DropContent">
Link 4
Link 5
Link 6
</div>
</li>
<li><button class="DropBtn">Dropdown 3</button></li>
<li><button class="DropBtn">Dropdown 4</button></li>
</ul>
</div>
Edited formatting.
Try placing your DropContent divs inside of the correspondent <li> tag, like the example bellow:
<div class="Dropdown">
<li>
<button class="DropBtn Second">Dropdown 2</button>
<div class="DropContent">
Link 4
Link 5
Link 6
</div>
</li>
</div>

black line through box

After adding link_to block, I now see a black line when I hover over the box -- see attached pic. Tried changing many CSS properties but couldn't resolve the issue. My view and CSS code are below. Any ideas how to remove this black line?
**View Code**
<div class="categories">
<ul>
<%= link_to nqdc_user_path do %>
<li>Sample Box</li>
<% end %>
</ul>
</div>
**CSS Code**
div.categories {
margin-top: 25px;
margin-left: 50px;
}
ul {
padding: 10px;
color: white;
list-style: none;
text-align: center;
}
li {
background-color: #4d4dff;
padding: 25px;
margin: 15px;
display: inline-block;
border-radius: 8px;
font-size: 18px;
color: white;
}
li:hover {
background: #b3b3ff;
color: black;
text-decoration: none;
}
Source Code
<div class= "categories">
<ul>
<a href="/users/1/nqdc">
<li>Sample Box</li>
</a>
</ul>
</div>
Link a element should go inside li element
<li>
<a href="">
Sample Box
</a>
</li>
codepem

how to overlap a list of menus over an image

When the menu "product" is clicked or mouse over, the another list of menus appear.. but the image block which is below the menu bar, moves away from the position. if i use css [ position:absolute;], then the image box remains static and the product's sub-menu overlaps the image block, which is what i wanted. but the image blocks width & height settings change drastically, thereby spoiling the alignment.
pls chk the codings in jsFiddle
.home_menu {
border: 1px solid black;
width: 98%;
height: 3.3%;
margin-right: auto;
margin-left: auto;
}
div#menuDemo {
clear: both;
//border:1px solid black;
height: 78%;
width: 100%;
position: relative;
left: 0;
top: 0;
background-color: #A55927;
/*Remove this next one in production - Used for demo purpose only*/
margin-bottom: 0.1%;
padding-top: 0.7%;
z-index: 4;
}
div#menuDemo ul {
list-style: none;
margin: 0;
padding: 0;
background-color: #A55927;
}
div#menuDemo > ul > li {
float: left;
text-align: center;
}
div#menuDemo ul li {
width: 25%;
//border: 5px solid purple;
}
div#menuDemo ul li a {
text-decoration: none;
font-weight: bolder;
text-align: center;
}
div#menuDemo > ul > li > ul {
display: none;
text-align: center;
}
div#menuDemo > ul > li:hover > ul {
display: block;
text-align: center;
}
.sub1 {
width: 100%;
//border:1px solid green;
}
.colouring {
color: black;
font-weight: bolder;
}
.colour {
//border:1px solid blue;
color: black;
text-align: center;
//width:100%;
}
.wrapper {
border: 5px solid pink;
width: 98.8%;
height: 82%;
margin-top: 1%;
z-index: 2;
}
.uniform_block {
border: 5px solid green;
width: 100%;
height: 40%;
cursor: pointer;
}
.uniform_block img {
width: 100%;
height: 100%;
}
<body>
<div class="home_menu">
<div id="menuDemo">
<ul>
<li id="homeMenu">About Us
</li>
<!-- <li >About Us</li> -->
<li>Products
<ul class="sub1">
<li> Uniforms
<ul>
<li> &nbsp
</li>
<li> Automobile Industry Uniforms
</li>
<li> Pharmaceutical Uniforms
</li>
<li> Food Industry Uniforms
</li>
<li> Government Sector Uniforms
</li>
<li> School/College Uniforms
</li>
<li> &nbsp
</li>
</ul>
</li>
<li>Shoes
<ul>
<li> &nbsp
</li>
<li> Industrial Shoes
</li>
<li> Safety & Security Shoes
</li>
<li> Executive Shoes
</li>
<li> &nbsp
</li>
</ul>
</li>
</ul>
</li>
<li>Contact Us
</li>
</ul>
</div>
</div>
<div class="wrapper">
<div class="uniform_block">
<img src=" http://t0.gstatic.com/images?q=tbn:ANd9GcSH-kRi3rkVciPcH_c6dDJJI6C1ntzwcKl9MoVQIyuKk8F7unpf" />
</div>
<div class="home_footer">
<div class="footer_contents"></div>
</div>
</div>
</body>
kindly help. My requirement is, when i mouse over the "product menu", the drop down menu should be viewed above the image block which is below the menu bar.
Add position:absolute to the css of your ul menu (in your case, the sub1 class), and remove the width:100% so it can inherit the default width of its parent. Absolute positioning will prevent your browser from trying to put your ul element after the previous element on the page.
ul.sub1 {
position:absolute;
}
http://jsfiddle.net/C2YXp/2/

Odd Internet Explorer 7 bug; not calculating padding on links correctly

It would appear that I am suffering from a new bug in IE7, as I can't seem to find any reference to it anywhere else. It is best explained using screenshots, so here are a couple of links (and as a note, it's not a requirement for it to work in IE6, so I don't even want to know what it looks like under that!):
How it should be displayed (using Safari 4):
http://dl-client.getdropbox.com/u/45961/safari4.png
How IE7 is displaying it:
http://dl-client.getdropbox.com/u/45961/ie7.png
Here's the CSS for that menu chunk:
#mm #leftNav .navigation {
width: 100%;
margin-bottom: 0;
float: left;
}
#mm #leftNav li {
list-style: none;
display: inline;
margin: 0;
}
#mm #leftNav .navigation li ul {
display: none;
}
#mm #leftNav .navigation li a {
text-decoration: none;
color: #ffffff;
font-size: 11pt;
padding-left: 20px;
}
#mm #leftNav .navigation li {
cursor: pointer;
margin-right: 4px;
padding-left: 8px;
padding-right: 8px;
padding-top: 10px;
padding-bottom: 8px;
overflow: visible;
}
.menu_item {
background: #419185;
}
.menu_item:hover {
background: #48a093;
}
.currentcat {
background-color: #4aa8a6;
}
.currentcat:hover {
background: #4aa8a6;
}
And here is the HTML:
<div id="mm">
<div id="leftNav">
<ul class="navigation">
<li class="menu_item">
<a class="icon icon-base">Base</a>
</li>
<li class="menu_item">
<a class="icon icon-devices">Devices</a>
</li>
<li class="menu_item">
<a class="icon icon-management">Management</a>
</li>
<li class="menu_item">
<a class="icon icon-iptools">IP Tools</a>
</li>
<li class="menu_item">
<a class="icon icon-config">Configuration</a>
</li>
<li class="menu_item">
<a class="icon icon-admin">Administration</a>
</li>
</ul>
<div id="subnav"></div>
</div>
</div>
Any ideas?
top and bottom padding are not supported on inline elements (some browsers will render it, others won't)
Here's a good article on the problem:
http://www.maxdesign.com.au/presentation/inline/
If you really need correct padding, you should change the menu items to "display:block" and "float:left"
Hehe, activa beat me to it.
Indeed, move your margin/padding to the A element, kinda like so:
mm #leftNav .navigation li a {
text-decoration: none;
color: #ffffff;
font-size: 11pt;
display:block;
float:left;
background: #419185;
margin-right: 4px;
padding-left: 20px;
padding-right: 8px;
padding-top: 10px;
padding-bottom: 8px;
}
mm #leftNav .navigation li {
cursor: pointer;
}
.menu_item {
}

Resources