需要在标题后修复div的位置

时间:2015-04-02 05:47:48

标签: html css twitter-bootstrap twitter-bootstrap-3

我设计了以下页面,但主要问题是我不知道如何将主容器保留在标题下方。

正如您在演示中看到的我的容器在这里,有文本1和我的容器在这里,标题部分显示了文本2。只要主容器可见,菜单就会被停用。

Demo

.menu {
    position: absolute;
    width: 100%;
    height: 66px;
    max-height: 90px; //
    height: 50px; //
    margin: -30px auto;
    background: rgb(10, 15, 100); //
    z-index: -100;
}

.menu img {
    max-height: 30px;
}

.menu ul { //
    left: 0;
    margin: 0 auto;
    width: 80%;
    margin: -30px auto 0 auto;
    font-size: 16px;
    font-weight: bold;
    max-width: 1200px;
}

.menu ul li:first-child {
    border-left: 1px solid gray;
}

.menu ul li { //
    width: 140px;
    width: 14%;
    display: block;
    float: left;
    text-align: center;
    border-right: 1px solid gray;
    color: white;
    height: 50px;
    line-height: 70px;
    vertical-align: bottom;
}


.menu ul li a {
    color: white;
}

.menubtn {
    width: 30px;
    height: 30px; //
    opacity: 0.5;
    cursor: pointer;
}

.menubtn .fa {
    font-size: 26px;
    color: rgb(75, 0, 100)
}

#menubtn {
    position: absolute;
    top: 2px;
    left: 4px;
}

@media only screen and (min-width: 501px) {
    .topbar {
        display: none;
    }
    .menu ul li a {
        font-size: 14px;
    }
    #mybody{
    margin-top:8%;}
}

@media only screen and (max-width: 1200px) {
    .menu ul li a {
        font-size: 12px;
    }

}

@media only screen and (max-width: 888px) {
    .menu ul li a {
        font-size: 12px;
    }
}

@media only screen and (max-width: 685px) {
    .menu {
        height: 40px;
    }
    .menu ul {
        margin: 0;
    }
    .menu img {
        display: none
    }
    .menu ul {
        width: 100%;
    }
    .menu ul li {
        line-height: 40px;
        height: 40px;
        font-size: 13px;
    }
}

@media ( max-height : 480px) and (min-width: 480px) and (max-width:
    600px) {
    .menu {
        display: none;
    }
}

@media only screen and (min-width : 320px) and (max-width : 480px) and
    (orientation : landscape) {
    .menu {
        display: none;
    }
}



<header>
    <div class="container-fluid">
        <div class="row" style="background-color: black;">
            <div class="col-md-10 col-sm-8 col-xs-1">
                <div id="banner" style="margin-left: 49%;">
                    <img height="25px" width="25px"
                        src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRQVtGP5ULNel-_RtPVdF2aLmeKISd9ONVL1Gs81rGdeBzHgtNitQ"> <img height="40px;"
                        width="253px;" src="http://s3.amazonaws.com/contemporaryartgroup/wp-content/uploads/2013/10/Black-Magic.jpg">

                </div>
            </div>
            <div class="col-md-1">
                <div id="images" style="float: left;">
                    <a class="btn btn-social-icon btn-sm btn-facebook"
                        style="text-align: center;"
                        href="https://www.facebook.com"> <i
                        class="fa fa-facebook"></i>
                    </a> <a class="btn btn-social-icon btn-sm btn-twitter"
                        href="http://twitter.com"> <i
                        class="fa fa-twitter"></i>
                    </a> <a class="btn btn-social-icon btn-sm btn-google-plus"
                        href="https://plus.google.com"> <i
                        class="fa fa-google-plus"></i>
                    </a>
                </div>
            </div>
            <div class="container">
                <div class="row">
                    <div class=" col-md-12 col-sm-12 col-xs-12 search-container">

                    </div>
                </div>
            </div>
            <div class="row" style="background-color: orange;">
                <div class="col-md-12 col-sm-12 hidden-xs">

                    <div class="menu">
                        <img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQRTaQVZwEBQUXbqBiyDXUQWjms2PUI90JAGDMx7uexxi0pCWmjPA"
                            style="width: 100%; max-height: 40px;">
                        <ul id="idmenu">
                            <li ><a href="/"><i class="fa fa-home f24"></i>
                                    Item1</a></li>
                            <li><a href="/">Item2</a></li>
                            <li><a href="/">Item3</a></li>
                            <li><a href="/">Item4</a></li>
                            <li><a href="/">Item5</a></li>
                        </ul>

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

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

<div class="container">
    <div class="row">
        <div class="col-md-12">
            <p>My container is here, there is text 1</p>
               <p>My container is here, there is text 2</p>
               <p>My container is here, there is text 3</p>
               <p>My container is here, there is text 4</p>
               <p>My container is here, there is text 5</p>
               <p>My container is here, there is text 6</p>
               <p>My container is here, there is text 7</p>
               <p>My container is here, there is text 8</p>
               <p>My container is here, there is text 9</p>
               <p>My container is here, there is text 10</p>
               <p>My container is here, there is text 11</p>
               <p>My container is here, there is text 12</p>

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

1 个答案:

答案 0 :(得分:1)

CSS将.menu position:absolute更改为relative

.menu {
  position: relative;
  width: 100%;
  height: 66px;
  max-height: 90px;
  background: rgb(10, 15, 100);
}

DEMO