Make single item in menu exceed it's parent's height - css

I'm required to do design in which there is top page divided into 3 sections. First is header, under the header is border and under this border is menu. Problem is that part of border above highlighted menu should change color.
Now, i spent whole day on this little thing and I don't have any more ideas how can I make this work. I know I can make it work if I put there background image which have all these layers in it, but I don't think this is best way. This example is of course much simpler then real design. Do you have better ideas?
To be clear, here are images of how menu looks now when hovered and how it should look like:
HTML:
<div class="header"></div>
<div class="head_menu">
<div class="menu">
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
</ul>
</div>
</div>
CSS:
.header {
background-color: #AC3123;
height: 70px;
}
.head_menu {
background-color: #972B1E;
border-bottom: 7px solid #E8E8E8;
position: relative;
height: 55px;
}
.menu {
position: absolute;
width: 100%;
bottom: 0;
background: #4d5057
}
.menu ul {
overflow: hidden;
max-width: 300px;
margin: auto;
padding: 0;
}
.menu ul li {
float: left;
list-style: none;
}
.menu ul li a {
display: block;
padding: 15px 12px 14px 12px;
color: #fff;
}
.menu ul li a:hover {
color: #000;
background: #e8e8e8;
}

There are a lot of things you can do to resolve this issue.
One simple thing would be to not use border's for your dark-red strip. Instead, you could use a pseudo-element, and layer it underneath your li's using a correct z-index. Here's a jsFiddle: http://jsfiddle.net/rgthree/4BWNB/
HTML:
<div class="header"></div>
<div class="head_menu">
<div class="menu">
<ul>
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3</li>
</ul>
</div>
</div>
CSS:
.header {
background-color: #AC3123;
height: 70px;
}
.menu ul {
position:relative;
background: #4d5057;
border-bottom: 7px solid #E8E8E8;
text-align:center;
list-style: none;
padding:0px;
margin:0px;
}
.menu ul:before {
content:''; display:block; font-size:0px;
position:absolute; left:0px; top:0px; right:0px; height:7px; z-index:1;
background:#972B1E;
}
.menu ul li {
position:relative; z-index:2;
display:inline-block;
padding:0px;
margin:0x;
}
.menu ul li a {
display: block;
padding: 22px 12px 14px 12px;
color: #fff;
}
.menu ul li a:hover {
color: #000;
background: #e8e8e8;
}

I doubt this is the right way, but i got it to work using only css
I added a span into your list items
<ul>
<li><span></span>Menu 1
</li>
<li><span></span>Menu 2
</li>
<li><span></span>Menu 3
</li>
</ul>
and added this css
.menu ul li:hover span {
color: #000;
background: #e8e8e8;
}
.menu ul li span:hover {
background: #972B1E;
}
.menu li span {
position: absolute;
top: -8px;
height: 8px;
width: 73px;
}
http://jsfiddle.net/JR3xR/2/

Related

Dropdown Menu shifted to the right

