css - textbox filling to width, right justify buttons, etc - html

In some ways, I'm still pretty new to CSS and don't "get" how things are done (is seems convoluted, and there doesn't seem to be an easy way to figure things out) - so I am hoping someone here can help me. I'll post the relevant code. I am a programmer - but can't seem to figure out how to do what I want. (BTW - are there any good tools for 'visually' editing CSS? I'm doing this purely by code).
a) I need an HTML text box to expand/contract as the browser window expands/contracts, with a 'search' image icon to the right of it.
b) I need some signup/login buttons right justified
c) I need the logo/text left justified.
So basically the flow is:
[#1 logo] [#2 menu items ] [#3 search-bar with icon] [#4 login/signup buttons]
And if the browser window expands, then #3 expands to fill in the space.
i.e.,
small desktop
[#1][#2][#3][#4]
big desktop
[#1][#2][<#3-------------------------->][#4]
ideally, I'd also like to figure out on mobile (tiny desktop) how to make it:
[#1][#4]
[#3---->]
This is the HTML I have (with other stuff removed to make it simple)
/* General CSS */
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding-top: 150px;
padding-bottom: 30px;
font-family: 'Open Sans', sans-serif;
font-size: 18px;
line-height: 1.42857143;
margin: 0;
}
ul {
list-style-type: none;
}
.clfix {
display: table;
content: " ";
clear: both;
}
.hide {
display: none;
}
/* Top bar */
.logo-separator {
float: left;
width: 1px;
border-right: 1px dashed #fff;
height: 80px;
padding-left:20px;
}
.navbar {
background-color: #124780;
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: 1030;
}
.navbar .navbar-brand {
text-decoration: none;
float: left;
height: 85px;
padding: 15px 15px;
font-size: 18px;
line-height: 20px;
}
.navbar .navbar-header {
position: relative;
}
.navbar ul li a, .navbar .navbar-brand {
position: relative;
display: block;
padding: 15px;
line-height: 20px;
color: #fff;
text-decoration: none;
}
.nav.navbar-nav {
float: left;
margin: 50;
padding-left:20px;
color: #fff;
}
.navbar-nav > .separator {
padding: 15px 2px;
line-height: 20px;
}
.navbar-nav .dropdown .dropdown-menu > ul > li.separator {
padding: 5px 10px;
color: #000;
}
.navbar-nav .dropdown .dropdown-menu {
text-align:center;
display: none;
position: absolute;
background: #fff;
border-bottom: 1px solid #124780;
z-index: 999;
}
.navbar-nav .dropdown .dropdown-menu > li:hover > a {
background-color: #8fb4de;
}
.navbar-nav > li {
float: left;
}
/*
.nav.navbar-nav li > a:hover, .nav.navbar-nav > li.open a {
color: #000;
}*/
.top-buttons {
margin: 0;
padding: 0;
float:right;
}
.searchBar {
margin: 0;
padding: 0;
float:right;
border-style:solid;border-width:2px;border-color:#FF0000;
display:inline-flex;
background-color: #124780;
position: absolute;
top: 0;
right: 0;
left: 0;
}
.navbar-nav-button {
display: inline-block;
float:right;
padding-top:18px;
padding-right: 5px;
padding-left: 5px;
}
.top-buttons .btn.btn-sm {
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
border-radius: 7px;
display: inline-block;
margin-bottom: 0;
font-weight: 400;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
width: 88px;
text-align: center;
}
.top-buttons .btn.btn-primary {
color: #fff;
background-color: #337ab7;
border-color: #2e6da4;
font-weight:bold;
}
.top-buttons .btn.btn-default {
color: #333;
background-color: #fff;
border-color: #ccc;
font-weight:bold;
}
.icon-bar {
background-color: #fff;
}
.navbar-nav2 {
display: inline-flex;
width: 100%;
padding-bottom: 5px;
padding-top: 0px;
position: absolute;
left: 0;
top: 85px;
background: #fff;
height: 35px;
overflow: hidden;
}
.navbar-line {
position: absolute;
bottom:0px;
width: 100%;
height: 1px;
background-color: #000;
left: 0;
}
/* Content */
.container {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.row {
margin-right: -15px;
margin-left: -15px;
}
.col-50 {
float: left;
width: 50%;
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
/* Panels */
.submenu {
xborder: 1px solid #ebf2f2;
border-radius: 5px;
margin-bottom: 20px;
background-color: #fff;
}
.submenu .panel-heading {
background-color: #24a3d1;
border: 11px solid #ebf2f2;
cursor: pointer;
text-align: center;
border-radius: 25px;
padding: 20px 15px;
}
.submenu .panel-heading.expanded {
border: 11px solid #ebf2f2;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.submenu .panel-heading .fa-plus, .submenu .panel-heading.expanded .fa-minus {
display: block;
}
.submenu .panel-heading.expanded .fa-plus, .submenu .panel-heading .fa-minus {
display: none;
}
.submenu .panel-heading:hover {
background-color: #166988;
}
.submenu .panel-heading .panel-title {
display: inline-block;
margin: 0;
font-size: 20px;
color: #fff;
}
.submenu .panel-heading i.fa {
font-size: 25px;
color: #fff;
}
.submenu .panel-heading i:first-child {
float: left;
}
.submenu .panel-heading i.fa-plus, .submenu .panel-heading i.fa-minus {
float: right;
}
.submenu .panel-body {
padding: 0;
overflow: hidden;
}
.submenu .panel-body.closed {
display: none;
}
.submenu .panel-body ul {
border: 1px solid #ebf2f2;
border-bottom: 12px solid #ebf2f2;
margin: 0;
padding: 0;
}
.submenu .panel-body ul li a {
display: block;
padding: 12px 8px;
color: #000;
/* border-left: 1px solid #24a3d1;
border-right: 11px solid #ebf2f2; */
border-left: 11px solid #ebf2f2;
border-right: 11px solid #ebf2f2;
border-bottom: 1px solid #ebf2f2;
text-decoration: none;
font-size: 16px;
}
.submenu .panel-body ul li a i {
font-size: 12px;
color: #24a3d1;
}
.submenu .panel-body ul li a:hover, .submenu .panel-body ul li a:hover i {
color: #fff;
background-color: #24a3d1;
text-decoration: none;
}
/* Modals */
.modal {
position: fixed;
left: 0;
top: 0;
z-index: 2000;
width: 100%;
height: 100%;
}
.modal-overlay {
position: relative;
left: 0;
top: 0;
background-color: #000;
opacity: .7;
width: 100%;
height: 100%;
}
.modal-content {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding-top: 60px;
padding-bottom: 60px;
padding-left: 20px;
padding-right: 20px;
}
.modal-body {
width: 100%;
background-color: #fff;
margin-left: auto;
margin-right: auto;
border-radius: 10px;
z-index:1000;
position:relative;
}
.modal-body .modal-row {
width: 100%;
}
.modal-body .close {
background: transparent;
border: 0;
float: right;
font-size: 20px;
color: #aeaeae;
cursor:pointer;
}
.modal-body .button-container {
width: 100%;
height: 30px;
padding: 5px 10px;
}
.modal .modal-title {
font-weight: 700;
text-align: center;
}
.modal .modal-subtitle {
text-align: center;
padding-top: 8px;
padding-bottom: 8px;
}
.modal-body .fields {
padding-top: 20px;
position: relative;
}
.modal-body .input-container {
display: block;
padding: 10px 30px;
font-size: 13px;
}
.modal-body .input {
display: block;
width: 100%;
height: 30px;
padding: 5px 10px;
font-size: 12px;
line-height: 1.5;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 3px;
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
-webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
.modal-body .button {
padding: 8px 12px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
display: inline-block;
margin-bottom: 0;
font-weight: 400;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
width: 100%;
}
.modal-body a.forgot {
float: right;
}
.modal-body .button.btn-primary {
color: #fff;
background-color: #337ab7;
border-color: #2e6da4;
}
.modal-body .button.facebook {
background-color: #3b5998;
color: #fff
}
.modal-body .button.google-plus {
background-color: #d9534f;
color: #fff
}
.modal-body .not-member {
text-align: center;
padding-top: 30px;
}
.modal-body .horizontal-line {
padding-top: 15px;
border-bottom: 2px solid #dedede;
}
.modal-body .bottom-message {
padding: 20px;
text-align: center;
font-size: 13px;
}
.modal-body .bottom-message {
background-color: #f8f8f8;
}
.modal-body .grey {
color: #a19997;
}
.navbar-nav .dropdown-menu > li > a {
color: #fff;
background-color: #4692e6;
text-align:left;
padding: 10px 30px;
border-bottom: 1px solid #fff;
}
.navbar-nav2 a {
text-decoration: none;
text-transform: uppercase;
font-size: 12px;
font-weight: bold;
top:220px;
}
.navbar-nav2 .custom {
text-decoration: none;
text-transform: uppercase;
font-size: 12px;
top:220px;
}
#media (min-width: 768px) {
.container, .modal-body {
width: 750px;
}
.top-buttons {
position: absolute;
top: 10px;
/* i took this out because it was screwing things up display: inline-flex; */
display: inline-flex;
}
.navbar-toggle {
display: none;
}
.navbar-nav > li:hover > a, .navbar-nav > li.active > a {
color: #aeaeae;
}
.navbar-nav > .dropdown {
position: relative;
}
.navbar-nav > .dropdown > .fa-caret-up {
position: absolute;
bottom: -4px;
left: 50%;
transform: translateX(-50%);
color:#4692e6;
display: none;
}
.navbar-nav .dropdown-menu > li > a {
width: 250px;
}
.navbar-nav > li:hover .dropdown-menu, .navbar-nav > li:hover > .fa-caret-up {
display: block;
padding:0;
}
.modal-body .vertical-line {
position: absolute;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
.modal-body .vertical-line .line-color {
width: 1px;
background-color: #eee;
height: 87%;
position: absolute;
left: 50%;
}
.modal-body .vertical-line .vertical-message{
display: block;
margin-top: 75px;
background-color: #fff;
color: #696463;
position: relative;
}
}
#media (min-width: 992px) {
.container {
width: 970px;
}
}
#media (min-width: 1200px) {
.container {
width: 1170px;
}
}
#media ( max-width: 767px) {
body {
padding-top: 110px;
}
.navbar {
background-color: #124780;
position: absolute;
}
.separator {
display: none;
}
.modal-body .vertical-line {
display: block;
width: 100%;
float: left;
padding: 10px;
position: relative;
text-align: center;
}
.modal-body .vertical-line .line-color {
position: absolute;
width: 90%;
background-color: #eee;
top: 50%;
height: 1px;
left: 5%;
}
.modal-body .vertical-line .vertical-message{
background-color: #fff;
color: #696463;
position: relative;
}
.logo-separator {
display: none;
}
.navbar {
max-height: 340px;
}
.navbar-nav, .navbar-nav .dropdown-menu, .navbar-nav2 {
display: none;
}
.navbar-nav.open, .navbar-nav .dropdown-menu.open, .navbar-nav2.open {
display: block;
}
.navbar .container {
width: 100%;
padding: 0;
margin: 0;
}
.navbar .container .navbar-header{
position: relative;
width: 100%;
}
.navbar-toggle {
position: relative;
float: right;
padding: 9px 10px;
margin-top: 8px;
margin-right: 15px;
margin-bottom: 8px;
background-color: transparent;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
}
.navbar-toggle .icon-bar {
display: block;
width: 22px;
height: 2px;
border-radius: 1px;
background-color: #fff;
}
.navbar-nav > .dropdown > .fa-caret-up {
display: none;
}
.navbar-header:before, .navbar-header:after{
content: " ";
}
.navbar-toggle .icon-bar+.icon-bar {
margin-top: 4px;
}
.navbar .navbar-nav, .navbar .navbar-nav .dropdown-menu > ul {
margin: 0;
padding: 0;
width: 100%;
}
.navbar .navbar-nav >li>a {
background-color: #78b1eb;
}
.navbar .navbar-nav >li:hover>a {
background-color: #a6c6e6;
}
.navbar .navbar-nav >li>.dropdown-menu {
margin-bottom:0;
margin-top:0;
padding-bottom: 0;
padding-top: 0;
position: relative;
padding-left:0;
}
.navbar .navbar-nav >li>.dropdown-menu>ul>li>a {
color: #fff;
background-color: #aacef2;
text-align:left;
padding: 10px 30px;
border-bottom: 1px solid #fff;
}
.navbar .navbar-nav2 {
padding-top: 0;
position: relative;
top: 0;
height: auto;
}
.navbar .navbar-nav2 a {
display: block;
padding: 10px 15px;
border-bottom: 1px solid #aaa;
}
.navbar .navbar-nav2 a:hover {
background-color: #fff1f1;
color: #5d5aff;
}
.navbar .navbar-nav2 span.separator {
display: none;
}
.navbar ul li {
float: none;
}
.top-buttons {
position: absolute;
top: 10px;
right: 60px;
}
.col-50 {
width: 100%;
}
}
<nav class="navbar">
<div class="container clfix">
<div class="navbar-header">
<button type="button" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img src=./mylogo.jpg><img src=./mytextlogo.gif></a>
<div class="logo-separator"></div>
</div>
<div id="navbar">
<ul class="nav navbar-nav">
<li class="dropdown">
Menu Item 1
</li>
<li class="separator">|</li>
<li class="dropdown">
Menu Item 1
</li>
<li class="separator">|</li>
<li class="dropdown">
Menu Item 3
</li>
<li class="separator">|</li>
</ul>
<div class="navbar-nav2">
<div class="navbar-line"></div>
<div class="container" style="width:100%" align=center>
Secondary Menu 1
Secondary Menu 2
</div>
</div>
</div><!--/.nav-collapse -->
//--------------------------------------------------------------------------------------------
/* THIS IS WHERE I WANT A SEARCH BAR WITH ICON TO EXPAND/CONTRACT BASED ON BROWSER WIDTH
//--------------------------------------------------------------------------------------------
<div class=searchBar>
<input name=something type=text width=40><img src=./searchbutton.jpg>
</div>
//--------------------------------------------------------------------------------------------
/* I WANT THESE BUTTONS 'RIGHT' JUSTIFIED HERE
//--------------------------------------------------------------------------------------------
<div >
<ul class="top-buttons" style="width:100%;border-style:solid;border-width:2px;border-color:#FF0000;float:right">
<li class="navbar-nav-button"><Button id="btn-login" class="btn btn-primary btn-sm">Log in</Button></li>
<li class="navbar-nav-button"><Button id="btn-signup" class="btn btn-default btn-sm">Sign Up</Button></li>
</ul>
</div>
</div>
</nav>
any help would be greatly appreciated!

Sounds like you will need judicious use of media queries:
#media screen and (min-width: 480px) {
body {
background-color: lightgreen;
}
}
http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
You've already indicated the three device sizes you need media queries for:
small desktop
[#1][#2][#3][#4]
big desktop
[#1][#2][<#3-------------------------->][#4]
mobile
[#1][#4]
[#3---->]
Now you just need to create media queries for those three sizes and set the CSS accordingly.
Mobile: Hide #2. Maybe play with floats to get #3 to display below the other two.
Big Desktop: Change #3 width (percentage based most likely)
Small Desktop: #1, #2, #3, #4 should all have the same width (percentage based most likely)
You can then use the width property to adjust the size of buttons on these different media widths:
http://www.w3schools.com/cssref/pr_dim_width.asp

Related

My dropdown menu is not showing upon hover

I'm having trouble making a dropdown menu. My dropdown menu just won't show upon hover, but if I change my display from none to block in .submenu ul li, the dropdown is in the right place.
Can anyone please help me?
* {
padding: 0;
margin: 0;
text-decoration: none;
list-style: none;
box-sizing: border-box;
}
body {
font-family: 'montserrat';
}
.container {
height: 80px;
width: 100%;
background: #34495e;
display: block;
float: right;
}
h1.logo {
font-size: 35px;
font-weight: bold;
color: white;
padding: 0 40px;
line-height: 80px;
float: left;
width: auto;
/* border: 1px red solid; */
}
.logo span {
color: #3498db;
}
nav ul {
float: right;
margin-right: 40px;
/* border: 1px red solid; */
}
nav li {
display: inline-block;
margin: 0 5px;
line-height: 80px;
text-align: center;
/* border: 1px red solid; */
}
nav a {
color: white;
font-size: 18px;
text-transform: uppercase;
padding: 7px 10px;
border-radius: 3px;
}
a.active,
a:hover {
border: 1px solid white;
transition: .5s ease-in;
}
nav #icon {
color: white;
font-size: 30px;
line-height: 80px;
float: right;
margin-right: 40px;
cursor: pointer;
background: #34495e;
border: none;
}
#media (min-width: 980px) {
h1.logo {
font-size: 32px;
padding-left: 60px;
}
nav ul {
margin-right: 20px;
}
nav a {
font-size: 17px;
}
nav #icon {
display: none;
}
div button {
display: none;
}
}
#media(max-width:980px) {
nav #icon {
display: block;
}
nav ul {
position: fixed;
width: 100%;
height: 100vh;
background: #2f3640;
top: 80px;
left: -100%;
text-align: center;
transition: all .5s ease-in;
}
.submenu ul {
top: 100%;
}
nav li {
display: block;
margin: 50px 0;
line-height: 30px;
}
nav a {
font-size: 20px;
text-align: center;
}
a.active,
a:hover {
border: none;
color: #3498db;
}
#btn1:hover {
border: none;
color: #3498db;
}
#btn2:hover {
border: none;
color: #3498db;
}
#btn3:hover {
border: none;
color: #3498db;
}
nav ul.show {
left: 0;
}
}
body {
background-image: url('../images/workout.jpg');
background-size: cover;
height: calc(100vh-80px);
}
div .connect {
background: #2f364e;
display: inline-block;
width: auto;
height: auto;
}
#btn1 {
background: #2f364e;
padding: .5em .7em;
border: none;
font-size: 20px;
color: white;
margin: 0 5px;
}
#btn2 {
background: #2f364e;
padding: .5em .7em;
border: none;
font-size: 20px;
color: white;
margin: 0 5px;
}
#btn3 {
background: #2f364e;
color: white;
padding: .5em .7em;
border: none;
font-size: 20px;
margin: 0 5px;
}
.submenu ul li {
display: none;
background: #34495e;
border-radius: 6px;
padding: 0 2px;
text-align: center;
opacity: 0.9;
transition: .5s ease-in;
}
.submenu ul {
margin: 0;
padding: 0;
}
.submenu li a {
margin: 0;
padding: .5em;
}
.main-nav li :hover .submenu {
display: block;
}
<header>
<nav class="container">
<h1 class="logo">Fitness Fir<span>st</span></h1>
<nav class="navbar">
<div class="main-nav">
<ul>
<li><a class="active" href="#">Home</a></li>
<li>About</li>
<li>Services
<div class="submenu">
<ul>
<li>Membership</li>
<li>Coaching</li>
</ul>
</div>
</li>
<li>Timetables</li>
<li>Contact</li>
<div class="connect" class="button">
<button id="btn1"><i class="fa fa-facebook"></i></button>
<button id="btn2"><i class="fa fa-instagram"></i></button>
<button id="btn3"><i class="fa fa-twitter"></i></button>
</div>
</ul>
<button id="icon"><i class="fa fa-bars" style="font-size:36px"></i></button>
</div>
</nav>
</nav>
</header>
Issue
In your CSS file, you have only hidden the li elements in your submenu:
.submenu ul li {
display: none;
background: #34495e;
border-radius: 6px;
padding: 0 2px;
text-align: center;
opacity: 0.9;
transition: .5s ease-in;
}
But here, you're trying to display the .submenu class, rather than the lis inside. In addition, the :hover selector is not attached to the li
.main-nav li :hover .submenu {
display: block;
}
Fix
To fix this we can change the above selector to the below, so that it is now un-hiding the submenu's lis, when you hover over the parent li (Services button)
.main-nav li:hover .submenu li {
display: block;
}

