John Moore
John Moore

Reputation: 519

How do I position a div under a fixed position div

I have a position:fixed div at the top of my page, so that when a user scrolls down the menu always stays at the top.

How do I position another div element underneath the fixed div.

I'm using CSS and HTML.

layout

I'm using a smooth scrolling jQuery and need each section header to appear just under the menu bar.

Upvotes: 1

Views: 5072

Answers (2)

sergdenisov
sergdenisov

Reputation: 8572

Something like this — http://codepen.io/sergdenisov/pen/pJyMGb:

HMTL:

<div class="menu">
    <div class="menu-item">Home</div>
    <div class="menu-item">About</div>
    <div class="menu-item">Demo</div>
    <div class="menu-item">Contact</div>
</div>
<div class="menu-item menu-item_sub">Contact</div>

CSS:

body {
    height: 2000px;
}

.menu {
    position: fixed;
    background: blue;
    width: 100%;
}

.menu-item {
    display: inline-block;
    padding: 30px;
}

    .menu-item_sub {
        position: fixed;
        left: 0;
        top: 60px;
    }

Upvotes: 2

user2828274
user2828274

Reputation: 31

Do everything in absolute position domain.

.1(class){
position: absolute;
left: 10px;
top20px;
}

Like above classify each object with a class and set their position.

Upvotes: -1

Related Questions