简体   繁体   English

DIV对齐和定位问题

[英]DIV alignment and positioning issue

I'm having a hard time on this DIV alignment and positioning. 我在进行DIV对齐和定位时遇到了困难。 I have a parent DIV width=980px(yellow) and child DIV's: left width=600px(red) and in right width=280px(green) . 我有一个parent DIV width=980px(yellow)和一个子DIV的: left width=600px(red)right width=280px(green) And in right DIV i want to display vertical arrangement of images(white boxes). 在右边的DIV中,我想显示图像的垂直排列(白框)。 Here the sample image: 这里是示例图片:

样本图片

Here's my code so far: JSFiddle 到目前为止,这是我的代码: JSFiddle

Thank you in ADVANCE! 先感谢您!

Question 1 - Positioning divs with CSS 问题1-使用CSS定位div

Example

JSFiddle JSFiddle

CSS 的CSS

<style>
* {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    font-family: Helvetica;
}
.yellow {
    width: 980px;
    height: 600px;
    background: yellow;
    padding: 10px;
}

.red {
    float: left;
    width: 600px;
    display: block;
    height: 100%;
    background: red;
    margin: 0px 10px 0px 0px;
}

.green {
    float: right;
    width: 280px;
    height: 100%;
    background: green;
    padding: 10px;
}

.white {
    background: white;
    height: 180px;
    margin: 0 0 10px 0;
}
</style>

HTML 的HTML

<div class="yellow">
<div class="red"></div><!-- end red -->
<div class="green">
<div class="white"></div>
<div class="white"></div>
<div class="white"></div>
</div><!-- end green -->
</div><!-- end yellow -->

Question 2 - Using CSS3 for a responsive layout 问题2-使用CSS3进行响应式布局

To answer your additional question, you can use CSS3 media queries for a responsive layout that will display the "Green" div on top of the "Red" div if the window size is under a certain width. 为了回答您的其他问题,您可以使用CSS3媒体查询进行响应式布局,如果窗口尺寸小于一定宽度,该布局将在“红色” div上方显示“绿色” div。

Example

JSFiddle . JSFiddle

Here is what you want http://jsfiddle.net/ZZ5AD/4/ 这是您想要的东西http://jsfiddle.net/ZZ5AD/4/

<div>
    <div class="parent">
        <div id="left" class="child">
                Yo
        </div>
        <div id="right" class="child">
            <div class="baby">
                lol
            </div>
            <div class="baby">
                lol
            </div>
            <div class="baby">
                lol
            </div>
        </div>
    </div>
</div>

css 的CSS

.parent{
    width: 900px;
    height: 400px;
    background: yellow;
    padding: 10px 10px 10px 0px;
}
.child{
    float: left;
    margin: 0px 0px 0px 10px;
    height: 100%;
}
#left{width:600px;     background: red;}
#right{width:280px;     background: green;}
.baby{
    height: 30%;
    width: auto;
    margin: 10px 10px 0px 10px;
    background: white;
}

I don't know if I understand correctly your question and if this will help you 我不知道我是否正确理解您的问题,这是否对您有帮助
If in your question you are referring to the fact that the yellow div doesn't include the items on the right you can try this code for parent element content(overflow:hidden) 如果在您的问题中指的是黄色div不包含右侧项目的事实,则可以尝试使用此代码获取父元素内容(溢出:隐藏)

#content {
    margin: 30px 0 50px;
    padding: 5px 50px;
    width: auto;
    height:auto;
    background:yellow;
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px;
    -webkit-box-shadow: 0 1px 3px rgba(0,0,0,.4);
    -moz-box-shadow: 0 1px 3px rgba(0,0,0,.4);
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
    opacity:0.8;
    text-align:justify;
    overflow:hidden;
}

If this solution does not suit your needs, i apologize for making you lose time. 如果此解决方案无法满足您的需求,我深表歉意使您浪费时间。

Html HTML

<div id="main">
    <div id="leftd">
    </div>
    <div id="rightd">
        <div></div>
        <div></div>
        <div></div>
    </div>
</div>

CSS 的CSS

#main {
    width:980px;
    background:yellow;
    padding:20px;
    float:left;
}

#leftd {
    background:red;
    height:400px;
    width:600px;
    float:left;
}

#rightd {
    background:green;
    height:400px;
    width:360px;
    float:right;
}

#rightd div
{
    height:100px;
    background:white;
    margin:20px;
}

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

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