简体   繁体   English

CSS并排div位于第一个的中间

[英]CSS side by side div half way up the first one

See image: https://dl.dropboxusercontent.com/u/63494571/whatswrong_div.jpg 查看图片: https : //dl.dropboxusercontent.com/u/63494571/whatswrong_div.jpg

As you can see in the image above, for some reason my image is only part way up the first div, it should be right next to it with the same height. 如您在上图中所看到的,由于某种原因,我的图像仅位于第一个div的上方,因此它应该以相同的高度紧邻它。

Here is a link to an image of how it will eventually look: https://dl.dropboxusercontent.com/u/63494571/add_sale_new.jpg 这是指向最终外观的图像的链接: https : //dl.dropboxusercontent.com/u/63494571/add_sale_new.jpg

css 的CSS

.add_sale_background {
    background-color:#353535;
    border:solid #000 1px;
    border-radius: 10px;    
}
.add_sale_container { width:210px; margin:1em; font-size:14px; display:inline-block; }

.add_sale_image_container { width:150px; text-align:left; padding:4px; display:inline-block; }
.add_sale_image { height:135px; width:135px; background-size:cover; margin: 7.5px; }
.add_sale_selected_product > span {
    margin:2px;
    border-radius:5px;
    padding:2px;
    cursor:pointer;
    background-color:#353535;
    border:solid #000 1px;
    border-radius: 5px;
    display:inline-block;
}
.add_sale_selected_product > span:hover { background-color:#005c9c; }

.add_sale_controls_container {
    width:35px;
    height:200px;
    display:inline-block;
}

html html

    <div class="sidebar">
        Sidebar
    </div>
    <div class="add_sale_container">
        <form name="sale">
            <div class="add_sale_image_container add_sale_background">
                <div>image1</div>
                <div class="add_sale_image" style="background-image:url(images/image4.JPG);"></div>
                <div class="add_sale_selected_product">
                    <span>KR</span>
                </div>
                <input type="hidden" id="applied_product" value="KR" />
            </div>
            <div class="add_sale_controls_container add_sale_background">
                dsa
            </div>
        </form>
    </div>

Float the control section right, float: right; 向右float: right;控制部分,向右float: right;

DEMO http://jsfiddle.net/kevinPHPkevin/fAAXU/ 演示http://jsfiddle.net/kevinPHPkevin/fAAXU/

To get where you want to go you'll need to add the following to the following css: 要到达您想去的地方,您需要将以下内容添加到以下css中:

.add_sale_image_container { 
    float: left; 
    margin-right: 10px;
}

I made a jsfiddle that shows you how it looks: http://jsfiddle.net/mattokdla/L9Wre/ 我做了一个jsfiddle,向您展示了它的外观: http : //jsfiddle.net/mattokdla/L9Wre/

You can leave the over all container to inlin-block without floating it left, but the divs inside need to be floated left as show on the jsfiddle file to make it work. 您可以将整个容器保留为inlin-block而不向左浮动,但是内部的div需要向左浮动,如jsfiddle文件上所示才能使其正常工作。 This way it also lets you control the margin space between the 2 divs. 这样,您还可以控制2个div之间的边距空间。

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

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