navigation drop down displays too far left

I have been working on fixing this but cannot figure out what I am missing. I would like for drop down list to show right below its parent. The list shows but all go to far left and forces the remaining nav items to drop down to another line. i have included a snippet for what is currently looks like and an image of what I want it to look like. Also, I have been trying to figure out how to add down fa fa-caret to nav items with drop down list. Please help!
.navbar {
background: linear-gradient(#9E0A0C, #EBEBEB);
padding: 10px;
border-top: solid 1px #000000;
overflow: hidden;
}
.navbar a {
text-decoration: none;
color: #ffffff;
font-weight: bolder;
font-size: 20px;
text-transform: uppercase;
padding: 3px 5px;
margin: auto;
/*float: left; may need to be removed to show borders*/
display: inline;
}
.navbar ul {
padding: 0;
margin-top: 0;
width: auto;
}
.navbar li {
border-left: solid 2px #000000;
display: inline;
list-style-type: none;
width: 800px;
padding: 0;
}
.navbar a:active {
background-color: #000000;
}
.navbar a:hover {
background-color: #ddd;
color: black;
font-size: 20px;
}
li:first-child {
border-left: none;
}
.dropdown {
display: block;
overflow: hidden;
/*float: left;*/
}
.list {
display: none;
min-width: 50px;
max-width: 150px;
z-index: 2;
box-shadow: 0 8px 16px 0 #e7e7e7;
background: #050243;
}
.list a {
color: #000000;
float: none;
font-size: 14px;
text-decoration: none;
display: block;
text-align: left;
background: #B6B6B6;
columns: 2;
}
.list a:hover {
background-color: #EEEEEE;
}
.dropdown:hover .list {
display: block;
}
form {
float: right;
padding: 0px;
margin: 0;
overflow: auto;
}
input {
border: solid 1px #000000;
background-image: url(pics/search.png);
background-repeat: no-repeat;
background-position: center right;
background-size: 15px;
border-radius: 5px;
padding: 5px 2px;
width: 250px;
}
<div class="navbar">
<ul>
<li>Home</li>
<li class="dropdown">Our Lodge
<div class="list">
NEWS
FACILITIES
OFFICERS
GUEST BOOK
</div>
</li>
<li class="dropdown">Events
<div class="list">
CALENDAR
BINGO
</div>
</li>
<li class="dropdown">Contact Us
<div class="list">
BECOME AN ELK
</div>
</li>
<form action="#">
<input type="text" placeholder="Search.." name="search">
</form>
</ul>
</div>
You can achieve this by first making the div.list element into an absolute positioned. The 'display:block' property was pushing all the other content down to the next row because the block element was taking up space.
As you see now the list is no longer pushing the content down but now it is not aligned to the correct nav item. We are also going to add a left:0 so that the div.list is to the left of the parent property.
Now the parent property needs a position of relative so that the left:0 on the child element is being positioned relative to the parent element.
.dropdown:hover .list {
display: block;
position: absolute;
left: 0;
}
.navbar li {
border-left: solid 2px #000000;
display: inline;
list-style-type: none;
width: 800px;
padding: 0;
position: relative;
}
The problem with your CSS code is, you missed to add position: relative and position: absolute to the .dropdown and .list selectors, which is compulsory to create dropdown. Try this code.
.navbar {
background: linear-gradient(#9E0A0C, #EBEBEB);
padding: 10px;
border-top: solid 1px #000000;
}
.navbar a {
text-decoration: none;
color: #ffffff;
font-weight: bolder;
font-size: 20px;
text-transform: uppercase;
padding: 3px 5px;
margin: auto;
/*float: left; may need to be removed to show borders*/
display: inline;
}
.navbar ul {
padding: 0;
margin-top: 0;
width: auto;
}
.navbar li {
border-left: solid 2px #000000;
display: inline;
list-style-type: none;
width: 800px;
padding: 0;
}
.navbar a:active {
background-color: #000000;
}
.navbar li:hover > a {
background-color: #ddd;
color: black;
}
li:first-child {
border-left: none;
}
.dropdown {
display: block;
overflow: hidden;
position: relative;
/*float: left;*/
}
.list {
display: none;
min-width: 50px;
max-width: 150px;
z-index: 2;
box-shadow: 0 8px 16px 0 #e7e7e7;
background: #050243;
position: absolute;
left: 0;
top: 100%;
}
.list a {
color: #000000;
float: none;
font-size: 14px;
text-decoration: none;
display: block;
text-align: left;
background-color: #B6B6B6;
columns: 2;
}
.list a:hover {
background-color: #EEEEEE;
}
.dropdown:hover .list {
display: block;
}
form {
float: right;
padding: 0px;
margin: 0;
overflow: auto;
}
input {
border: solid 1px #000000;
background-image: url(pics/search.png);
background-repeat: no-repeat;
background-position: center right;
background-size: 15px;
border-radius: 5px;
padding: 5px 2px;
width: 250px;
}
--> Please update following code in your existing file
.navbar {
background: linear-gradient(#9E0A0C, #EBEBEB);
padding: 10px;
border-top: solid 1px #000000;
}
.navbar a {
text-decoration: none;
color: #ffffff;
font-weight: bolder;
font-size: 20px;
text-transform: uppercase;
padding: 3px 5px;
margin: auto;
display: inline;
}
.navbar ul {
padding: 0;
margin-top: 0;
width: auto;
}
.navbar li {
border-left: solid 2px #000000;
display: inline;
list-style-type: none;
width: 800px;
padding: 0;
position: relative;
}
.navbar a:active {
background-color: #000000;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
li:first-child {
border-left: none;
}
.dropdown {
display: block;
overflow: hidden;
}
.list {
opacity: 0;
visibility: hidden;
min-width: 50px;
max-width: 150px;
z-index: 2;
box-shadow: 0 8px 16px 0 #e7e7e7;
background: #050243;
position: absolute;
top: 20px;
left: 0;
transition: 0.3s ease-in-out;
}
.list a {
color: #000000;
float: none;
font-size: 14px;
text-decoration: none;
display: block;
text-align: left;
background: #dddddd;
columns: 2;
}
.list a:hover {
background-color: #EEEEEE;
}
.dropdown:hover .list {
opacity: 1;
visibility: visible;
}
form {
float: right;
padding: 0px;
margin: 0;
overflow: auto;
}
input {
border: solid 1px #000000;
background-image: url(pics/search.png);
background-repeat: no-repeat;
background-position: center right;
background-size: 15px;
border-radius: 5px;
padding: 5px 2px;
width: 250px;
}
<div class="navbar">
<ul>
<li>Home</li>
<li class="dropdown">Our Lodge
<div class="list">
NEWS
FACILITIES
OFFICERS
GUEST BOOK
</div>
</li>
<li class="dropdown">Events
<div class="list">
CALENDAR
BINGO
</div>
</li>
<li class="dropdown">Contact Us
<div class="list">
BECOME AN ELK
</div>
</li>
<form action="#">
<input type="text" placeholder="Search.." name="search">
</form>
</ul>
</div>

CSS hold parent horizontal menu background

I am designing simple horizontal menu with html/css, see jsfiddle.net. The problem is that after hovering on li childrens i can not hold parent li background. See print screens below:
in this state, after hover on menu childrens, such as Settings or Applications, i can't hold background of parent block, such as Options :
You had added :hover effect for a tag and when you leave the a tag :hover is lost you can just add :hover to li tag and the :hover by using this you will not loose the :hover effect of the parent
.nav {
background: #C2E2EC;
height: 50px;
display: inline-block;
width: 100%;
margin: 0 0 10px 0;
padding: 0;
}
.nav li {
float: right;
list-style-type: none;
position: relative;
}
.nav li a {
font-size: 11px;
color: #000;
display: block;
line-height: 50px;
padding: 0 26px;
text-decoration: none;
font-family: Tahoma;
text-shadow: 0 0 1px rgba(255, 255, 255, 0.5);
}
/* changed :hover to li:hover */
.nav li:hover {
background-color: #2e2e2e;
}
#settings img {
margin: 0;
padding: 0;
}
#settings a {
height: 50px;
font-size: 11px;
}
#settings img {
width: 48px;
margin: 0px;
padding: 0px;
font-size: 11px;
}
#search {
width: 338px;
margin: 4px;
}
#search_text {
width: 297px;
padding: 12px;
font-size: 11px;
font-family: tahoma;
border: 0 none;
height: 34px;
direction: rtl;
text-align: right;
margin-right: 0;
color: white;
outline: none;
background: #1f7f5c;
float: right;
box-sizing: border-box;
transition: all 0.15s;
}
#search_text:focus {
background: rgb(64, 151, 119);
}
#search_button {
border: 0 none;
cursor: pointer;
float: left;
height: 34px;
margin-left: 5px;
margin-top: 5px;
padding: 0;
text-align: center;
width: 34px;
}
#options a {
border-left: 0 none;
}
#options > a {
background-position: 85% center;
background-repeat: no-repeat;
padding-right: 42px;
color: #fff;
}
.subnav {
visibility: hidden;
position: absolute;
top: 110%;
right: 0;
width: 200px;
height: auto;
opacity: 0;
transition: all 0.1s;
background: #232323;
margin: 0;
padding: 0;
}
.subnav li {
float: none;
}
.subnav li a {
border-bottom: 1px solid #2e2e2e;
color: #fff;
}
#options:hover .subnav {
visibility: visible;
top: 100%;
opacity: 1;
}
<ul class="nav">
<li id="options">Options
<ul class="subnav">
<li>Settings
</li>
<li>Application
</li>
<li>Board
</li>
<li>Options
</li>
</ul>
</li>
</ul>

