简体   繁体   English

Div定位以实现流畅的布局

[英]Div positioning for a fluid layout

I'm trying to figure out how to get my planned layout. 我正在尝试弄清楚如何获得计划的布局。

I am trying to place a white border around the page (when scrolling content in the container the border should still be there on top). 我正在尝试在页面周围放置白色边框(在容器中滚动内容时,边框仍应位于顶部)。 Right now there is a border but content can still place over the border when resizing the browser window or if there is too much content in the content_area. 现在有一个边框,但是当调整浏览器窗口的大小或content_area中的内容过多时,内容仍然可以放在边框上。 Trying to get the layout pretty fluid so it will resize ok on any device just stacking content and the menu on top of eachother. 尝试使布局流畅,以便在任何将内容和菜单堆叠在一起的设备上调整大小。

I am also trying to center the content_area in the container. 我也试图将content_area放在容器的中心。

I think the nav_area staying at the fixed bottom center location always visible on top of any content is the only part working as planned right now. 我认为,nav_area始终位于所有内容的顶部,始终位于固定的底部中心位置,这是目前按计划工作的唯一部分。

Help much appreciated! 帮助非常感谢!

This is my html: 这是我的html:

<div id="container_border">

    <!-- CONTAINER -->
    <div id="container">
        <div id="content_area">

            <div class='thumb' data-container='project1_container'>
             </div>

            <div class='thumb' data-container='project2_container'>
             </div>

            <div class='thumb' data-container='project3_container'>
             </div>

            <div class='thumb' data-container='project4_container'>
             </div>

            <div class='thumb' data-container='project5_container'>
             </div>

            <div class='thumb' data-container='project6_container'>
             </div>
        </div>
        <div id="nav_area">
            <div id="nav">
                <div class='link' data-container='a_container'><a href="#">A</a>
             </div>
             <div class='link' data-container='b_container'><a href="#">B</a>
             </div>
             <div class='link' data-container='c_container'><a href="#">C</a>
             </div>
             <div class='link' data-container='d_container'><a href="#">D</a>
             </div>

            </div>
        </div>
    </div><!-- END CONTAINER -->
    </div>

This is my css: 这是我的CSS:

* {
margin: 0;
padding: 0;
font-family: futura;
}

#container_border {
position: fixed;
height: 100%;
width: 100%;
display: block;
background: #fff;
}

#container {
position: fixed;
display: block;
top:10px;left:10px;right:10px;bottom:10px;
vertical-align: center;
background: -webkit-linear-gradient(#FDC0B1, #EAA6C9); /* For Safari */
background: -o-linear-gradient(#FDC0B1, #EAA6C9); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#FDC0B1, #EAA6C9); /* For Firefox 3.6 to 15 */
background: linear-gradient(#FDC0B1, #EAA6C9); /* Standard syntax (must be last)*/ 

}

#content_area {
position: relative;
margin: 0 auto;
display: block;
width: auto;
height: auto;
}

.link {
text-align: center;
display: inline-block;
margin-right: 15px;
margin-left: 15px;
font-size: 1.5em;
}

.thumb { 
float: left;
background-color: #ccc;
display: block;
width: 250px;
height: 250px;
margin: 30px;
}

#nav_area {
position: fixed;
clear: both;
display: block;
height: auto;
z-index: 2;
left:10px;right:10px;bottom:10px;

}

#nav {
position: relative;
font-style: italic;
height: auto;
text-align: center;
margin-bottom: 10px;
}

#nav a {
color: #381cdf;
text-decoration: none;
}

#nav a:hover {
background-color: #fff;
}

JSFiddle Example JSFiddle示例

I assume this is what you are after (if not, please include a diagram) add this: 我假设这就是您想要的(如果没有,请附上图表)添加以下内容:

#container {
    overflow: hidden;
}

and change this to: 并将其更改为:

.thumb {
    width: 16.6%;
}

Change the 16.6%; 改变16.6%; on how you want your breakpoints, this is 100 / 6 . 关于您希望怎样的断点,这是100 / 6

http://jsfiddle.net/HPUb6/1/ http://jsfiddle.net/HPUb6/1/

I'm not pretty sure if is what you need but , this is the example: 我不太确定您是否需要,但这是示例:

http://jsfiddle.net/HPUb6/4/ http://jsfiddle.net/HPUb6/4/

using display:inline-block and text-align: center will center your thumbs. 使用display:inline-blocktext-align: center将使您的拇指居中。

#content_area {
 text-align:center;
}
.thumb { 
display: inline-block;
}

I made another changes on the layout using border and removing fixed positions 我使用border对布局进行了另一处更改并删除了固定位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM