user4752928
user4752928

Reputation:

Two DIVs on the same place

My "search box and social icons" are hidden behind my main-menu. This is probably because of my .hide-menu class. I have a jQuery plugin that makes the main-menu appear when scrolling-up and makes it disappear when scrolling-down. What I want to achieve is that the "search box and social icons" DIV show always and below the main-menu. Is this possible?

My FIDDLE... FIDDLE LINK HERE

.navbar-default .navbar-nav > .active > a,.navbar-default .navbar-nav > .active > a:focus,.navbar-default .navbar-nav > .active > a:hover {
    color: #fff;
}

.menu-container {
    background-color: #fff;
    border-bottom: 1px solid #000;
	border-top: 1px solid #000;
    min-height: 20px;
    position: relative;
}

.navbar-nav a:hover {
    color: #000;
}

.navbar-nav a:link {
    font-size: 12px;
    font-family: 'century schoolbook';
    color: #000;
    /*text-decoration: overline;
    text-decoration-color: #A10000*/
}

.brand-name a {
    text-decoration: none;
}

.brand-name img {
    max-width: 137px;
    padding: 8px;
/*position:absolute;*/
    left: 0;
}

ul {
    list-style-type: none;
}

.navbar-form input,.form-inline input {
    width: auto;
}

#nav.affix {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 10;
}

#sidebar.affix-top {
    position: static;
}

#sidebar.affix {
    position: fixed;
    top: 80px;
}

.navbar-default .navbar-nav > li > a {
    color: #A10000;
    font-family: 'LuzSans-Book';
    font-size: 15px;
	font-weight:bold
}

.navbar-default .navbar-nav > li > a:hover {
    background-color: #A10000;
    color: #000;
	margin-top:4px;
	margin-bottom:4px;
}

.navbar-default .navbar-nav > .active > a {
    background-color: #000;
	margin-top:4px;
	margin-bottom:4px;
}

.navbar-custom-social {
    height: 15px;
    float: right;
    clear: none;
    margin-right: 25px;
}

.navbar-fixed-top {
    padding-top: 0;
}


#search-social {
	margin-bottom:20px
}

header.site_header {
    box-shadow: 0 1px 6px rgba(0,0,0,.35);
    width: 100%;
    top: 0;
    left: 0;
    position: fixed;
    z-index: 999;
    -webkit-transition: top .5s;
    transition: top .5s;
    background-color: #fff;
}

header.site_header.hide-menu {
    top: -90px;
}
<header class="site_header root" id="nav">
        <div class="container">
            <div class="row">
                <div class="col-sm-12">
                    <div class="navbar navbar-default navbar-static">
                        <!-- <div class="clearfix container navbar-fixed-top"> -->
                        <div class="clearfix menu-container">
                            <div class="pull-right clearfix toggle_btn_wrap">
                                <a class="navbar-toggle" data-target=
                                ".navbar-collapse" data-toggle="collapse" href=
                                "#"><i class="fa fa-bars"></i></a>
                            </div>
                            <div class="pull-left brand-name">
                                <a href="#"><img alt="NAME" src=
                                "/images/LOGO.png"></a>
                            </div>
                            <div class="clearfix prevent-float"></div>
                            <div class="navbar-collapse collapse">
                                MENU ITEMS
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>
<div id="search-social" class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar navbar-default navbar-static">
                    <div class="clearfix search_and_social">
                        <div class="clearfix navbar navbar-custom-search">
                            SEARCH BOX
                        </div>
                        <div class="clearfix navbar navbar-custom-social">
                            SOCIAL ICONS
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

Upvotes: 0

Views: 1001

Answers (3)

yezzz
yezzz

Reputation: 3020

Easiest is probably to use sibling selector between .site_header and #search-social. Make sure that #search-social is positioned. Something like:

#search-social {
  margin-bottom: 20px;
  position: relative;
}

header.site_header ~ #search-social {
  top: 40px;
}
header.site_header.hide-menu ~ #search-social {
  top: 0px;
}

Example (with a testbutton): https://jsfiddle.net/7f6q75h8/2/

Note: Top styling needs some adjustment depending on the menu height.

Upvotes: 1

Rajesh Jangid
Rajesh Jangid

Reputation: 724

I don't know if this is what you want but may lead you in right direction. just added a jquery function to determine the state when menu bar is visible,

function adjustMenu() {
   if (!$('#nav').hasClass('hide-menu')) {
      $('#search-social').css('margin-top', $('#nav').height() + 'px');
   } else {
      $('#search-social').css('margin-top', '0px');
   }
}

this function is called on page load as well as inside the onscroll event of page

$(window).scroll(function() {
   adjustMenu();
});

here is the updated fiddle

there are better ways if you can edit in the plugin code you are using.

Upvotes: 0

Medda86
Medda86

Reputation: 1630

Maybe you can use position:absolute;

Else you can add a class on the wrapper when you wanna show or hide something.

.wrapper .active .div2{
   display:block;
}

Upvotes: 0

Related Questions