How to display (<li>) menu items over divs - z-index not working

I am using a ul & li a bit like a select dropdown to trigger a JS function (not shown).
It's working fine - except the menu items appear BEHIND divs that are shown below them.
I've mocked up the problem here: http://jsfiddle.net/bf8ugef7/1/
I'm fiddling with z-index and position:absolute but can't see how to make it work.
Can anyone help?
Here is the HTML and CSS:
body {
font-family: sans-serif;
color: gray;
font-weight: 100;
}
div, li {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
li {
color: #333333;
text-decoration: none;
/* background-image: url("images/mullion.gif"); */
}
div.images {
border: 1px solid #555555;
/* padding-left: 5px; */
width: 100%;
float: left;
clear: left;
margin-bottom: 20px;
/*
background-image: url("images/iMullion.gif");
background-repeat: no-repeat;
*/
}
div.lowerText {
width: 100%;
}
div.btn {/* +filter */
float: right;
width: 195px;
cursor: default;
text-align: right;
/* margin-left: 1px; */
display: inline-block;
}
div.btn1 {
float: left;
width: 153px;
cursor: default;
text-align: center;
margin-left: 1px;
display: inline-block;
position: absolute;
color: black;
background-color: #79c1ee;
left: 182px;
}
div.btn2 {
float: left;
width: 20px;
display: inline-block;
color: white;
font-weight: 100;
text-align: center;
background-color: white;
cursor: default;
position: absolute;
left: 162px;
z-index: 100;
}
div.btn2 ul {
list-style: none;
position: absolute;
display: block;
margin: 0px;
padding: 0px;
z-index: 100;
}
div.btn2 ul li {
display: none;
cursor: pointer;
color: white;
height: 25px;
background-color: #79c1ee;
margin-top: 1px;
z-index: 100;
}
div.btn2 ul li:first-child {
margin-top: 0px;
display: inline-block;
width: 20px;
z-index: 100;
}
div.btn2 ul:hover {
height: 200px;
}
div.btn2 ul:hover li {
display: block;
z-index: 100;
}
div.btn2 ul li:hover {
background-color: #13A3E2;
z-index: 100;
}
/*
div.btn2 ul li:hover {
display: block;
width: 20px;
height: 100px;
}
*/
div.btn3 {
margin-left: 1px;
float: left;
width: 20px;
display: inline-block;
vertical-align: top;
text-align: center;
font-weight: 400;
color: white;
background-color: #13A3E2;
position: absolute;
left: 336px;
cursor: pointer;
}
div.btn3:hover {
background-color: red;
}
div.btn4 {
/* border: 1px solid black; */
padding-left: 5px;
float: left;
width: 153px;
display: inline-block;
color: #444444;
cursor: default;
background-color: white;
}
div.attr {
padding-left: 5px;
color: #444444;
background-color: #79C1ED;
float: right;
clear: none;
display: inline-block;
text-align: left;
}
div.filters {
width: 100%;
line-height: 1.8;
overflow: hidden;
display: block;
font-size: 14px;
text-decoration: none;
float: left;
}
div.toptext {
line-height: 2.2;
display: block;
max-height: 35px;
color: #444444;
background-color: #555555;/* matches border color */
color: white;
width: 100%;
padding-left: 5px;
cursor: not-allowed;
/* border: 1px solid pink; */
}
div.leftnav {
width: 350px;
float: left;
clear: left;
}
div#container {
padding: 0px;
margin: 0px;
}
<div class="leftnav">
<div class="images">
<div class="toptext">Filters
<div class="btn">+ filter</div>
</div>
<div id="container">
<div class="filters rem" id="f12">
<div class="btn4" id="b4f12">Pupil name</div>
<div class="btn2" id="b2f12">
<ul>
<li id="ddf_12_0">=</li>
<li id="ddf_12_1">></li>
</ul>
</div>
<div class="btn1" id="b1f12">Joe Bloggs</div>
<div class="btn3" id="if12">x</div>
</div>
<div class="filters rem" id="f13">
<div class="btn4" id="b4f13">Pupil name</div>
<div class="btn2" id="b2f13">
<ul>
<li id="ddf_13_0">=</li>
<li id="ddf_13_1">></li>
</ul>
</div>
<div class="btn1" id="b1f13">Bill Clinton</div>
<div class="btn3" id="if13">x</div>
</div>
</div>
</div>
</div>
Thanks
Emma
Try this code:
div.btn2 {
float: left;
width: 20px;
display: inline-block;
color: white;
font-weight: 100;
text-align: center;
background-color: white;
cursor: default;
left: 162px;
}
div.btn2 ul {
display: block;
margin: 0;
padding: 0;
}
div.btn2 ul li {
display: none;
cursor: pointer;
color: white;
height: 25px;
background-color: #79c1ee;
}
div.btn2 ul li:first-child {
display: inline-block;
border-top: none;
width: 20px;
}
div.btn2:hover li {
display: block;
position: absolute;
width: 20px;
border-top: 1px solid #fff;
}
div.btn2:hover li:first-child {
position: relative;
}
div.btn2 ul li:hover {
background-color: #13A3E2;
}
# Claudiu Yes it should be comment, but i dont have enough points to add comments
div.btn2 {
width: 20px;
display: inline-block;
color: white;
font-weight: 100;
text-align: center;
cursor: pointer;
left: 162px;
}
div.btn2 ul {
display: block;
margin: 0;
padding: 0;
}
div.btn2 ul li {
display: none;
cursor: pointer;
color: white;
height: 25px;
background-color: #79c1ee;
}
div.btn2 ul li:first-child {
display: inline-block;
width: 20px;
}
div.btn2:hover li {
display: block;
position: absolute;
width: 20px;
background: #000;
}
div.btn2:hover li:first-child {
position: relative;
}
div.btn2 ul li:hover {
background-color: #13A3E2;
}
i have updated the fiddle