I have a dropdown menu that is working well except for one minor bug that I cannot solve.
The first dropdown menu item appears normally. However, the second dropdown menu item is shifted slightly to the right. I am guessing that the margin-right that I set to the link caused the dropdown menu to shift slightly to the right. If that is the case, what can I do to go around the problem?
It's a simple nav menu that sets the position of the dropmenu item to absolute, and is hidden by the parent element's overflow:hidden feature. On hover, the dropdown menu is brought into view with overflow:visible.
The live site is here -> nav menu
CSS
#mainMenu {
position: relative;
}
#mainMenu ul {
list-style: none;
float: right;
background-color: #FFFFFF;
}
#mainMenu ul li {
position: relative;
display: inline;
float: left;
/*padding-right: 1.5em;*/
font-size: 1.2em;
zoom:1;
overflow: hidden;
}
#mainMenu>ul>li {
line-height: 2em;
}
#mainMenu ul li:hover {
overflow: visible;
}
#mainMenu ul li a {
float: left;
text-decoration: none;
color: black;
padding: 0 1em;
}
#mainMenu>ul>li:last-child a {
padding:0.4em 1em 0.4em 1em;
border-radius:4px;
background-color: #00b200;
color: #FFFFFF;
}
#mainMenu ul li a:hover{
text-decoration: none;
color: rgb(42, 160, 239);
}
#mainMenu ul ul{
position: absolute;
top: 2em;
left: 60%;
width: 10em;
margin-left: -3em;
height: auto;
border: solid #CCC;
border-width: 0 1px 1px;
}
#mainMenu ul ul:first-child{
padding-top: 2em;
}
#mainMenu ul ul li,
#mainMenu ul ul a {
display:block;
float:none;
border:0;
box-shadow:none;
text-align:center;
font-size: 1em;
padding: 0.4em;
text-align: left;
}
#mainMenu ul ul li:first-child {
border-top:1px solid rgb(72, 147, 196);
}
#mainMenu ul ul li {
border-top: 1px solid #e9e9e9;
}
#mainMenu a:active,
#mainMenu a:focus,
#mainMenu a:hover {
background:#F2F6FA;
color:#333;
}
HTML
<div id="nav-row">
<h1>
<a href="\">
Corporate Site
<span></span>
</a>
</h1>
<div id="mainMenu">
<ul>
<li>About
<ul>
<li class="company">Company Profile</li><li class="team">
The Team</li><li class="linsux">
Pricing Packages</li>
</ul></li>
<li>Services
<ul>
<li class="webDesign">Websites</li><li class="Emails">
Landing Pages</li><li class="Logos">
Logos</li>
</ul></li>
</li>
<li>Case Studies</li><li>
Blog</li><li>
Contact</li><li>
Free Web Analysis</li>
</ul>
</div>
</div>
It because you use to indent the submenu % of parent width which isn't the same. margin-left: -3em is a constant.
Use, for example:
left: -10px; /* I see the first submenu cca. 10px before the parent LI */
margin-left: 0;
Not sure why you indent by 60% and the move the submenu back using -3em.
try the following :
#mainMenu ul ul {
left: 39% !important;
}
Or
#mainMenu ul ul {
left: 0;
margin-left: 0;
}

Dropdown menu: Submenu name is below the menu bar and not within the nav box

I've coded a css dropdown menu and cant seem to get the name "LOGOS" to stay within the green box when I hover over the word "Illustration". I've made the word 5em so I can see it. Cant get it to stay in the box...no control of it's position. Can you help?
Thanks,
T.
<div id="nav-bar-sm-cont">
<ul id="sm-nav">
<li id="home">HOME</li>
<li id="about">PROFILE</li>
<li id="illustration">ILLUSTRATION
<ul>
<li id="logos">LOGOS</li>
</ul>
</li>
<li id="billboards">BILLBOARDS</li>
<li id="six-mo">6 MO BREAKFAST</li>
<li id="cal">ARTSHOW</li>
<li id="church">CHURCH</li>
<li id="contact">CONTACT</li>
<li id="cat-ill">CAT ILLUSTRATION</li>
<li id="contact-cat">CONTACT CAT</li>
</ul>
</div>
<!--end nav bar sm container -->
/* START small NAV bar **************************/
#nav-bar-sm-cont { position: absolute;
width: 1000px;
height: 100px;
}
#sm-nav li { position: relative;
top: 30px;
left: 35px;
font-size: .6em;
line-height: 250%;
letter-spacing: 0.3em;
list-style-type: none;
float: left;
}
#sm-nav a:link{ text-decoration:none;
color:silver;
background-color:transparent;
padding: 5px 5px;
}
#sm-nav a:visited {text-decoration:none;
color: #9781B7;
padding: 5px 5px;
background-color: transparent;
}
#sm-nav a:hover {text-decoration:none;
color: #fff;
background-color:#a7d6d5;
padding: 5px 5px;
}
#sm-nav a:active {text-decoration:none;
color:#fff;
background-color: green;
padding: 5px 5px;
}
/*start drop down************************************/
#sm-nav li ul { position:relative;
list-style-type: none;
display: none;
}
#sm-nav li:hover ul { position: absolute;
background: green;
padding: 5px 5px;
display:block;
font-size: 5em;
width: 103px;
height: 10px;
}
/*end drop down*****************************************/
/* END small NAV BAR *****************************/
The problem is that your CSS for the li is affecting both the parent li and the child. To fix that just change:
#sm-nav li {
to
#sm-nav > li {
Now that CSS will only affect the parent li and you're free to adjust the CSS for the child however you want like this:
#sm-nav li:hover ul li { }
JSFiddle

