试图在网页中定位Divs?

时间:2014-04-23 21:42:50

标签: css html

我试图定位这些因此有2行3“内容框”但是当试图对齐它们时它们就到处都是。任何帮助?谢谢。

代码。

    .carbox {
    float: left;
    width: 400px;
    height: 200px;
    line-height: normal;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: #363F48;
}
.carlisting {
    -webkit-box-shadow: 0px 0px 6px rgba(229, 238, 248, 1);
    -moz-box-shadow: 0px 0px 6px rgba(229, 238, 248, 1);
    box-shadow: 0px 0px 6px rgba(229, 238, 248, 1);
    border: 1px solid #e9edf2;
    margin-bottom: 50px;
    -webkit-transition: all 0.35s ease-in-out;
    -moz-transition: all 0.35s ease-in-out;
    -ms-transition: all 0.35s ease-in-out;
    -o-transition: all 0.35s ease-in-out;
    transition: all 0.35s ease-in-out;
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    border-radius: 2px;
    background: #ffffff;
}
.toprow {
    height: 107px;
    border-bottom: lightgray 1px solid;
}
.carinfo {
    height: 107px;
    float: right;
    width: 50%;
}
.carinfo .title {
    height: 53.5px;
    font-size: 20px;
    line-height:53px;
}
.carinfo .price {
    height: 53.5px;
}
.carinfo .price span {
    color: white;
    height: 18px;
    width: 50px;
    padding:2px 4px;
    background-color: #363F48;
    cursor:pointer;
}
.btrow span {
    border-right: 1px lightgray solid;
    margin:5px 4px;
}

HTML(请注意,顶部有一个容器,是边距等。

    <div class="container">
        <div class="carbox">
            <div class="carlisting">
                <div class="toprow">
                    <img height="107px" src="http://demo.swebdesignstudio.com/templates/carell/car_dealer/images/car-1.jpg" width="186px" />
                    <div class="carinfo"> 
                    <div class="title">Honda</div>
                    <div class="price"><span>£999.99</span></div>
                    </div>
                </div>
                <div class="btrow">
                    <span>2012</span> <span>100bhp</span> <span>12,000mi</span>
                    <span>Manual</span> </div>
            </div>
        </div>
        <div class="carbox">
            <div class="carlisting">
                <div class="toprow">
                    <img height="107px" src="http://demo.swebdesignstudio.com/templates/carell/car_dealer/images/car-1.jpg" width="186px" />
                    <div class="carinfo"> 
                    <div class="title">Honda</div>
                    <div class="price"><span>£999.99</span></div>
                    </div>
                </div>
                <div class="btrow">
                    <span>2012</span> <span>100bhp</span> <span>12,000mi</span>
                    <span>Manual</span> </div>
            </div>
<div class="carbox">
            <div class="carlisting">
                <div class="toprow">
                    <img height="107px" src="http://demo.swebdesignstudio.com/templates/carell/car_dealer/images/car-1.jpg" width="186px" />
                    <div class="carinfo"> 
                    <div class="title">Honda</div>
                    <div class="price"><span>£999.99</span></div>
                    </div>
                </div>
                <div class="btrow">
                    <span>2012</span> <span>100bhp</span> <span>12,000mi</span>
                    <span>Manual</span> </div>
            </div>
        <div class="container">
        <div class="carbox">
            <div class="carlisting">
                <div class="toprow">
                    <img height="107px" src="http://demo.swebdesignstudio.com/templates/carell/car_dealer/images/car-1.jpg" width="186px" />
                    <div class="carinfo"> 
                    <div class="title">Honda</div>
                    <div class="price"><span>£999.99</span></div>
                    </div>
                </div>
                <div class="btrow">
                    <span>2012</span> <span>100bhp</span> <span>12,000mi</span>
                    <span>Manual</span> </div>
            </div>
        </div>
        <div class="carbox">
            <div class="carlisting">
                <div class="toprow">
                    <img height="107px" src="http://demo.swebdesignstudio.com/templates/carell/car_dealer/images/car-1.jpg" width="186px" />
                    <div class="carinfo"> 
                    <div class="title">Honda</div>
                    <div class="price"><span>£999.99</span></div>
                    </div>
                </div>
                <div class="btrow">
                    <span>2012</span> <span>100bhp</span> <span>12,000mi</span>
                    <span>Manual</span> </div>
            </div>
<div class="carbox">
            <div class="carlisting">
                <div class="toprow">
                    <img height="107px" src="http://demo.swebdesignstudio.com/templates/carell/car_dealer/images/car-1.jpg" width="186px" />
                    <div class="carinfo"> 
                    <div class="title">Honda</div>
                    <div class="price"><span>£999.99</span></div>
                    </div>
                </div>
                <div class="btrow">
                    <span>2012</span> <span>100bhp</span> <span>12,000mi</span>
                    <span>Manual</span> </div>
            </div>
</section>

Screesnshot:

https://dl-web.dropbox.com/get/Screenshots/Screenshot%202014-04-23%2022.41.37.png?_subject_uid=15468544&w=AADDCyCb4DCHjvJkraYMb1RDu90iqHThnQV_z203Fit2UA

2 个答案:

答案 0 :(得分:0)

你有很多遗漏</div>

以下是您的代码示例。我使用百分比代替宽度的px值。

http://jsfiddle.net/Kfg4L/

答案 1 :(得分:0)

问题看起来(除了其他人提到的未关闭的div)你的元素有一个固定的宽度,所以只能有#34; 3行的行#34;在非常特定的屏幕尺寸上使用该像素宽度。

可能最好更改为%宽度,例如width:30%;margin-right:3%;或类似内容具有更快速响应的内容结构 - 您需要确保在这些框中您不会修复破坏它的宽度。