as you can see in the bottom code i create li to make list instead select option in html tag. but i get undesirable thing in appearance.
how to make li width same like bottom width. i have added value of width in css. the value 100% make li wider than bottom.
how tom make caret and number inside li position float in right. i can add class pull-rigt to make it in right position but it make caret higher than text in left position (i want make them in same middle vertical position)
.instead-option {
z-index:999;
position: absolute;
margin: 0;
max-height:300px;
background: #ffffff;
border-radius:4px;
border:1px solid #dddddd;
width:100%;
overflow:auto;
}
.instead-option > li {
width:100%;
background: #eee;
line-height: 25px;
font-size: 14px;
padding: 0 10px;
cursor: pointer;
}
.instead-option > li > a{
display: flex;
width: 100%;
}
.instead-option > li:nth-child(odd) {
background-color: #ffffff;
}
.instead-option > li:nth-child(even) {
background-color: #e5e5e5;
}
.instead-option > li:hover {
background: #aaa;
}
.instead-option > li > a{
color:#232323;
text-decoration:none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<button type="button" class="form-control text-left nominal">Pilih nominal<span class="caret caret-right"></span></button>
<ul class="instead-option list-unstyled">
<li>English <span class="text-primary pull-right">10000</span></li>
<li>Deutsch <span class="text-primary pull-right">50000</span></li>
</ul>
</div>
</div>
</div>
Since you have position: absolute; on .instead-option element, you can have another element wrapping with position: relative;.
You can use a small hack to position the caret both horizontally and vertically by using top: 50%; rule.
.instead-option {
z-index: 999;
position: absolute;
margin: 0;
max-height: 300px;
background: #ffffff;
border-radius: 4px;
border: 1px solid #dddddd;
width: 100%;
overflow: auto;
}
.instead-option > li {
width: 100%;
background: #eee;
line-height: 25px;
font-size: 14px;
padding: 0 10px;
cursor: pointer;
}
.instead-option > li > a {
display: block;
width: 100%;
}
.instead-option > li:nth-child(odd) {
background-color: #ffffff;
}
.instead-option > li:nth-child(even) {
background-color: #e5e5e5;
}
.instead-option > li:hover {
background: #aaa;
}
.instead-option > li > a {
color: #232323;
text-decoration: none;
}
.dropdown-container {
position: relative;
}
.dropdown-container .caret {
position: absolute;
/* Have the same padding to right as in the button*/
right: 12px;
/* Position the element from top by 50% of the parent element's height */
top: 50%;
/* Moves the element from its current position by -50% on Y axis to position the element vertically middle*/
transform: translateY(-50%);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="dropdown-container">
<button type="button" class="form-control text-left nominal">Pilih nominal<span class="caret caret-right"></span>
</button>
<ul class="instead-option list-unstyled">
<li>English <span class="text-primary pull-right">10000</span>
</li>
<li>Deutsch <span class="text-primary pull-right">50000</span>
</li>
</ul>
</div>
</div>
</div>
</div>
You're using position:absolute on the .instead-option list. As such, width:100% is calculated independent of the containing div's padding value.
You can fix this by changing your css to match the padding on the col div
.instead-option {
z-index:999;
position: absolute;
margin: 0;
max-height:300px;
background: #ffffff;
border-radius:4px;
border:1px solid #dddddd;
/* width:100%; */ /* REMOVE THIS LINE */
overflow:auto;
left:15px; /* matches column left padding */
right:15px; /* matches column right padding */
}
Below is your answer. Fixed both points, See additional css added at the end of css code .
.instead-option {
z-index: 999;
position: absolute;
margin: 0;
max-height: 300px;
background: #ffffff;
border-radius: 4px;
border: 1px solid #dddddd;
width: 100%;
overflow: auto;
}
.instead-option > li {
width: 100%;
background: #eee;
line-height: 25px;
font-size: 14px;
padding: 0 10px;
cursor: pointer;
}
.instead-option > li > a {
display: flex;
width: 100%;
}
.instead-option > li:nth-child(odd) {
background-color: #ffffff;
}
.instead-option > li:nth-child(even) {
background-color: #e5e5e5;
}
.instead-option > li:hover {
background: #aaa;
}
.instead-option > li > a {
color: #232323;
text-decoration: none;
}
/*Additional Css*/
.instead-option {
width: calc(100% - 30px)
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-sm-12">
<button type="button" class="form-control text-right nominal">
<span class="pull-left">Pilih nominal</span><span class="caret caret-right"></span>
</button>
<ul class="instead-option list-unstyled">
<li>English <span class="text-primary pull-right">10000</span>
</li>
<li>Deutsch <span class="text-primary pull-right">50000</span>
</li>
</ul>
</div>
</div>
</div>
Related
/*---POPUP MENU CSS---*/
.box{
position:fixed;
top: 0.1%;
left: 14px;
display: inline-block;
cursor: pointer;
}
ul{
list-style-type: none;
}
ul li{
font-family: Lato;
padding: 10px;
}
ul li a{
text-decoration: none;
color: black;
}
ul li:hover{
background-color: bisque;
}
.box1{
position: absolute;
top:3%;
left:15px;
z-index: 1;
background-color: floralwhite;
max-width: 260px;
box-sizing: border-box;
box-shadow: 2px 5px 15px black;
display: none;
}
.box2{
position: absolute;
top:3%;
left:8%;
z-index: 2;
background-color: floralwhite;
max-width: 260px;
box-sizing: border-box;
box-shadow: 2px 5px 15px black;
display: none;
}
.box:hover .box1{
display: block;
}
#nav li:focus .box2 {
display:block;
}
<!--box-->
<div class="box">
<img src="https://img.icons8.com/ios-filled/344/menu-rounded.png"
height="35px"width="35px" id="menu">
<!--box1-->
<div class="box1">
<ul>
<li id="nav">item1 »</li>
<li>item2</li>
<li><a href="#" >item3</a></li>
<li>item4</li>
<li><a href="#" >item5</a></li>
<li>item6</li>
</ul>
</div>
</div>
<!--box2-->
<div class="box2">
<ul>
<li>sub-item1</li>
<li>sub-item2</li>
<li>sub-item3</li>
<li>sub-item4</li>
</ul>
</div>
I'm trying to create a popup menu that appears when you click or hover on a small image(basically an icon)with only html and css no js. But problem is the main menu appears but sub-menu don't appear when you focus on some desire item from the list.
Is there anything that I can do? I just want to build a very basic menu.`
You can use checkbox inputs to simulate this behaviour with the :checked attribute.
By hiding the checkbox and making your menu icon a label for that input element, you can toggle the checked state and use CSS to display based on that instead of hover.
/*---POPUP MENU CSS---*/
.box {
position: fixed;
top: 0.1%;
left: 14px;
display: inline-block;
cursor: pointer;
}
ul {
list-style-type: none;
}
ul li {
font-family: Lato;
padding: 10px;
}
ul li a {
text-decoration: none;
color: black;
}
ul li:hover {
background-color: bisque;
}
.box1 {
position: absolute;
top: 3%;
left: 15px;
z-index: 1;
background-color: floralwhite;
max-width: 260px;
box-sizing: border-box;
box-shadow: 2px 5px 15px black;
display: none;
}
.box2 {
position: absolute;
top: 3%;
left: 8%;
z-index: 2;
background-color: floralwhite;
max-width: 260px;
box-sizing: border-box;
box-shadow: 2px 5px 15px black;
display: none;
}
#nav li:focus .box2 {
display: block;
}
/**
* Checkbox toggle
*/
/* hide the checkbox */
.menu-toggle {
display: none;
}
/* display the box when input is checked */
.menu-toggle:checked ~ .box1 {
display: block;
}
<!--box-->
<div class="box">
<!-- hidden checkbox -->
<input class="menu-toggle" id="menu-toggle" type="checkbox" />
<!-- label for the toggle -->
<label for="menu-toggle">
<img src="https://img.icons8.com/ios-filled/344/menu-rounded.png"
height="35px"width="35px" id="menu">
</label>
<!--box1-->
<div class="box1">
<ul>
<li id="nav">item1 »</li>
<li>item2</li>
<li>item3</li>
<li>item4</li>
<li>item5</li>
<li>item6</li>
</ul>
</div>
</div>
<!--box2-->
<div class="box2">
<ul>
<li>sub-item1</li>
<li>sub-item2</li>
<li>sub-item3</li>
<li>sub-item4</li>
</ul>
</div>
I have tried to embed a vertical menu bar on my Blogger website. But it seems like it's not responsive and the colour is not matching my website.
I need to remove the shadow and make the website responsive in mobile.
My website's background colour is white: https://codemyquestion.blogspot.com/
This is how it is opened:
This is the expected output:
Below is the code:
<style>
.ddsmoothmenu-v ul {
margin: 0;
padding: 0;
width: 130px;
/* Main Menu Item widths */
list-style-type: none;
font: bold 12px Verdana;
border-bottom: 0px solid #ccc;
}
.ddsmoothmenu-v ul li {
position: relative;
}
.downarrowclass {
position: absolute;
top: 12px;
right: 7px;
}
.rightarrowclass {
position: absolute;
top: 10px;
right: 5px;
}
/* Top level menu links style */
.ddsmoothmenu-v ul li a {
display: block;
overflow: auto;
/*force hasLayout in IE7 */
height: 32px;
color: white;
text-decoration: none;
padding: 5px 5px 5px 25px;
border-bottom: 0px solid #778;
border-right: 0px solid #778;
}
.ddsmoothmenu-v ul li a:link, .ddsmoothmenu-v ul li a:visited, .ddsmoothmenu-v ul li a:active {
color: white;
background-image: url(http://3.bp.blogspot.com/-VCtcZunZJ2U/T9W7MM1uIXI/AAAAAAAAB9o/yVJ0Cad3Q0g/s1600/tab_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
margin-bottom: 1px;
}
.ddsmoothmenu-v ul li a.selected {
/*CSS class that's dynamically added to the currently active menu items' LI A element*/
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
.ddsmoothmenu-v ul li a:hover {
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
/*Sub level menu items */
.ddsmoothmenu-v ul li ul {
position: absolute;
width: 170px;
/*Sub Menu Items width */
height: 22px;
top: 0;
font-weight: normal;
visibility: hidden;
}
/* Holly Hack for IE \*/
* html .ddsmoothmenu-v ul li {
float: left;
height: 1%;
}
* html .ddsmoothmenu-v ul li a {
height: 1%;
}
/*======= Vertical Drop Down Menu By Helper Blogger ========= */
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://helperblogger.ucoz.com/code/hb-smooth-menu.js"></script>
<script type="text/javascript">
})
</script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "smoothmenu2",
//Menu DIV id
orientation: 'v',
//Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu-v',
//class added to menu's outer DIV
//customtheme: ["#804000", "#482400"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<div id="smoothmenu2" class="ddsmoothmenu-v">
<ul>
<li>
Home
</li>
<li>
Folder 0
<ul>
<li>
Sub Item 1.1
</li>
<li>
Sub Item 1.2
</li>
</ul>
</li>
<li>
Folder 1
<ul>
<li>
Sub Item 1.1
</li>
<li>
Sub Item 1.2
</li>
</ul>
</li>
<li>
Item 3
</li>
<li>
Folder 2
<ul>
<li>
Sub Item 2.1
</li>
</ul>
</li>
<li>
Create This
</li>
</ul>
<br style="clear: left" />
</div>
the black white nav menu:
HTML
<div class="sidenav">
<i class="fa fa-home"></i> About
<i class="fa fa-home"></i> Services
<i class="fa fa-home"></i> Clients
<i class="fa fa-home"></i> Contact
<div href="#" class="dropdown-btn">
<i class="fa fa-home"></i>
<i class="fa fa-caret-right"></i>Dropdown
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fa fa-home"></i> Search
</div>
CSS
.sidenav {
height: 100%;
width: 58px;
position: relative;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding: 20px 0;
white-space: nowrap;
overflow-x:hidden;
transition: all 0.2s ease-in-out;
}
.sidenav:hover {
width: 200px;
overflow-x:visible;
}
.sidenav .fa:not(.fa-caret-right){
margin-right:20px;
}
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
position:relative;
}
.dropdown-btn:hover .dropdown-container{
display:block;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
position:absolute;
width:200px;
left:100%;
margin-top:-30px;
}
.fa-caret-right {
float: right;
padding-right: 8px;
display:none !important;
}
the sub-menu opens to the right side, if you want to open it from the left side use this code:
HTML
<div class="sidenav">
<i class="fa fa-home"></i> About
<i class="fa fa-home"></i> Services
<i class="fa fa-home"></i> Clients
<i class="fa fa-home"></i> Contact
<div href="#" class="dropdown-btn">
<i class="fa fa-home"></i>
Dropdown
<i class="fa fa-caret-left"></i>
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fa fa-home"></i> Search
</div>
CSS
.sidenav {
direction:rtl;
height: 100%;
width: 58px;
position: relative;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding: 20px 0;
white-space: nowrap;
overflow-x:hidden;
transition: all 0.2s ease-in-out;
}
.sidenav:hover {
width: 200px;
overflow-x:visible;
}
.sidenav .fa:not(.fa-caret-left){
margin-left:20px;
}
.sidenav a, .dropdown-btn {
padding: 6px 16px 6px 8px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: right;
cursor: pointer;
outline: none;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
position:relative;
}
.dropdown-btn:hover .dropdown-container{
display:block;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-right: 8px;
position:absolute;
width:200px;
right:100%;
margin-top:-30px;
}
.fa-caret-right {
float: left;
display:none !important;
}
Funny, I recently made my online web-game mobile responsive too. I can help:
The problem is px. Don't use px for mobile websites. Instead, use percent (%) or viewport-width (vw) these will make it so the elements will resize to the browser size.
Absolute positioning. It will override the width of the page if the elements are not inside a div. If it's in a div, It'll not follow the width of that div. Instead, use position: relative because this is relative to the width or height of the viewport page.
Try resizing your browser on your laptop/desktop, and notice the elements match. Next:
Use the CSS3 max-width property so on laptop, it'll look fine. But on mobile devices it'll probably look like a smaller version of the desktop sized screen. For example:
will look the same on a mobile device but smaller.
Now, finally, you can use: <meta> HTML tag. It definitely works on texts, images, Etc. Here's how:
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
use these tricks and your website is ready for mobile devices.
Edit: I saw your website. Everything looks fine on my laptop.
What exactly is wrong?
you just need to make some changes in your style
<style>
.ddsmoothmenu-v ul {
margin: 0;
padding: 0;
width: 130px;
/* Main Menu Item widths */
list-style-type: none;
font: bold 12px Verdana;
border-bottom: 0px solid #ccc;
}
.ddsmoothmenu-v ul li {
position: relative;
}
.downarrowclass {
position: absolute;
top: 12px;
left: 7px;
transform:rotateY(180deg); /* change the right arrow to left arrow */
}
.rightarrowclass {
position: absolute;
top: 10px;
left: 5px;
transform:rotateY(180deg); /* change the right arrow to left arrow */
}
/* Top level menu links style */
.ddsmoothmenu-v ul li a {
display: block;
overflow: auto;
/*force hasLayout in IE7 */
height: 32px;
color: white;
text-decoration: none;
padding: 5px 5px 5px 25px;
border-bottom: 0px solid #778;
border-right: 0px solid #778;
}
.ddsmoothmenu-v ul li a:link, .ddsmoothmenu-v ul li a:visited, .ddsmoothmenu-v ul li a:active {
color: white;
background-image: url(http://3.bp.blogspot.com/-VCtcZunZJ2U/T9W7MM1uIXI/AAAAAAAAB9o/yVJ0Cad3Q0g/s1600/tab_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
margin-bottom: 1px;
}
.ddsmoothmenu-v ul li a.selected {
/*CSS class that's dynamically added to the currently active menu items' LI A element*/
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
.ddsmoothmenu-v ul li a:hover {
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
/*Sub level menu items */
.ddsmoothmenu-v ul li ul {
position: absolute;
width: 170px;
/*Sub Menu Items width */
height: 22px;
top: 0;
font-weight: normal;
visibility: hidden;
left:-170px !important; /* move the sub-menu to the left */
box-shadow:none !important; /* remove the shadow */
}
/* Holly Hack for IE \*/
* html .ddsmoothmenu-v ul li {
float: left;
height: 1%;
}
* html .ddsmoothmenu-v ul li a {
height: 1%;
}
/*======= Vertical Drop Down Menu By Helper Blogger ========= */
</style>
I am writing a web and the drop-down menu button is not working. The hoverable content is not shown. May anyone tell me the reason, please. Thanks a lot!!!
Here is the code
* {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
h1.header {
text-align: center;
color: #66F3ED;
}
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #808080;
height: 70px;
font-size: 18px;
}
li {
float: left;
height: 70px;
}
li:last-child {
border-bottom: none;
}
li a {
display: block;
color: #66f3ed;
text-align: center;
padding: 23px 60px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #808080;
border-bottom: 5px solid #66f3ed;
}
/* Create three unequal columns that floats next to each other */
.column {
float: left;
height: 800px;
}
/* Left and right column */
.column.side {
width: 6%;
background-color: #868686;
overflow: hidden;
z-index:2;
}
/* Middle column */
.column.middle {
width: 70%;
background-color: #777777;
z-index:1;
}
.column.right {
width: 24%;
background-color: #919191;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/*Drop down Menu*/
.dropbtn {
background-color: transparent;
color: #66F3ED;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
display: inline-block;
z-index: 10!important;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
left:100%;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.column.side, .column.middle {
width: 100%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="row">
<!--Side Menu Bar-->
<div class="column side">
<div class="dropdown">
<button class="dropbtn"><img src="Menu/Menu-1.png" style="width: 100%" alt="Menu"></button>
</div>
<br /><br />
<img src="menu.jpg" alt="Menu">
</div>
<div class="dropdown-content">
Link 1
Link 2
</div>
<div class="column middle">
<ul>
<li><img src="sa_crop.gif" style="height: 70px"alt="Logo"></li>
<li><a class="active" href="#home">Face Mask Detection</a></li>
<li>Social Distance Detection</li>
</ul>
<br /><h1 class="header">Face Mask Detection</h1><br />
<!--Face Mask Detection Area-->
</div>
<div class="column right">
<ul>
<li style="float:right"><img src="user_808080.jpg" style="height: 70px" alt="User"></li>
</ul>
</div>
</div>
</body>
</html>
The whole codings are shown above. I am not sure about the problem, yet it should be the CSS styling issues. Please someone give me a hint. Thank you very much!
You have several issues in both your HTML and CSS to solve, so the menu will work correctly.
First: The <div class="dropdown"> should contins the button, image and dropdown-content inside </div>
for example, change:
<div class="column side">
<div class="dropdown">
<button class="dropbtn"><img src="Menu/Menu-1.png" style="width: 100%" alt="Menu"></button>
</div>
<br /><br />
<img src="menu.jpg" alt="Menu">
</div>
<div class="dropdown-content">
Link 1
Link 2
</div>
to
<div class="column side">
<div class="dropdown">
<button class="dropbtn"><img src="Menu/Menu-1.png" style="width: 100%" alt="Menu"></button>
<br /><br />
<img src="menu.jpg" alt="Menu">
<div class="dropdown-content">
Link 1
Link 2
</div>
</div>
</div>
Second: in the style of .dropdown-content, using of position: absolute; is correct but you should change left:100%; to left:0;, therefore you get the dropdown-content beside the menu-item.
Third: Add the CSS style code for hovering over the menu item, to make the sub-menu-item appears as:
.dropdown:hover .dropdown-content{
display: block;
}
Fourth: Change the background of the sub-menu-item when hovering, for example
.dropdown-content a:hover {
color: white;
background-color: red;
}
if you make the above four points, the menu will behave as expected.
and here is the full modified code of the question- just press Run the code snippet below:
* {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
h1.header {
text-align: center;
color: #66F3ED;
}
body {
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #808080;
height: 70px;
font-size: 18px;
}
li {
float: left;
height: 70px;
}
li:last-child {
border-bottom: none;
}
li a {
display: block;
color: #66f3ed;
text-align: center;
padding: 23px 60px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #808080;
border-bottom: 5px solid #66f3ed;
}
/* Create three unequal columns that floats next to each other */
.column {
float: left;
height: 800px;
}
/* Left and right column */
.column.side {
width: 6%;
background-color: #868686;
overflow: hidden;
z-index:2;
}
/* Middle column */
.column.middle {
width: 70%;
background-color: #777777;
z-index:1;
}
.column.right {
width: 24%;
background-color: #919191;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/*Drop down Menu*/
.dropbtn {
background-color: transparent;
color: #66F3ED;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
display: inline-block;
z-index: 10!important;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
left:0; /* Modified */
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* adding */
.dropdown:hover .dropdown-content{
display: block;
}
/* adding */
.dropdown-content a:hover {
color: white;
background-color: red;
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 600px) {
.column.side, .column.middle {
width: 100%;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>CSS Website Layout</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="row">
<!--Side Menu Bar-->
<div class="column side">
<div class="dropdown">
<button class="dropbtn"><img src="Menu/Menu-1.png" style="width: 100%" alt="Title"></button>
<br /><br />
<img src="menu.jpg" alt="MenuItem">
<div class="dropdown-content">
Link 1
Link 2
</div>
</div>
</div>
<div class="column middle">
<ul>
<li><img src="sa_crop.gif" style="height: 70px"alt="Logo"></li>
<li><a class="active" href="#home">Face Mask Detection</a></li>
<li>Social Distance Detection</li>
</ul>
<br /><h1 class="header">Face Mask Detection</h1><br />
<!--Face Mask Detection Area-->
</div>
<div class="column right">
<ul>
<li style="float:right"><img src="user_808080.jpg" style="height: 70px" alt="User"></li>
</ul>
</div>
</div>
</body>
</html>
My "search box and social icons" are hidden behind my main-menu. This is probably because of my .hide-menu class. I have a jQuery plugin that makes the main-menu appear when scrolling-up and makes it disappear when scrolling-down.
What I want to achieve is that the "search box and social icons" DIV show always and below the main-menu. Is this possible?
My FIDDLE... FIDDLE LINK HERE
.navbar-default .navbar-nav > .active > a,.navbar-default .navbar-nav > .active > a:focus,.navbar-default .navbar-nav > .active > a:hover {
color: #fff;
}
.menu-container {
background-color: #fff;
border-bottom: 1px solid #000;
border-top: 1px solid #000;
min-height: 20px;
position: relative;
}
.navbar-nav a:hover {
color: #000;
}
.navbar-nav a:link {
font-size: 12px;
font-family: 'century schoolbook';
color: #000;
/*text-decoration: overline;
text-decoration-color: #A10000*/
}
.brand-name a {
text-decoration: none;
}
.brand-name img {
max-width: 137px;
padding: 8px;
/*position:absolute;*/
left: 0;
}
ul {
list-style-type: none;
}
.navbar-form input,.form-inline input {
width: auto;
}
#nav.affix {
position: fixed;
top: 0;
width: 100%;
z-index: 10;
}
#sidebar.affix-top {
position: static;
}
#sidebar.affix {
position: fixed;
top: 80px;
}
.navbar-default .navbar-nav > li > a {
color: #A10000;
font-family: 'LuzSans-Book';
font-size: 15px;
font-weight:bold
}
.navbar-default .navbar-nav > li > a:hover {
background-color: #A10000;
color: #000;
margin-top:4px;
margin-bottom:4px;
}
.navbar-default .navbar-nav > .active > a {
background-color: #000;
margin-top:4px;
margin-bottom:4px;
}
.navbar-custom-social {
height: 15px;
float: right;
clear: none;
margin-right: 25px;
}
.navbar-fixed-top {
padding-top: 0;
}
#search-social {
margin-bottom:20px
}
header.site_header {
box-shadow: 0 1px 6px rgba(0,0,0,.35);
width: 100%;
top: 0;
left: 0;
position: fixed;
z-index: 999;
-webkit-transition: top .5s;
transition: top .5s;
background-color: #fff;
}
header.site_header.hide-menu {
top: -90px;
}
<header class="site_header root" id="nav">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="navbar navbar-default navbar-static">
<!-- <div class="clearfix container navbar-fixed-top"> -->
<div class="clearfix menu-container">
<div class="pull-right clearfix toggle_btn_wrap">
<a class="navbar-toggle" data-target=
".navbar-collapse" data-toggle="collapse" href=
"#"><i class="fa fa-bars"></i></a>
</div>
<div class="pull-left brand-name">
<a href="#"><img alt="NAME" src=
"/images/LOGO.png"></a>
</div>
<div class="clearfix prevent-float"></div>
<div class="navbar-collapse collapse">
MENU ITEMS
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<div id="search-social" class="container">
<div class="row">
<div class="col-sm-12">
<div class="navbar navbar-default navbar-static">
<div class="clearfix search_and_social">
<div class="clearfix navbar navbar-custom-search">
SEARCH BOX
</div>
<div class="clearfix navbar navbar-custom-social">
SOCIAL ICONS
</div>
</div>
</div>
</div>
</div>
</div>
Easiest is probably to use sibling selector between .site_header and #search-social. Make sure that #search-social is positioned. Something like:
#search-social {
margin-bottom: 20px;
position: relative;
}
header.site_header ~ #search-social {
top: 40px;
}
header.site_header.hide-menu ~ #search-social {
top: 0px;
}
Example (with a testbutton): https://jsfiddle.net/7f6q75h8/2/
Note: Top styling needs some adjustment depending on the menu height.
Maybe you can use position:absolute;
Else you can add a class on the wrapper when you wanna show or hide something.
.wrapper .active .div2{
display:block;
}
I don't know if this is what you want but may lead you in right direction. just added a jquery function to determine the state when menu bar is visible,
function adjustMenu() {
if (!$('#nav').hasClass('hide-menu')) {
$('#search-social').css('margin-top', $('#nav').height() + 'px');
} else {
$('#search-social').css('margin-top', '0px');
}
}
this function is called on page load as well as inside the onscroll event of page
$(window).scroll(function() {
adjustMenu();
});
here is the updated fiddle
there are better ways if you can edit in the plugin code you are using.
Please consider the following code snippet.
My question is: why is the second li, the one with class filterdivision, lower in the layout than the previous one instead of being verticaly aligned with it ? I gave it the same height and see no margin or padding that might push it down.
Javascript code isn't relevant to the question but allows the snippet to be functional.
var triggerFilter = function(filterData)
{
console.log(filterData);
}
$(".customDropdown li").on('click',function(){
var $self = $(this);
var $list = $self.parent();
if($list.hasClass("listVisible"))
{ //Whole list is visible => Selecting an option
$list.find('.active').removeClass("active");
$self.addClass("active");
$list.removeClass("listVisible");
triggerFilter({filterName:$list.data("fieldname"),filterValue:$self.data("fieldvalue")});
}
else
{
//Show whole list
$list.addClass("listVisible");
}
});
.wrapper { background: #f2f2f2;; padding: 20px;position: relative;height:60px;}
.wrapper input { box-sizing: border-box; border: 1px solid #c2c2c2; font-size: 14px; padding: 10px 15px; width: 100%;}
.wrapper ol.filters { padding:0; margin: 0; font-size: 0; height:58px;}
.wrapper ol.filters > li
{
list-style-type: none;
display: inline-block;
width: 150px;
margin-right:20px;
height: 58px;/*Need to fix height because of absolute positionned fake dropdowns*/
position:relative;
}
.wrapper ol.filters > li:last-child{ margin-right:0;}
.wrapper ol.filters > li:first-child{ width: 150px;}
.wrapper label { display:block; font-size:12px; color: #797979; margin-bottom: 3px;}
/* CSS for custom dropdown */
.customDropdown {
position:absolute;
z-index: 50;
padding:0;
margin:0;
list-style-type: none;
background: #fff;
border: 1px solid #c2c2c2;
cursor: pointer;
width:150px;
}
.customDropdown li {display:none;padding: 10px 15px;font-size:14px;}
.customDropdown li::after { position: absolute; top: 10px; right: 10px; content: ""; display: inline-block; width: 0.5em; height: 0.5em; border-right: 2px solid black; border-bottom: 2px solid black; transform: rotate(45deg);}
.customDropdown li.active {display:block;}
.customDropdown.listVisible li {display:block;border-bottom: 1px solid #f2f2f2;}
.customDropdown.listVisible li:hover {background: #f2f2f2;color:#4fbbeb;}
.customDropdown.listVisible li.active {color:#4fbbeb;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<ol class="filters">
<li class="filterSearch">
<label for="filterSearch">Search</label><input type="text" id="search">
</li>
<li class="filterDivision">
<label>Division</label>
<ol class="customDropdown" data-fieldname="division">
<li class="active" data-fieldvalue="all">All divisions</li>
<li data-fieldvalue="consulting">Consulting</li>
<li data-fieldvalue="digital">Digital</li>
<li data-fieldvalue="other">Other</li>
</ol>
</li>
<!-- ... Other filter options in li tags -->
</ol>
</div>
Try using
float:left
instead of
display:inline-block
in
.wrapper ol.filters > li
Although this doesn't seem to be an issue here, floating elements wont affect the parent elements height, unless you add
clear:both;
overflow:auto;
to the parent elements style like this:
<div style="clear:both; overflow:auto">
<div style="float:left">hello</div>
<div style="float:left">world</div>
</div>
here's you code snippet using floating elements (I'm not sure what's causing your issue exactly, but floating left fixes it)
var triggerFilter = function(filterData)
{
console.log(filterData);
}
$(".customDropdown li").on('click',function(){
var $self = $(this);
var $list = $self.parent();
if($list.hasClass("listVisible"))
{ //Whole list is visible => Selecting an option
$list.find('.active').removeClass("active");
$self.addClass("active");
$list.removeClass("listVisible");
triggerFilter({filterName:$list.data("fieldname"),filterValue:$self.data("fieldvalue")});
}
else
{
//Show whole list
$list.addClass("listVisible");
}
});
.wrapper { background: #f2f2f2;; padding: 20px;position: relative;height:60px;}
.wrapper input { box-sizing: border-box; border: 1px solid #c2c2c2; font-size: 14px; padding: 10px 15px; width: 100%;}
.wrapper ol.filters { padding:0; margin: 0; font-size: 0; height:58px;}
.wrapper ol.filters > li
{
list-style-type: none;
float:left;
width: 150px;
margin-right:20px;
height: 58px;/*Need to fix height because of absolute positionned fake dropdowns*/
position:relative;
}
.wrapper ol.filters > li:last-child{ margin-right:0;}
.wrapper ol.filters > li:first-child{ width: 150px;}
.wrapper label { display:block; font-size:12px; color: #797979; margin-bottom: 3px;}
/* CSS for custom dropdown */
.customDropdown {
position:absolute;
z-index: 50;
padding:0;
margin:0;
list-style-type: none;
background: #fff;
border: 1px solid #c2c2c2;
cursor: pointer;
width:150px;
}
.customDropdown li {display:none;padding: 10px 15px;font-size:14px;}
.customDropdown li::after { position: absolute; top: 10px; right: 10px; content: ""; display: inline-block; width: 0.5em; height: 0.5em; border-right: 2px solid black; border-bottom: 2px solid black; transform: rotate(45deg);}
.customDropdown li.active {display:block;}
.customDropdown.listVisible li {display:block;border-bottom: 1px solid #f2f2f2;}
.customDropdown.listVisible li:hover {background: #f2f2f2;color:#4fbbeb;}
.customDropdown.listVisible li.active {color:#4fbbeb;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<ol class="filters">
<li class="filterSearch">
<label for="filterSearch">Search</label><input type="text" id="search">
</li>
<li class="filterDivision">
<label>Division</label>
<ol class="customDropdown" data-fieldname="division">
<li class="active" data-fieldvalue="all">All divisions</li>
<li data-fieldvalue="consulting">Consulting</li>
<li data-fieldvalue="digital">Digital</li>
<li data-fieldvalue="other">Other</li>
</ol>
</li>
<!-- ... Other filter options in li tags -->
</ol>
</div>
Inline blocks are blocks that try to span the entire width and in your code, the .wrapper didn't have the width set, which forced it to take up space beside, and not below
var triggerFilter = function(filterData)
{
console.log(filterData);
}
$(".customDropdown li").on('click',function(){
var $self = $(this);
var $list = $self.parent();
if($list.hasClass("listVisible"))
{ //Whole list is visible => Selecting an option
$list.find('.active').removeClass("active");
$self.addClass("active");
$list.removeClass("listVisible");
triggerFilter({filterName:$list.data("fieldname"),filterValue:$self.data("fieldvalue")});
}
else
{
//Show whole list
$list.addClass("listVisible");
}
});
.wrapper { background: #f2f2f2;; padding: 20px;position: relative;height:150px; width: 60px}
.wrapper input { box-sizing: border-box; border: 1px solid #c2c2c2; font-size: 14px; padding: 10px 15px; width: 100%;}
.wrapper ol.filters { padding:0; margin: 0; font-size: 0; height:116px;}
.wrapper ol.filters > li
{
list-style-type: none;
display: inline-block;
width: 150px;
margin-top: 10px;
margin-right:20px;
height: 58px;/*Need to fix height because of absolute positionned fake dropdowns*/
position:relative;
}
.wrapper ol.filters > li:last-child{ margin-right:0;}
.wrapper ol.filters > li:first-child{ width: 150px;}
.wrapper label { display:inline-block; font-size:12px; color: #797979; margin-bottom: 3px;}
/* CSS for custom dropdown */
.customDropdown {
position:absolute;
z-index: 50;
padding:0;
margin:0;
list-style-type: none;
background: #fff;
border: 1px solid #c2c2c2;
cursor: pointer;
width:150px;
}
.customDropdown li {display:none;padding: 10px 15px;font-size:14px;}
.customDropdown li::after { position: absolute; top: 10px; right: 10px; content: ""; display: inline-block; width: 0.5em; height: 0.5em; border-right: 2px solid black; border-bottom: 2px solid black; transform: rotate(45deg);}
.customDropdown li.active {display:block;}
.customDropdown.listVisible li {display:block;border-bottom: 1px solid #f2f2f2;}
.customDropdown.listVisible li:hover {background: #f2f2f2;color:#4fbbeb;}
.customDropdown.listVisible li.active {color:#4fbbeb;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<ol class="filters">
<li class="filterSearch">
<label for="filterSearch">Search</label><input type="text" id="search">
</li>
<li class="filterDivision">
<label>Division</label>
<ol class="customDropdown" data-fieldname="division">
<li class="active" data-fieldvalue="all">All divisions</li>
<li data-fieldvalue="consulting">Consulting</li>
<li data-fieldvalue="digital">Digital</li>
<li data-fieldvalue="other">Other</li>
</ol>
</li>
<!-- ... Other filter options in li tags -->
</ol>
</div>