Different alignment of Top menu and submenu

Hi I am trying to keep my top navigation menu centered while left aligning the submenus that come out. What do i have to change in order to accomplish this? THanks!
<div id="container">
<ul id="nav">
<li>Home</li>
<li>Services <img src="images/tri2.gif">
<ul>
<li>Massages</li>
<li>Body Treatments</li>
<li>Facials & Waxing</li>
<li>Hair & Nails</li>
</ul>
</li>
<li>Packages <img src="images/tri2.gif">
<ul>
<li>Linky</li>
<li>Linky</li>
<li>Linky</li>
<li>Linky</li>
<li>Linky</li>
<li>Linky</li>
</ul>
</li>
<li>Specials</li>
<li>Contacts</li>
</ul>
</div>
Here is the CSS:
#container {
width: 740px;
margin: -16px auto;
padding: 0 0 0 0px;
font: 100% Helvetica, Arial sans-serif;
font-size:14px;
}
ul#nav {
line-height: 23px;
padding: 0;
}
ul#nav li {
float: left;
position: relative;
list-style: none;
background: #006666;
}
ul#nav li a {
width: 146px;
display: block;
border: 1px solid #000;
text-align: center;
text-decoration: none;
color: #fff;
}
ul#nav li:hover {background: #990000;}
ul#nav ul {
position: absolute;
padding: 0;
left: 0;
top: 23px;
visibility: hidden;
}
ul#nav li:hover ul {visibility: visible;}
ul#nav a:hover {color: yellow;}
http://jsfiddle.net/chuckie365/5LuCA/
what you need here is an additional CSS targeting that a elements:
ul#nav ul li a {
text-align:left;
}
Heres is the demo http://jsfiddle.net/5LuCA/10/

How do i make the whole tile(.ie the tab in the nav menu) part of the hyperlink

