I am testing a pages CSS by wrapping it in a media query.
#media screen and (min-width: 1200px)
If I don't wrap the CSS in the media query everything looks fine. If I do wrap it, 99% looks fine, but on some of my list items the formatting gets weird. Little dots appear as if I had set a list style, but I didn't. If I mouse over the li, the formatting clears up.
This doesn't happen if I don't add the media query. I'm trying to work formatting for a large and small screen, and am trying to get the large screen portion operational.
Here is a snippet of the code. I set it to use a min width of 600, since that was what would work in JFiddle. If you run this code as is, and then hover over the Sports, you'll notice some weird artifacts on the tabs. Move the cursor and the artifacts disappear. If you remove the encapsulating #media query the artifacts don't appear at all.
#media screen and (min-width: 600px) {
* {
margin: 0;
padding: 0;
}
body {
font: 300 15px/1.5"Helvetica Neue", helvetica, arial, sans-serif;
background: #FFF;
margin: 15px;
color: #000;
font-family: Arial, Helvetica, sans-serif;
font-size: small;
font-style: normal;
background-color: #fff;
border: 0;
}
#navigation {
width: auto;
margin: 0;
padding: 0;
border: 0;
clear: both;
}
#column_l {
position: relative;
float: left;
}
#column_r {
float: left;
}
#footer {
width: auto;
clear: both;
overflow: auto;
}
.float_right {
float: right;
}
article {
width: 100%;
margin: 0 auto;
background: #0047FF;
color: #fff;
border-radius: 5px;
box-shadow: 0 0 15px 2px #666;
}
article P {
background: #0047FF;
}
img {
max-width: 100%;
max-height: 100%;
}
section {
clear: left;
}
#main_content {
padding: 60px;
}
p {
margin: 15px 0;
}
#container {
width: 100%;
margin: 0;
background-color: #fff;
position: relative;
padding: 0;
}
#masthead {
text-align: right;
width: 100%;
background-color: #c5d5e5;
margin: 0;
padding: 0;
overflow: auto;
}
#page_content {
position: relative;
width: 98%;
border-top-width: 1px;
border-top-style: solid;
border-top-color: #CCAA77;
left: 20px;
}
/* Styles for Footer */
#footer p {
font-size: x-small;
text-align: center;
color: #393939;
margin: 10px;
padding: 1px;
}
#footer a {
color: #393939;
text-decoration: underline;
}
#footer a:hover {
color: #000;
text-decoration: none;
}
#footer {
background-color: #dfcfbf;
padding-bottom: 5px;
}
/* Styles for Masthead */
#masthead img {
float: left;
margin: 0;
padding: 0;
}
#masthead p {
font-size: small;
text-align: right;
color: #000;
margin: 0 0 0 0;
padding: 0;
}
/* Styles for Navigationcommon */
#navigationcommon {
background-color: #548EBE;
overflow: hidden;
}
#navigationcommon ul {
list-style-type: none;
width: 100%;
margin: 0;
padding: 0;
}
#navigationcommon li {
float: left;
}
#navigationcommon a {
color: #FFF;
text-decoration: none;
display: block;
padding: 5px;
border: 1px solid #D3D3D3;
background-color: #548EBE;
}
#navigationcommon a:hover {
color: #000;
text-decoration: none;
border: 1px solid #D3D3D3;
background-color: #ADD8E6;
}
/*Menu Color Classes*/
.green {
background: #6AA63B;
}
.yellow {
background: #FFFF00;
}
.red {
background: #CC6666;
}
.purple {
background: #CC99FF;
}
.siteblue {
background: #0047FF;
}
.blue {
background: #0292C0;
}
.purplered {
background: #66FFFF;
}
.yellowgreen {
background: #99FF33;
}
.orange {
background: #FF9900;
}
.bluegrey {
background: #669999;
}
/**
* horizontal navigation (SO)
*/
/* Targeting both first and second level menus */
#nav {
position: relative;
font-size: 13px;
}
#nav li {
list-style: none;
float: left;
}
#nav li a {
display: block;
padding: 8px 6px;
text-decoration: none;
}
#nav li a:hover {
background-color: red;
color: #FFF;
opacity: 1;
-webkit-border-top-left-radius: 30px 15px;
border-top-left-radius: 30px 15px;
-webkit-border-top-right-radius: 30px 15px;
border-top-right-radius: 30px 15px;
}
/* Targeting the first level menu */
#nav {
top: 158px;
min-width: 100%;
display: block;
height: 36px;
z-index: 1000;
position: absolute;
color: black;
background: url('images/sscbanner.png') 50% 50%;
}
#nav > li > a {} #nav a {
color: black;
}
/*added by me */
#nav li:hover {
background-color: red;
color: #FFF;
opacity: 1;
}
/*added by me */
#nav li {
max-width: 150px;
background-color: #CCCCCC;
-webkit-border-top-left-radius: 30px 15px;
border-top-left-radius: 30px 15px;
-webkit-border-top-right-radius: 30px 15px;
border-top-right-radius: 30px 15px;
list-style: none;
/*-webkit-border-radius: 30px 30px 0px 0px;
border-radius: 30px 30px 0px 0px;*/
border-left: 2px dotted black;
}
/* Targeting the second level menu */
#nav li ul {
color: black;
display: none;
position: absolute;
min-width: 100%;
background-color: #0047FF;
}
#nav li ul li {
display: inline;
/*added by me
line-height: 50px;*/
margin: 0;
padding: 10px 4px 0 4px;
color: black;
height: 50px;
text-align: center;
max-width: 150px;
background-color: #CCCCCC;
border-left: 2px dotted black;
list-style: none;
}
/*this is hitting all of the a elements */
#nav li ul li a {
border: none;
/*line-height: 50px;*/
margin: 0;
padding: 0 4px 0 4px;
color: black;
}
#nav li ul li a:hover {
background-color: red;
color: #FFF;
opacity: 1;
-webkit-border-top-left-radius: 30px 15px;
border-top-left-radius: 30px 15px;
-webkit-border-top-right-radius: 30px 15px;
border-top-right-radius: 30px 15px;
}
/* Third level menu */
#nav li ul li ul {
top: 0;
min-width: 100%;
}
ul.child {
background-color: #FFF;
}
/* A class of current will be added via jQuery */
#nav li.current > a {
background: #f7f7f7;
float: left;
}
/* CSS fallback */
#nav li:hover > ul.child {
left: 0;
top: 34px;
display: inline;
position: absolute;
text-align: left;
}
/*added by me */
#nav ul > li:hover > ul.child {
left: 0;
top: 50px;
display: inline;
position: absolute;
text-align: left;
}
#nav li:hover > ul.grandchild {
display: block;
}
.linktable {
border-spacing: 0;
table-layout: fixed;
border: thick;
border-style: solid;
}
#nav .linkul {
width: 500px;
}
#nav .linkrow {
height: 50px;
}
#nav .linkcell {
padding: 0px;
border: thin;
border-style: solid;
margin: 0px;
font-size: 12px;
width: 100px;
background-color: #FFFF66;
text-align: center;
}
#nav .nonlinkcell {
padding: 0px;
border: thin;
border-style: solid;
margin: 0px;
font-size: 12px;
width: 100px;
text-align: center;
}
#nav .tablelink {
padding: 0px 0px 0px 0px;
margin: 0px;
font-size: 12px;
text-align: center;
background-color: #FFFF66;
line-height: inherit
}
#nav li ul li ul table tr td {
line-height: 12px;
}
#nav li ul li ul table tr td a:hover {
background-color: #FFFF66;
color: red;
opacity: 1;
}
#nav ul li:first-of-type {
-webkit-border-top-left-radius: 30px 15px;
border-top-left-radius: 30px 15px;
-webkit-border-top-right-radius: 30px 15px;
border-top-right-radius: 30px 15px;
}
#nav ul li ul li:first-of-type {
-webkit-border-top-left-radius: 30px 15px;
border-top-left-radius: 30px 15px;
-webkit-border-top-right-radius: 30px 15px;
border-top-right-radius: 30px 15px;
}
#nav ul li:last-of-type {
-webkit-border-top-left-radius: 30px 15px;
border-top-left-radius: 30px 15px;
-webkit-border-top-right-radius: 30px 15px;
border-top-right-radius: 30px 15px;
}
#nav ul li:first-of-type {
border-left: none;
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:mso="urn:schemas-microsoft-com:office:office">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<title>My Testing Page Issue</title>
<meta name="author" content="Me" />
<style>
</style>
<script type="text/javascript">
</script>
<meta name="processowner" content="Me" />
<script type="text/javascript">
</script>
</head>
<body>
<div id="container">
<article onclick="">
<ul id="nav">
<li><a id="close" href="" onclick="showiframe(this.id); return false;">Fruit</a>
<ul class="child">
<li>
<a id="fruit" href="" onclick="showiframe(this.id); return false;">
<br />About</a>
</li>
<li>Oranges</li>
<li>
<br />Grapes</li>
<li>
<br />Apples</li>
<li>
<br />Bananas</li>
<li>
<br />Pears</li>
</ul>
</li>
<li><a id="close0" href="" onclick="showiframe(this.id); return false;">Sports</a>
<ul class="child">
<li>
<a id="sports" href="" onclick="showiframe(this.id); return false;">
<br />About</a>
</li>
<li>
<br />Hockey</li>
<li>Professional
<br />Soccer</li>
<li>Professional <br /> Football
<ul class="child">
<table class="linktable blue">
<tr class="linkrow blue">
<td class="linkcell blue">Miami Dolphins
</td>
</tr>
</table>
</ul>
</li>
<li>
<br />Tennis</li>
<li>
<a href="#">
<br />Bowling</a>
</li>
<li>
<a href="#">
<br />NASCAR</a>
</li>
<li>
<a href="#">
<br />Swimming</a>
</li>
<li>
<a href="#">
<br />Fishing</a>
<ul class="child">
<table class="linktable blue">
<tr class="linkrow blue">
<td class="linkcell blue">Fly Fishing
</td>
</tr>
</table>
</ul>
</li>
<li>Olympics
</li>
<li>Baseball
<ul class="child">
<table class="linktable blue">
<tr class="linkrow blue">
<td class="nonlinkcell blue">NY Mets</td>
<td class="linkcell blue"><a class="tablelink" href="">Boston Redsox</a>
</td>
<td class="nonlinkcell blue">Los Angeles Dodgers</td>
<td class="nonlinkcell blue">New York Yankees</td>
<td class="linkcell blue"><a class="tablelink" href="">San Diego Padres</a>
</td>
<td class="linkcell blue"><a class="tablelink" href="">Cincinatti Reds</a>
</td>
<td class="linkcell blue"><a class="tablelink" href="">San Francisco Giants</a>
</td>
<td class="nonlinkcell blue"></td>
<td class="nonlinkcell blue"></td>
<td class="nonlinkcell blue"></td>
</tr>
</table>
</ul>
</li>
</ul>
</li>
</ul>
</article>
</div>
</body>
</html>
Related
I'm having a little positioning error and I'm sure it's a simple fix, but after trying lots of different combinations of margin and padding, I can't get it perfect. The problem is I can't seem to get my drop-up menu (footer-nav ul ul) to move down 10px when it appears by hovering over #info. If I remove the margin from the css under #info, it drops the footer-nav ul ul down 10px where I need it, but it removes the 10px margin between the black box (streaks-content) and the footer-nav. Anyone know how to fix this? I appreciate it so so much! I don't know what I would do without you geniuses!
Here is the JS Fiddle: https://jsfiddle.net/fe2zk4L8/19/
Here is the html:
<header id="header">
<div id="nav">
<ul>
<li id="projects">PROJECTS
<ul>
<li id="one"> ONE </li>
<li id="two"> TWO </li>
<li id="three"> THREE </li>
<li id="four"> FOUR </li>
</ul>
</li>
</ul>
</div>
</header>
<div id="color">
<div id="streaks-content">
</div>
</div>
<footer id="footer">
<div id="footer-nav">
<ul>
<li id="info">INFO
<ul>
<li id="twitter">
TWITTER
</li>
<li id="instagram">
INSTAGRAM
</li>
<li id="email">
EMAIL
</li>
</ul>
</li>
</ul>
</div>
</footer>
Here is the css:
a {
text-decoration: none;
color: inherit;
display: block;
}
#header {
width: 100%;
position: fixed;
background-color: #FFFFFF;
margin: 0px;
padding: 0px;
top: 0;
left: 0;
text-align: center;
z-index: 10;
}
#nav {
width: 100%;
background-color: #FFFFFF;
}
#projects {
display: inline-block;
padding-bottom: 10px;
}
#nav ul {
font-family: Arial;
font-size: 15px;
font-weight: bold;
color: #000000;
list-style-type: none;
text-align: center;
margin: auto;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#nav ul ul {
width: 300px;
list-style-type: none;
font-weight: normal;
display: none;
}
#nav ul li:hover>ul {
display: block;
position: absolute;
text-align: center;
margin: 0 auto;
left: 0;
right: 0;
}
#one {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#one:hover {
background-color: black;
color: white;
}
#two {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#two:hover {
background-color: black;
color: white;
}
#three {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#three:hover {
background-color: black;
color: white;
}
#four {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#four:hover {
background-color: black;
color: white;
}
#footer {
width: 100%;
background-color: white;
position: fixed;
margin: 0px;
bottom: 0;
left: 0;
text-align: center;
z-index: 11;
}
#footer-nav {
width: 100%;
}
#info {
display: inline-block;
padding-top: 10px;
}
#footer-nav ul {
font-family: Arial;
font-size: 15px;
font-weight: bold;
color: #000000;
list-style-type: none;
text-align: center;
margin: auto;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 10px;
padding-left: 0px;
}
#footer-nav ul ul {
width: 300px;
list-style-type: none;
font-weight: normal;
display: none;
}
#footer-nav ul li:hover>ul {
display: block;
position: absolute;
bottom: 100%;
text-align: center;
margin: 0 auto;
left: 0;
right: 0;
}
#twitter {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#twitter:hover {
background-color: black;
color: white;
}
#email {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#email:hover {
background-color: black;
color: white;
}
#instagram {
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid black;
color: #000000;
background-color: white;
}
#instagram:hover {
background-color: black;
color: white;
}
#color {
width: 100%;
align-content: center;
}
#streaks-content {
background-color: black;
width: 300px;
height: 1000px;
display: block;
margin: 0 auto;
}
Please add to the following CSS selector #footer-nav ul li:hover>ul that rule padding-bottom: 0;
so, in total you should have:
#footer-nav ul li:hover>ul {
display: block;
position: absolute;
bottom: 100%;
text-align: center;
margin: 0 auto;
left: 0;
right: 0;
padding-bottom: 0;
}
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>
I have a website home page which has a menu (with a drop down) than an image (with text overplayed). For whatever reason the image is floating above the menu, so when you hover on the drop down it hides the menu behind the image.
HTML
* {
margin: 0;
padding: 0;
}
body {
background-color: #f3f3f3;
}
nav {
width: 100%;
height: 60px;
background-color: #fff;
position: fixed;
}
nav p {
font-family: arial;
color: #222;
font-size: 22px;
line-height: 55px;
float: left;
padding-left: 20px;
}
nav ul li {
list-style: none;
float: left;
position: relative;
text-transform: uppercase;
}
nav ul li a {
display: block;
padding: 21px 14px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li img {
float: right;
width: 8px;
padding-left: 6px;
position: relative;
top: 5px;
}
nav ul li ul {
display: none;
position: absolute;
padding: 10px;
background-color: #fff;
border-radius: 0px 0px 4px 4px;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
clear: both;
width: 180px;
border-radius: 4px;
}
nav ul li ul li a {
display: block;
padding: 11px 10px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li ul li:hover {
background-color: #eee;
}
.wrapper {
padding: 0px 0px
}
.search form {
list-style: none;
float: right;
position: relative;
padding-top: 8px;
padding-right: 20px;
}
.search input[type=text] {
width: 132px;
box-sizing: border-box;
border: 0.5px solid #ccc;
border-radius: 2px;
font-size: 16px;
background-color: white;
background-image: ('img/searchicon.png');
background-position: 10px 10px;
padding: 12px 20px 12px 40px;
}
.search input[type=text]:focus {
width: 300px;
}
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
h2 span.spacer {
padding:0 5px;
} here
<header>
<nav>
<p>Website Name</p>
<ul>
<li>Home</li>
<li>Resources <img src="img/dropdown.png">
<ul>
<li>About</li>
<li>Archives</li>
<li>Contact</li>
</ul>
</li>
<li>Login</li>
</ul>
<div class="search">
<form>
<input type="text" name="search" placeholder="Search...">
</form>
</div>
</nav>
</header>
<p style="line-height:400%"> </p>
<section>
<div class="image">
<img src="img/Shome.jpg" alt="Rowing" width="100% height="500px">
<h2><span>Site Name: <br /> Portal and Online Archives</span></h2>
</div>
</section>
Use z-index for making the dropdown above the image.An element with greater z-index will be on the top of that with lower z-index
* {
margin: 0;
padding: 0;
}
body {
background-color: #f3f3f3;
}
nav {
width: 100%;
height: 60px;
background-color: #fff;
position: fixed;
}
nav p {
font-family: arial;
color: #222;
font-size: 22px;
line-height: 55px;
float: left;
padding-left: 20px;
}
nav ul li {
list-style: none;
float: left;
position: relative;
text-transform: uppercase;
}
nav ul li a {
display: block;
padding: 21px 14px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li img {
float: right;
width: 8px;
padding-left: 6px;
position: relative;
top: 5px;
}
nav ul li ul {
display: none;
position: absolute;
padding: 10px;
background-color: #fff;
border-radius: 0px 0px 4px 4px;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
clear: both;
width: 180px;
border-radius: 4px;
}
nav ul li ul li a {
display: block;
padding: 11px 10px;
font-family: arial;
color: #222;
text-decoration: none;
}
nav ul li ul li:hover {
background-color: #eee;
}
.wrapper {
padding: 0px 0px
}
.search form {
list-style: none;
float: right;
position: relative;
padding-top: 8px;
padding-right: 20px;
}
.search input[type=text] {
width: 132px;
box-sizing: border-box;
border: 0.5px solid #ccc;
border-radius: 2px;
font-size: 16px;
background-color: white;
background-image: ('img/searchicon.png');
background-position: 10px 10px;
padding: 12px 20px 12px 40px;
}
.search input[type=text]:focus {
width: 300px;
}
.image {
position: relative;
width: 100%; /* for IE 6 */
}
h2 {
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
h2 span.spacer {
padding:0 5px;
} here
<header>
<nav>
<p>Website Name</p>
<ul>
<li>Home</li>
<li>Resources <img src="img/dropdown.png">
<ul>
<li>About</li>
<li>Archives</li>
<li>Contact</li>
</ul>
</li>
<li>Login</li>
</ul>
<div class="search">
<form>
<input type="text" name="search" placeholder="Search...">
</form>
</div>
</nav>
</header>
<p style="line-height:400%"> </p>
<section>
<div class="image">
<img src="img/Shome.jpg" alt="Rowing" width="100% height="500px">
<h2><span>Site Name: <br /> Portal and Online Archives</span></h2>
</div>
</section>
I am using HTML lists for dropdown menus in my navbar. The problem I have come across is that when the browser window is small, the dropdown goes off-screen to the left.
I am wondering on the best way to simply center it and stretch the content across 100% at a small screensize.
The problem is the notifications menu (hover over the little envelope).
I've put up some code I ripped from the site which gives you an idea: http://codepen.io/anon/pen/eBeYXd
Hover over the far-right item and the menu will appear, make the browser the size of a mobile screen and see the dropdown move off to the left being cut off.
Code below:
<div class="navigation-main">
<div class="container group">
<ul class="header-navbar">
<!-- notes test -->
<li class="dropdown pull-right alerts-box">
<img src="/templates/default/images/comments/envelope.png" alt=""/> <span class="badge badge-important">1</span> <b class="caret"></b>
<ul class="dropdown-menu">
<li><strong>liamdawe</strong> replied to "test a test test a test test a test test a test te…"</li>
<li class="divider"></li><li>Clear all</li>
<li class="divider"></li>
<li>See all</li>
</ul>
</li>
<!-- notes test -->
</ul>
</div>
</div>
CSS code:
*, *:before, *:after {
box-sizing: inherit;
}
.navigation-main {
position: fixed;
top: 0;
width: 100%;
height: 49px;
z-index: 10001;
background-color: #222;
}
.header-navbar {
list-style: none;
padding: 0;
margin: 0;
}
.header-navbar>li {
float: left;
}
.header-navbar>.pull-right {
float: right;
}
.header-navbar>li>a {
display: block;
color: #999;
padding: 14px;
}
.header-navbar>.active>a {
color: #FFF;
background-color: #000;
}
.header-navbar>li>a:hover {
color: #FFF;
text-decoration: none;
}
.header-navbar>.header-brand>a {
line-height: 0;
padding: 9px 14px;
margin-left: -14px;
}
.header-search {
padding: 9px 0;
}
.header-search .search-field {
width: auto;
background-color: #333;
border: 1px solid #5c5c5c;
outline: none;
line-height: 19px;
height: 30px;
color: #fff;
margin: 0;
}
.dropdown:hover .dropdown-menu {
display: block;
}
.header .dropdown-menu {
border-top-width: 1px;
}
.header .dropdown:hover .caret {
border-top-color: #FFF;
}
.header-avatar {
padding: 9px 0 9px 14px;
}
.dropdown {
position: relative;
}
.caret {
display: inline-block;
width: 0;
height: 0;
vertical-align: middle;
border-top: 4px solid #999;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
content: ""
}
.dropdown-menu {
position: absolute;
top: 49px;
left: 0;
z-index: 999;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 0;
list-style: none;
text-align: left;
background-color: #222;
border: 1px solid #000;
box-shadow: 0 3px 12px rgba(0, 0, 0, .15);
display: none;
}
.dropdown-menu li {padding: 0 15px 2px;}
.dropdown-menu .divider {
*width: 100%;
height: 1px;
padding: 0px;
margin: 9px 0;
*margin: -5px 0 5px;
overflow: hidden;
background-color: #383838;
}
.dropdown-menu a {
display: block;
clear: both;
line-height: 26px;
color: #999;
white-space: nowrap;
padding: 2px;
}
.dropdown-menu li>a:hover, .dropdown-menu li>a:focus {
text-decoration: none;
color: #fff;
}
.pull-right .dropdown-menu {
right: 0;
left: auto;
}
.pull-right {
float: right;
}
.nav-avatar {
vertical-align: middle;
background-color: #333;
}
play with min-width: or max-width: and probably allow your text to wrap
something like this
.dropdown-menu a {
display: block;
clear: both;
line-height: 26px;
color: #999;
min-width: 200px;
white-space: wrap;
padding: 2px;
}
I have a problem when my mouse hovering the dropdown menu, the dropdown container is gone. And also the menu dropdown is not steady. How can I fixed this? Please help me. Thanks a lot.
This is the JSfiddle.
.nav-bar {
position: fixed;
height: 30px;
top: 50px;
width: 100%;
background: #D9D9D9;
font-size: 13px;
color: #727272;
}
.line-nav img {
left: -50%;
top: 80px;
width: 150%;
height: 5px;
position: fixed;
}
#menu ul {
float: left;
margin: 7px 0 0 -20px;
font-weight: bold;
list-style: none;
display: inline;
}
#menu ul a {
text-decoration: none;
color: #727272;
padding-top: 0;
}
#menu ul a:hover {
color: #F4851E;
}
/* Dropdown Menu */
.dropdown_3columns {
margin: 5px auto;
float: left;
position: absolute;
left: -999em;
/* Hides the drop down */
text-align: left;
padding: 10px 5px 10px 5px;
border: 1px solid #777777;
border-top: none;
/* Gradient background */
background: #F4F4F4;
background: -moz-linear-gradient(top, #EEEEEE, #BBBBBB);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#EEEEEE), to(#BBBBBB));
/* Rounded Corners */
-moz-border-radius: 0px 5px 5px 5px;
-webkit-border-radius: 0px 5px 5px 5px;
border-radius: 0px 5px 5px 5px;
}
.dropdown_3columns {
width: 420px;
}
#menu ul:hover .dropdown_3columns {
left: -1px;
top: 25px;
}
/* Columns */
.col_1,
.col_2,
.col_3,
.col_4,
.col_5 {
display: inline;
float: left;
position: relative;
margin-left: 5px;
margin-right: 5px;
}
.col_1 {
width: 130px;
}
.col_2 {
width: 270px;
}
.col_3 {
width: 410px;
}
.col_4 {
width: 550px;
}
.col_5 {
width: 690px;
}
/* Right alignment */
#menu .menu_right {
float: right;
margin-right: 0px;
}
#menu ul .align_right {
/* Rounded Corners */
-moz-border-radius: 5px 0px 5px 5px;
-webkit-border-radius: 5px 0px 5px 5px;
border-radius: 5px 0px 5px 5px;
}
#menu ul:hover .align_right {
left: auto;
right: -1px;
top: auto;
}
/* Drop Down Content Stylings */
#menu p,
#menu h2,
#menu h3,
#menu ul ul {
font-family: Arial, Helvetica, sans-serif;
line-height: 21px;
font-size: 12px;
text-align: left;
text-shadow: 1px 1px 1px #FFFFFF;
}
#menu h2 {
font-size: 21px;
font-weight: 400;
letter-spacing: -1px;
margin: 7px 0 14px 0;
padding-bottom: 14px;
border-bottom: 1px solid #666666;
}
#menu h3 {
font-size: 14px;
margin: 7px 0 14px 0;
padding-bottom: 7px;
border-bottom: 1px solid #888888;
}
#menu p {
line-height: 18px;
margin: 0 0 10px 0;
}
#menu ul:hover div a {
font-size: 12px;
color: #015b86;
}
#menu ul:hover div a:hover {
color: #029feb;
}
<div class="nav-bar">
<div id="menu">
<ul>Home
<div class="dropdown_3columns">
<!-- Begin 2 columns container -->
<div class="col_2">
<h2>Welcome !</h2>
</div>
<div class="col_2">
<p>Hi and welcome here ! This is a showcase of the possibilities of this awesome Mega Drop Down Menu.</p>
<p>This item comes with a large range of prepared typographic stylings such as headings, lists, etc.</p>
</div>
</div>
<!-- End 2 columns container -->
</ul>
<ul>Product
<div class="dropdown_3columns">
<!-- Begin 2 columns container -->
<div class="col_2">Contain Product</div>
<div class="col_1">Contain Product</div>
<div class="col_2">Contain Product</div>
</div>
<!-- End 2 columns container -->
</ul>
<ul>Contact
</ul>
<ul>About Us
</ul>
</div>
<div class="line-nav">
<img src="http://www.iconsdb.com/icons/preview/caribbean-blue/square-xxl.png" />
</div>
</div>