Why am I missing a section?

So here's what I should be getting
But this is what I'm getting
As you can see the yellow section is missing. Here's my working example http://jsfiddle.net/Qk543/ but for some weird reason I cannot replicate it. Here's my code for the defective page.
<div class="wrap">
<div class="foot">
<ul class="styl">
<a id="html" href="#">
<li style="background: #F16529">
WORD
</li>
</a>
<a id="css" href="#">
<li style="background: #2AA9E0">
WORD
</li>
</a>
<a id="php" href="#">
<li style="background: #8892BF">
WORD
</li>
</a>
<a id="js" href="#">
<li style="background: #F0DB4F">
WORD
</li>
</a>
</ul>
</div>
</div>
And the CSS to it...
h1 {
padding: 80px 0 40px;
font-size: 40px;
line-height: 48px;
color: #505762;
}
.search h1 {
padding: 60px 0;
}
.slidey {
overflow: hidden;
padding: 30px 0;
background: #f3f5f8;
border-bottom: 1px solid #e5e8ed;
}
.js-enabled .slidey {
-webkit-transition: margin-top .2s;
-moz-transition: margin-top .2s;
transition: margin-top .2s;
}
.slidey b, .slidey label {
display: block;
font-weight: 500;
padding-bottom: 15px;
font-size: 15px;
font-weight: 500;
}
.slidey form, .slidey aside {
float: left;
width: 50%;
}
.slidey form input {
padding: 20px;
width: 75%;
}
.slidey li {
list-style: none;
}
.slidey a {
display: block;
text-decoration: none;
color: #717985;
}
.slidey a:hover {
color: #414b59;
}
.slidey li span {
float: right;
opacity: .6;
}
#top {
overflow: hidden;
padding: 20px 35px;
background: #fff;
border-bottom: 1px solid rgba(22,36,54,.1);
}
#top a {
float: left;
font-size: 13px;
font-weight: 500;
text-decoration: none;
color: #8895a7;
}
#top #logo:hover, #top ul a:hover, #top ul .active a, .posts .items li:first-child h2 a:hover, p a:hover {
color: #4171b1;
}
#top ul {
list-style: none;
float: right;
}
#top ul li {
float: left;
padding-left: 40px;
}
#top ul a {
display: inline-block;
color: #555f6d;
}
#top ul img {
display: inline-block;
vertical-align: middle;
position: relative;
top: -2px;
width: 16px;
height: 16px;
opacity: .4;
}
#top ul a:hover img {
opacity: .7;
}
#top ul a.active img {
opacity: 1;
}
/**
* Index page listing, category listing, search page results
*/
.items {
list-style: none;
}
.items > li {
padding: 70px 0 60px;
color: #97aec9;
background: #3c4552;
}
.posts .items > li:first-child {
background: #fff !important;
padding: 110px 0;
}
.items li h1 a, .posts .items > li:first-child h2 a {
color: #3d4551;
}
.items h1 {
padding: 0 0 8px;
}
.items h1 a {
text-decoration: none;
}
.items h2 {
font-size: 32px;
line-height: 41px;
}
.items h2 a {
display: block;
padding-bottom: 12px;
color: #fff;
color: rgba(176,200,236,.8);
text-decoration: none;
}
.items h2 a:hover {
color: #fff;
}
.items .content {
padding: 10px 0 0;
}
.items .content p {
padding-bottom: 15px;
}
/**
* Pagination
*/
.pagination {
overflow: hidden;
padding: 30px 0;
margin-bottom: 50px;
border-top: 1px solid rgba(22,36,54,.1);
border-bottom: 1px solid rgba(22,36,54,.1);
}
.pagination:empty {
display: none;
}
.pagination a {
float: left;
text-decoration: none;
font-size: 13px;
font-weight: 500;
color: #6f7b8b;
}
.pagination a:hover {
color: #3c4857;
}
.pagination a.next {
float: right;
}
/**
* Give some extra space to single-page wrappers
*/
.content.wrap {
padding-bottom: 50px;
}
.content.wrap ul, .content.wrap ol, .items li ul {
padding: 20px 30px;
}
.content.wrap ul ul, .content.wrap ol ol, .items li ul ul {
padding: 0 20px;
}
/**
* Footnotes and straplines
*/
.footnote, .commentlist time, .items footer {
display: block;
padding: 5px 0 15px;
color: #98a2b1;
font-size: 14px;
font-style: italic;
white-space: nowrap;
}
.footnote {
padding: 20px 0 40px;
}
/**
* Comment form
*/
ul.commentlist {
margin-bottom: 40px;
list-style: none;
border-top: 1px solid rgba(22,36,54,.1);
}
ul.commentlist .wrap {
position: relative;
}
ul.commentlist li {
padding: 40px 0;
border-bottom: 1px solid rgba(22,36,54,.1);
}
ul.commentlist time {
font-size: 13px;
}
ul.commentlist h2 {
font-size: 25px;
line-height: 33px;
}
ul.commentlist .counter {
position: absolute;
right: 0;
top: 0;
font-size: 25px;
font-weight: 300;
color: #cdd2da;
}
#comment {
overflow: hidden;
}
#comment label[for] {
display: none;
}
#comment p {
float: left;
width: 48%;
margin-right: 4%;
margin-bottom: 10px;
text-indent: 0;
}
#comment p + p {
margin-right: 0;
}
#comment p.textarea {
float: none;
width: 100%;
}
#comment input, #comment textarea {
width: 100%;
padding: 10px 15px;
font-size: 15px;
font-weight: normal;
border: 1px solid rgba(22,36,54,.2);
border-radius: 4px;
}
#comment input:focus, #comment textarea:focus {
outline: none;
background: #f7f9fc;
}
#comment textarea {
min-height: 150px;
max-height: 800px;
resize: vertical;
}
#comment button {
display: inline-block;
padding: 9px 18px;
background: #4e82ce;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 13px;
font-weight: 500;
}
#comment button:hover {
background: #3c6eb7;
}
*{padding:0;margin:0;}
body {
text-align: center;
padding-top: 50px;
font-family: "Helvetica Neue", sans-serif;
}
.foot{
bottom: 0px;
position: fixed;
width:100%;
margin: 0px;
font-weight: 400;
}
.foot li{
opacity: 0.95;
position: relative;
float: left;
list-style: none;
width: 25%;
height: 60px;
text-align: center;
}
.foot a{
font-size: 1.5em;
color: #fff;
height: 75px;
position: relative;
text-indent: 0;
text-decoration: none;
line-height: 60px;
}
.foot li:nth-child(1){
background: #B36C4E;
}
.foot li:nth-child(2){
background: #2AA9E0;
}
.foot li:nth-child(3){
background: #8892BF;
}
.foot li:nth-child(4){
background: #F0DB4F;
}
a:link{text-decoration: none}
a:hover{text-decoration: none}
a:visited{text-decoration: none}
a:active{text-decoration: none}
.content {
padding-right: 5%;
padding-left: 5%;
}
Any ideas?
You're using floats, so there's a good chance your last element is a pixel or so too wide for the container it's in and it's floating to the next line.
Try changing the width to 24% on each element and you'll probably see all four.
If you don't want to play with the width, try adding this to your css:
* {
box-sizing: border-box;
}
That includes any padding/margin in the width so that 25% width will be the true width instead of 25% plus padding/margin.