I have made this nav menu based on the Windows 8 concept.
i now want that the whole tile becomes part of the hyperlink. So then if we click anywhere on the tile it will take us to the linked site.
Code is here on JS Fiddle: http://jsfiddle.net/2Lkdy/
// html
<div class="div1">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
</div>
// css
.div1 {list-style: none;
margin-left:14%;
margin-right:auto;
margin-bottom:auto;
margin-top:auto;
text-decoration:none;
display:block;}
.div1 li {
display: inline;
float: left;
padding: 3em;
color: #000;
font-family: "Open Sans","Century Gothic","Trebuchet MS","Ubuntu","sans-serif";
font-weight: 400;
font-size: 18pt;
-webkit-transition: all 0.5s;
width:85px;
}
.div1 ul li:hover{
padding: 80px;
margin-top: -20px;
-webkit-transition: all 0.5s;
}
.div1 ul li a {
color: #000;
text-decoration: none;
}
.div1:hover ul:hover li{
opacity:0.5;
}
.div1:hover ul:hover li:hover{
opacity:10;
}
.div1 ul li:nth-of-type(1){
background:#CB4F1E;
}
.div1 ul li:nth-of-type(2){
background:#D3711B;
}
.div1 ul li:nth-of-type(3){
background:#94B339;
}
.div1 ul li:nth-of-type(4){
background:#68B43F;
}
#media screen and (max-width: 480px) {
.div1 {
position: relative ;
min-height: 70px;
}
.div1 ul {
width: 180px;
padding: 5px;
position: absolute;
top: 0;
overflow: hidden;
left: 0;
border: solid 1px #aaa;
background: url("threelines_48_3.png") no-repeat 10px 11px;
background-position:left 10px;
box-shadow: 0 1px 2px rgba(0,0,0,.3);
opacity:1;
min-height: 40px;
}
.div1 li {
display: none; /* hide all <li> items */
margin: 0;
opacity: 1;
}
.div1 ul:hover {
box-shadow: 0 1px 2px rgba(0,0,0,0);
background:transparent;
border: 0px solid #000;
}
.div1 ul:hover li {
display: block;
margin: 0 0 5px;
opacity: 1;
height: 20px;
padding:4px;
text-align: center;
}
.div1 ul li{
width:180px;
padding:4px;
margin-top:2px;
opacity:1;
height:20px;
}
.div1 ul li:hover{
opacity: 1;
height:20px;
padding:4px;
text-align: center;
}
.div1 ul li:nth-of-type(1){
background:#CB4F1E;
}
.div1 ul li:nth-of-type(2){
background:#D3711B;
}
.div1 ul li:nth-of-type(3){
background:#94B339;
}
.div1 ul li:nth-of-type(4){
background:#68B43F;
}
}
formatted.
Try something like this:
JSFiddle Demo
HTML:
<ul>
<li class="item1">1</li>
<li class="item2">2</li>
<li class="item3">3</li>
<li class="item4">4</li>
</ul>
CSS:
* {margin:0; padding:0; }
ul { width:400px; float:left }
li { float:left; list-style:none;}
li a { display:block; width:200px; height:200px; }
li.item1 a { background:red; }
li.item2 a { background:orange; }
li.item3 a { background:lime; }
li.item4 a { background:blue; }
li a:hover { opacity:0.5;}
Explanation:
By default the a element is inline, so if you want to give it a height and width then you need to make it either display:block or display:inline-block for the height/width to actually work and make the whole thing clickable.
You have invalid HTML. I have corrected it here: http://jsfiddle.net/M9nrL/2/
<div class="div1">
<ul>
<li>Item 1
</li>
<li>Item 2
</li>
<li>Item 3
</li>
<li>Item 4
</li>
</ul>
</div>
And added this CSS:
.div1 ul li a {
color: #000;
text-decoration: none;
display: block;
line-height: 100%;
}
The a element is defaulted to inline, which means its height and width are the lenght and height of the text inside it. But by setting display to block, the elements(a) height and width are set to its parent(li).
Also added line-height : 100%; to vertically align your text. (This will only work if your text fits in a single line)

how to position links at the bottom in a fixed height list

I would like to have a menu with an height of 100px with separators. I've put my menu in a unordered list and added a border-right to the li. So far so good but I can't find how to align my links at the bottom ?
HTML
<div id="menu">
<ul>
<li id="logo"></li>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
CSS
#menu {
background:#5a5a5a;
height:100px;
left:0px;
position:fixed;
top:50px;
width:100%;
}
#menu ul {
list-style-image: none;
list-style-type: none;
margin:0px;
}
#menu li {
border-right:1px solid #c6c6c6;
display:inline-block;
height:100px;
}
#menu ul li a {
color:#fff;
line-height:100px;
margin:0 10px;
padding:0 15px;
text-decoration:none;
vertical-align:bottom;
}
#menu ul li a:hover {
background:#c6c6c6;
color:#fff;
}
Thanks
I've always disliked the inline-block method, so I'm using floats for this instead. See if this is what you want (I've taken the liberty of making the anchors expand out to the size of the list items). http://jsfiddle.net/gSMVA/
The code:
#menu {
background: #5a5a5a;
height: 100px;
left: 0px;
position: fixed;
top: 50px;
width: 100%;
}
#menu ul {
list-style: none;
margin: 0px;
}
#menu li {
border-right: 1px solid #c6c6c6;
height: 100px;
float: left;
}
#menu ul li a {
color:#fff;
padding: 0 25px;
height: 100px;
display: block;
text-decoration:none;
/* Height * 2 - font size */
line-height: 188px;
font-size: 12px;
}
#menu ul li a:hover {
background: #c6c6c6;
color: #fff;
}
#menu li {
border-right:1px solid #c6c6c6;
display:inline-block;
height:20px;
padding-top:80px
}
#menu ul li a {
color:#fff;
line-height:20px;
margin:0 10px;
padding:0 15px;
text-decoration:none;

Resources