user3664608
user3664608

Reputation: 333

Adding div inside div in HTML

I have a header which contains a div .Inside the div i have placed a background image using CSS.Now inside this div i have put my logo div .Till now every thing is OK.Now i want to add a dropdownmenu 40px away from the logo but the problem is whatever i am trying to add is coming down to the header ..I am not able to trace out..

Here is my HTML..

<div class="header-wrapper">
            <div class="header">
                <div class="logo"> <img src="image/logo.png" alt="logo"/>



                </div>
            </div>
        </div>

and this is my CSS..

html, body {
color: #6F6F6F;
font-family: Trebuchet MS;
font-size: 0.75em;
margin: 0 auto;
width: 100%;
padding: 0px !important; }

.img {
border: 0 none; }


.header-wrapper {
background: url("../image/header_bg.png") repeat-x scroll 0 0 rgba(0, 0, 0, 0);
float: left;
height: 77px;
margin: 0 auto;
position: fixed;
width: 100%;
z-index: 60001; }

.header {
clear: both;
height: 77px;
margin: 0 auto;
padding: 0 20px;
width: 960px; }

.logo {
float: left;
height: 75px;
margin: 1px 49px 0 0;
width: 75px; }

and this is my dropdown code in HTML that i want to add ..

<div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Services</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</div>
</div>

and Here is my CSS..

<style type="text/css">

a{
text-decoration: none;
 }
.menu{
font-family: Arial;
color: #515151;
width: 200px;
position: relative;
height: 40px;
text-align:left;
width: 202px;
margin: 0 auto;
}
.menu li a{
color: #515151;
display: block;
padding: 6px 15px;
cursor: pointer;
font-size: 14px;
}
.menu li a:hover{
background: #f44141;
color: #fff;
}
.sub{
background: #fff;
position: absolute;
z-index: 2;
width: 200px;
padding: 40px 0 3px;
border-radius: 3px;
box-shadow: 0 2px 4px #ddd;
border: 1px solid #ddd;
display: none;
}
a.hover-link{
width: 190px;
background: #fff;
font-size: 14px;
color: #515151;
position: absolute;
z-index: 110;
display: block;
padding: 10px 0 1px 10px;
height: 28px;
cursor:pointer;
border-radius: 5px 5px 0 0;
font-weight: bold;
 border: 1px solid #ddd;
}
.sub-options{
list-style:none;
margin:0px;
padding:0px;
font-size: 11px;
 }
   </style>

Here is the Fiddle i which i want dropdown menu beside logo image instead it is coming down side..

Fiddle

Please help me..

Upvotes: 1

Views: 560

Answers (4)

apsuva
apsuva

Reputation: 459

margin-left:40px;

<div class="header-wrapper">
<div class="header">
    <div class="logo">
        <img src="image/logo.png" alt="logo" />
    </div>
    <div class='menu'>
           <a class='hover-link'>Hover on Menu</a>
            <div class='sub'>
                <ul class='sub-options'>
                    <li><a href='#'>Home</a>
                    </li>
                    <li><a href='#'>About</a>
                    </li>
                    <li><a href='#'>Services</a>
                    </li>
                    <li><a href='#'>Contact</a>
                    </li>
                </ul>
            </div>
        </div>
</div>

your menu doesnt work? you have code for menu? check my code : http://fiddle.jshell.net/T8snP/5/

$('.menu').click(function(){
var curDd = $(".sub");
var dur = 350;
if(curDd.hasClass('shown')){
    curDd.fadeOut(dur/2);
    curDd.removeClass('shown');
} else {
    curDd.css({ opacity: 0.01, marginTop: 20 }).show().animate({ opacity: 1, marginTop: 0 }, { duration: 250, easing: "easeOutQuad" });
    curDd.addClass('shown');
}

return false;
});

$('body, html').click(function(){
    $('.shown').fadeOut(250).removeClass('shown');
});

Upvotes: 0

Vicky
Vicky

Reputation: 704

HTML

<div class="header-wrapper">
            <div class="header">
                <div class="logo"> <img width="100%" height="100%" src="https://i.sstatic.net/3Gtg9.jpg" alt="logo"/></div>
                  <div class='menu'>
<a class='hover-link'>Hover on Menu</a>
<div class='sub'>
<ul class='sub-options'>
<li><a href='#'>Home</a></li>
<li><a href='#'>About</a></li>
<li><a href='#'>Services</a></li>
<li><a href='#'>Contact</a></li>
</ul>
</div>
</div>



            </div>
        </div>

CSS to be changed...

.menu{
font-family: Arial;
color: #515151;
width: 200px;
position: relative;
height: 40px;
text-align:left;
width: 202px;
margin-left:40px;
}

HERE is A DEMO

Upvotes: 0

Omega
Omega

Reputation: 3038

http://fiddle.jshell.net/T8snP/2/

You need to move your menu out of your logo div... HTML:

<div class="header-wrapper">
    <div class="header">
        <div class="logo">
            <img src="image/logo.png" alt="logo" />
        </div>
        <div class='menu'>
<a class='hover-link'>Hover on Menu</a>

                <div class='sub'>
                    <ul class='sub-options'>
                        <li><a href='#'>Home</a>
                        </li>
                        <li><a href='#'>About</a>
                        </li>
                        <li><a href='#'>Services</a>
                        </li>
                        <li><a href='#'>Contact</a>
                        </li>
                    </ul>
                </div>
            </div>
    </div>
</div>

Then float the menu div left with this CSS as suggested in the comment:

.menu {float: left;}

Upvotes: 0

Ghost Answer
Ghost Answer

Reputation: 1498

You have to change as below In html page

<div class="header-wrapper">
    <div class="header">
        <div class="logo">
            <img src="image/logo.png" alt="logo" /></div>
            <div class='menu'>
<a class='hover-link'>Hover on Menu</a>

                <div class='sub'>
                    <ul class='sub-options'>
                        <li><a href='#'>Home</a>
                        </li>
                        <li><a href='#'>About</a>
                        </li>
                        <li><a href='#'>Services</a>
                        </li>
                        <li><a href='#'>Contact</a>
                        </li>
                    </ul>
                </div>

        </div>
    </div>
</div>

add float in menu css as

float:left;

and set the margin in menu css as

margin: 0 auto 0 -40px;

Hope this will help you.

Upvotes: 1

Related Questions