I have been trying to design a dropdown menu like following for my wordpress theme using CSS.
I have manged to create the dropdown but I cannot figure out how to create the curve using CSS and make the background color look transparent like in the image above.
To make it look transparent I tried opacity:0.4; filter:alpha(opacity=40); but it doesn't look near the dropdown menu above.
Could you please tell me how to make my dropdown look like the one in the image and make it responsive too?
Thanks
Here's my Code:
You can also check my code live here http://jsfiddle.net/MdpPd/
HTML
<nav>
<ul id="menu">
<li>Homepage</li>
<li>Google
<ul class="sub-menu">
<li>About Us</li>
<li>Programs</li>
</ul>
</li>
</ul>
</nav>
CSS
#menu {
display: block;
float: left;
margin: 0 auto 0;
width: 100%;
}
#menu ul {
list-style: none;
margin: 0;
padding-left: 0;
position: absolute;
background: #108BB6;
}
#menu li {
float: left;
position: relative;
list-style-type: none;
}
#menu a {
display: block;
line-height: 2.4em;
padding: 0 13px;
text-decoration: none;
}
#menu ul li {
display:block;
clear: both;
width: 265px;
}
#menu ul li:hover {
display: inline-block;
}
#menu li:not(:hover) ul {
display: none;
}
#menu ul ul {
box-shadow: 0 3px 3px rgba(0,0,0,0.2);
-moz-box-shadow: 0 3px 3px rgba(0,0,0,0.2);
-webkit-box-shadow: 0 3px 3px rgba(0,0,0,0.2);
display: none;
float: left;
position: absolute;
top: 2em;
left: 0;
z-index: 99999;
}
#menu ul ul ul {
left: 100%;
top: 0;
}
#menu ul ul a {
background: #dedede;
line-height: 1em;
padding: .5em .5em .5em 1em;
width: 10em;
height: auto;
}
#menu a:link {color:black;}
#menu a:visited {color:black;}
#menu a:focus {color:black; background: #ebdb00;}
#menu a:hover {color:white; background: #0C6481;}
#menu a:active {color:black; background: #ebdb00;}
I created the effect on the submenu using :before and :after.
Take a look at the demo.
It isn't the cleanest solution, but it works.
It needs some adjusting from your side, but I hope this helps you on the way.
For giving curve to the Border you can use the
"border-radius" property in css.
like
border-radius: 5px; you can also use the border-(left,right,top,bottom) variations.
For giving the opacity to items
try giving color as "background-color: rgba(Redvalue, greenvalue, bluevalue, opacity value)".
like
background-color:rgba(0, 255, 0, 0.8)
for the class=submenu use the below code to brig the skew
.submenu
{
transform: skew(30deg,20deg);
-ms-transform: skew(30deg,20deg); /* IE 9 */
-webkit-transform: skew(30deg,20deg); /* Safari and Chrome */
}
the submenu would also use opaicity setting as you had already put ,to brig about the color just use background color you would like as in
.submenu{
opacity:0.4; filter:alpha(opacity=40);
background:blue;
}
to bring about responsive layout simply use common frameworks eg twitter bootstrap,project zurb
For the skew 'the curve' see http://www.w3schools.com/css3/css3_2dtransforms.asp skew function
For the transparency: the example is less transparent (more like 0.9) and a lighter blue. You could try asking the artist/designer as they probably know this
#menu ul {
list-style: none;
margin: 0;
padding-left: 0;
position: absolute;
background: 10aBd6;
opacity: 0.9;
transform: skew(30deg,0deg);
-webkit-transform: skew(30deg,0deg);
-ms-transform: skew(30deg,0deg);
}
should get you going, you'll need to 'unskew' the Text inside
#menu ul li {
display: block;
clear: both;
width: 265px;
transform: skew(-30deg,0deg);
-webkit-transform: skew(-30deg,0deg);
-ms-transform: skew(-30deg,0deg);
}
Related
I am brand new at coding and am working on the final project for my class. It's like web page 101: the very basics in HTML5 and a little CSS. The demos we built for class look like they're from the 90s. Simple is fine, but I really want to challenge myself so I am attempting something more complicated.
TL;DR I have zero skills and my code is probably messy, please bear with me!
I ran into some trouble with the navigation menu I'm making. Maybe one of you can help me out :)
When I mouse over each item in the textured metal bar, blood splatter/paint/ketchup shows up. "CONTENTS" has a drop down menu that changes color when hovering over a list item in it.
But...
1) The text links are gone. I don't know what happened to them, but I do know that they had vanished BEFORE I added the Multiply opacity to the background-color. I think maybe it was after I had the BG color change on hover. I need the links to be solid white.
2) Is there any way to have "CONTENTS" show as red-splattered while I am hovering over the drop down list items? (as opposed to only when I am hovering over "CONTENTS" itself?)
Here is my code, and here is the sprite image
in case you need it.
EDIT: Here is the JSfiddle
http://jsfiddle.net/dkxovdj1/
Thanks so much!
> ul#nav {
margin:0 0 0 0;
padding:0;
list-style:none;
clear: both;
}
ul#nav ul.dd li a {text-decoration: none;
color: white;}
#nav li {
text-indent:-9999px;
display:inline;
float:left;
width: 495px;
position: relative;
}
#nav li a {
background:url(navbar_main2.jpg) no-repeat;
width: 495px;
height: 101px;
display:block;
}
#nav li.nav-1 {width:144px; height:154px;}
#nav li.nav-1 a:hover{background-position:0px -101px;}
#nav li.nav-1 a{background-position:0px 0px;}
#nav li.nav-2 {width:151px; height:154px;}
#nav li.nav-2 a:hover{background-position:-144px -101px;}
#nav li.nav-2 a{background-position:-144px 0px;}
#nav li.nav-3 {width:308px; height:154px;}
#nav li.nav-3 a:hover{background-position:-295px -101px;}
#nav li.nav-3 a{background-position:-295px 0px;}
#nav li ul.dd {
display: none;
position: absolute;
top: 101px;
left: 0px;
width: 100px;
height: 175px;
background-color: #524f4a;
mix-blend-mode: multiply;
line-height: 25px;
border-bottom-left-radius: 7px;
border-bottom-right-radius: 7px;
opacity: 0.7;
text-align: center;
}
#nav li:hover ul.dd{
display: block;
}
}
#nav li ul.dd li{
text-align: center;
position: relative;
margin: 0 px;
text-indent: 0;
width: 115px;
height: 25px;
}
#nav li ul.dd li a{
top: 7px;
background: none;
display: block;
width: 105px;
height: 25px;
background-color: black;
text-align: center;
border: 1px solid #CCC;
border-radius: 7px;
margin: 2px;
}
#nav ul.dd li:hover a:hover {background-color: #ffde43;}
ul.dd li {position: absolute; right: 24px; top: 8px;}
The issue with the text not showing up is a typo. You have the following in your fiddle:
#nav li:hover ul.dd {
display: block;
} /* <-- should not be here */
}
The hover state can be amended to be #nav li.nav-1:hover a instead of #nav li.nav-1 a:hover. That should get the red to display when hovering over the submenu
Demo: http://jsfiddle.net/w0hq3L06/
Edit:
Per the comment here,
background-color: #524f4a;
mix-blend-mode: multiply;
should be
background-color: rgba(82, 79, 74, 0.7);
background-blend-mode: multiply;
and the opacity on the #nav li ul.dd style should be dropped entirely.
Demo: http://jsfiddle.net/w0hq3L06/2/
I have an ul of navigation links nested in a div which is in turn nested into a 'header' div. My header div also contains a banner image, which should display in the top left corner of the website, and next to the banner I want my navigation links, which contain drop down menus when moused over.
Right now I am floating the banner to the left, and the nav links are automatically displaying next to the banner at my desktops resolution. The problem with this method is that once I resize the browser window the nav links begin to wrap around the banner and it looks terrible. Ideally I want the banner and the nav links to stay on the same line no matter the resolution of the device my site is viewed on.
Here is a jfiddle with an example of how my site displays. When I view the site at my default resolution of 1920x1080 it displays fine, but when I resize it does some funky stuff.
<!--- header div containing banner image and navigation bar --->
<div class="header">
<img id="banner" src="img/image.png" alt="Banner image displays here">
<div id="w">
<nav>
<ul id="ddmenu">
<li>About
<ul>
<li>Our Mission</li>
<li>The Staff</li>
<li>History</li>
</ul>
</li>
<li>Services
<ul>
<li>Donations</li>
<li>Volunteering</li>
<li>Housing</li>
</ul>
</li>
<li>Links
<ul>
<li>China</li>
<li>Japan</li>
<li>Canada</li>
<li>Australia</li>
<li>South America</li>
</ul>
</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
/* relevent css for header, banner image, and navigation */
body {font-size: 100%; line-height: 1; max-width: 100%; font-family: 'Source Sans Pro', sans-serif; margin:0px; padding:0px;}
a:link, a:visited, a:active {color:#FFFFFF; text-decoration: none;}
a:hover {color: #C0C0C0; text-decoration: none;}
.header {width: 100%; margin:0; background-color: #FFFFFF; padding-bottom: 10px; margin-bottom: 10px;}
#banner { float: left; max-width:100%; margin: 0; padding: 0; border: none;}
#w { max-width:50%; background-color: #FFFFFF; margin: 0; padding: 0; border: none; }
#ddmenu {
max-width: 50%;
height: 68px;
margin: 0 auto;
padding-top: 2px;
padding-bottom: 2px;
background: #fff;
cursor: pointer;
outline: none;
font-weight: bold;
color: #8aa8bd;
}
#ddmenu li { display: inline-block; float: left; font-size: 1.00em;}
#ddmenu li a {
display: block;
float: left;
padding: 0 10px;
line-height: 4.9em;
font-weight: bold;
text-decoration: none;
color: #FF0000;
}
#ddmenu li:hover > a { color: #FFF; background-color: #FF0000;}
#ddmenu li:hover ul {display: block;}
/*Fills gap between top level li and nested ul so that the above mouse hover pseudoclass selecting ul works*/
#ddmenu > li:after {
content: " ";
position: absolute;
bottom: -12px;
left: 0;
width: 100%;
height: 12px;
background: transparent;
}
#ddmenu ul {
position: absolute;
top: 80px;
width: 120px;
background: #fff;
display: none;
margin: 0;
padding: 4px 4px;
list-style: none;
border-radius: 3px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
/* tooltip arrow */
#ddmenu ul:after {
content: "";
width: 0;
height: 0;
position: absolute;
bottom: 100%;
left: 8px;
border-width: 0px 8px 8px 8px;
border-style: solid;
border-color: #fff transparent;
}
#ddmenu ul:before {
content: "";
width: 0;
height: 0;
position: absolute;
bottom: 100%;
left: 4px;
border-width: 0 10px 10px 10px;
border-style: solid;
border-color: rgba(0, 0, 0, 0.1) transparent;
}
#ddmenu ul li {
display: block;
width: 100%;
font-size: 0.9em;
}
#ddmenu ul li a {
display: block;
width: 100%;
padding: 6px 2px;
line-height: 1.4em;
}
I removed a lot of your styling because there is a lot of CSS to debug, but take a look at this Fiddle. I think it shows a simpler example of the effect you are going for and you may be able to work from the CSS.
Here's a breakdown of the most important parts of the CSS:
.header ul { list-style-type: none; }: don't show bullets
.header li { display: inline-block; }: make the list items sit next to each other horizontally instead of stacking in a column like normal
.header ul ul li { display: block; }: Not for submenus, though. Still want those in a stack.
.header ul ul { display: none; }: Don't show the nested lists...
.header li:hover ul { display: block; }: ...until we hover over the parent
.header li:hover ul { position: absolute; }: binds to nearest non-statically positioned ancestor
.header li { position: relative; top: 0; left: 0; }: which is its parent thanks to this trickery. Remember to specify top and left even if you're not moving anywhere or certain browsers will ignore you.
The rest is just fluff to make it look a little better. Since you're using inline-block to take care of most of the effect, you get resizing and wrapping for free.
I have a navigation dropdown element that I would like to make selectable - currently the link only works when the text is hovered and not the box surrounding it. Is there a way in which I can do this in CSS.
My CSS code:
.main-menu {
position: absolute;
top:90px;
right:0px;
text-align: right;
z-index: 2000;
}
.main-menu ul {
width: 50%;
background-color: #333;
display: inline;
margin: 0;
padding: 20px 5px;
list-style: none;
color: #fff;
}
.main-menu ul li {
display: inline-block;
margin-right: -10px;
position: relative;
padding: 17px 15px;
cursor: pointer;
color: #fff;
font-size: 14px;
font-weight: 700;
}
.main-menu ul li a {
color: #fff;
border: none;
}
.main-menu ul li a:hover {
color: #f1c40f;
}
/* sub menu */
.main-menu ul li ul {
position: absolute;
top: 25px;
left: 0;
min-width: 150px;
opacity: 0;
margin: 10px 0px;
padding: 17px 5px 0px 5px;
visibility: hidden;
text-align: left;
}
.main-menu ul li ul li {
display: block;
color: #fff;
margin: 0px -5px;
}
.main-menu ul li ul li:hover {
background: #666;
color: #f1c40f;
}
.main-menu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
Jsfiddle is: http://jsfiddle.net/9BdTK/
Method 1
You can simply move the <a></a> outside of <li>.
E.G:
<li>Home</li>
DEMO HERE
Note: I have only done this for the first two links.
Method 2
A better way to do this is the following:
HTML:
<div id="con">
<ul>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
</div>
CSS:
#con {
width: 100%;
background: #eee;
text-align: center;
}
ul {
list-style: none;
}
li {
display: inline-block;
width: 80px;
height: 50px;
outline: 1px solid #000;
}
a {
display: block;
height: 100%;
width: 100%;
}
Keep <a> inside and set it to display: block;, then set the width and height to 100% and this will take up the whole div creating a div link.
Demo of div link - DEMO HERE
Demo with hover - DEMO HERE
Hope this helps.
I have this on my site, but I also managed to do so from this site.
have a look :
Don't put padding in the 'li' item. Instead set the anchor tag to
display:inline-block; and apply padding to it.By Stussa
As said on : Make whole area clickable
Goodluck
i'm new with css and got an code for a 2 layer css menu but i want 3 layers or 4 but its a bit confusing with ul ul li ul li hover a and so on. please can you help me? I`m trying it for 3 days but i only get the main menu and the second layer correctly styled...
/* Hauptmenü */
ul {
text-align: left;
display: inline;
text-decoration:none;
z-index:1;
padding: 0px 0px 0px 0px;
list-style: none;
}
ul a {
text-decoration:none;
color: #fff;
z-index:1;
}
ul li {
font: bold 13px/18px sans-serif;
display: inline-block;
height:23px;
position: relative;
margin: 2px 8px 0px -4px;
padding: 1px 5px 0px 5px;
color: #fff;
cursor: pointer;
z-index:1;
}
ul li:hover {
background: #db0133;
z-index:2;
}
/* Hauptmenü Ende*/
/* Untermenü 1*/
ul li ul li {
font: normal 13px/18px sans-serif;
background: none;
margin: 0px 0px 0px 0px;
display: block;
color: #000;
z-index:1;
}
ul li ul li:hover {
font: normal 13px/18px sans-serif;
background: none;
margin: 0px 0px 0px 0px;
color: #db0133;
background:#f0f0f0;
text-decoration: none;
z-index:1;
}
ul li ul {
padding: 0;
position: absolute;
top: 25px;
z-index:2;
width: 180px;
margin: -1px 0px 0px 0px;
display: none;
opacity: 1;
visibility: hidden;
background: #fff;
border: 1px solid #dcdcdc;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
z-index:2;
}
/* Untermenü 1 Ende*/
/* Untermenü 2 */
ul li ul li ul li{
padding: 0;
position: absolute;
top: 25px;
z-index:2;
width: 180px;
margin: 0px 0px 0px 175px;
display: none;
opacity: 1;
visibility: hidden;
background: #fff;
border: 1px solid #dcdcdc;
}
ul li ul li:hover ul li {
display: block;
opacity: 1;
visibility: visible;
z-index:2;
}
/*Untermenü 2 Ende */
<!-- NAVIGATION ENDE -->
Without reading the full code I am pretty sure that I know what you mean with "confusing".
when you style a ul-element, it will also affect the inner ul-elements, right?
(Same for the li-elements)
I recommend you this solution:
Classify your ul - hierarchy like this in your HTML:
<ul class="navigation-layer-0">
<li>
First layer
<ul class="navigation-layer-1">
<li>
Second layer
<ul class="navigation-layer-2">
<li>Third layer</li>
</ul>
</li>
</ul>
</li>
Now in your CSS you can do the following to always style just one layer:
.navigation-layer-0 {
/* properties for your first layer go here */
}
.navigation-layer-0 > li {
/* properties for your first layer list-elements go here */
}
.navigation-layer-1 {
/* properties for your second layer go here */
}
.navigation-layer-1 > li {
/* properties for your second layer list-elements go here */
}
/* same for third layer */
".navigation-layer-x > li" means,
Matches any li element that is a direct child of an element .navigation-layer-x.
By this you only style the list-elements of one specific list-layer.
Hope this helps!
http://jsfiddle.net/zcfqu/
Been playing around with this piece of code for a while and am confused a bit.
How do I:
Change the color of the each submenu?
Make the submenu the same width as the main button?
HTML
<ul id="menu">
<li>This is the button
<ul class="submenu">
<li>Button one
</li>
<li>Button two
</li>
<li>Button three
</li>
</ul>
</li>
</ul>
Remove all floats and position:absolute
Check this demo
I just removed all floats (which was causing funny jumping of li and really not needed) and position:absolute (which was causing menu to shift sideways)
Also, I didn't read through all your CSS to find which background property is overriding which one, but I just removed them all and added new ones at bottom.
#menu > li { background-color: red; }
#menu > li:hover { background-color: green; }
.submenu li { background-color: blue; }
.submenu li:hover { background-color: yellow; }
EDIT 1
Its a good idea to use CSS shorthands and reduce CSS size and also make it more readable. Also, remove all incorrect CSS and you can also write border-radius: 2px 2px 2px 2px as border-radius: 2px (and save 12 bytes :O)
EDIT 2
CSS shorthands - MDN
font shorthand - W3C
background shorthand - W3C (scroll to the very bottomo of the page)
Change the color of the each submenu
ul.submenu a:hover {
background-color: red !important;
}
This changes on hover. If you want it always the same color remove :hover
Make the submenu the same width as the main button
ul.submenu, ul.submenu>li {
width: 100%;
}
This way you don't need to apply a fixed width. The browser will calculate it using parents adapted width.
Demo
Here is the correct approach in tackling your issues
DEMO http://jsfiddle.net/kevinPHPkevin/zcfqu/37/
// be more specific when targeting
ul#menu ul.submenu li a:hover {
background-color: green;
}
// set width to match button size
ul.submenu, ul.submenu>li {
width: 100%;
}
// assign classes for different coloured buttons. You could do this with css3 and `nth child` but it would limit your browser support considerably.
ul#menu .submenu li.btn1 a {
background: red;
}
ul#menu .submenu li.btn2 a {
background: yellow;
}
ul#menu .submenu li.btn3 a {
background: blue;
}
Take a look to this, I changed the background, and the "hover" and the width. It is correct ? Fiddle
ul#menu, ul#menu ul.sub-menu and ul#menu, ul.submenu --> width: 200px;
ul#menu li a for the background
I've set each li as 150px width. This has fixed the issue.
http://jsfiddle.net/andaywells/zcfqu/34/
ul#menu ul.submenu li {width: 150px;}
You can try the css as below with no changes on the html elements. I have added some comments for your references. Only 3 changes made on the css.
/*Initialize*/
ul#menu, ul#menu ul.sub-menu {
font-family: Helvetica;
background-color: #57AD68;
color: #FFFFFF;
border-radius: 3px 3px 3px 3px;
font-size: 12px;
font-style: normal;
font-weight: 400;
height: 40px;
line-height: 39px;
padding: 0 20px;
position: relative;
text-align: center;
vertical-align: bottom;
border-radius: 3px 3px 3px 3px;
border-style: none none solid;
border-width: 0 0 1px;
cursor: pointer;
display: inline-block;
float: center;
list-style-type: none;
text-decoration: none;
}
ul#menu, ul.submenu{
margin: 0;
padding: 0;
list-style: none;
float: left;
width: 134px; /*Adjust the sub menu width*/
}
ul#menu li{
float: left;
}
/* hide the submenu */
li ul.submenu {
display: none;
}
/* Main Button */
ul#menu li a{
display: block;
text-decoration: none;
color: #ffffff;
padding: 0 20px;
background: ; /*Remove the color here to avoid overlapped*/
float:right;
border-radius: 2px 2px 2px 2px;
font-family: Helvetica;
}
ul.submenu a:hover {
background: red;
}
/* show the submenu */
ul#menu li:hover ul.submenu{
display: block;
position: absolute;
float:right;
background-color:green; /*Adjust the color of sub menu.*/
}
ul#menu li:hover li, ul#menu li:hover a {
float: none;
background: ;
}
ul#menu li:hover li a:hover {
opacity:0.9;
}