【问题标题】:How can I position two <div>? One from the left and one from the right of a bootstrap modal?如何定位两个 <div>?一个从左侧和一个从引导模式的右侧?
【发布时间】:2015-09-04 02:37:13
【问题描述】:

假设我有一个引导模式,在模式的主体中。我有两个&lt;div&gt;,左边的&lt;div&gt; 包含一张图片,而右边的&lt;div&gt; 包含图片的标题。

目标输出!

假设这是一个引导模态体:

--------------            ----------------
|            |            |              |
|            |            |Name:         |
|  <image>   |            |Description:  |
|            |            |Price:        |
|            |            |              |
--------------            ----------------

不要介意两个 div 之间的空间,让我们假设它只是一个小空间。所以问题是我怎样才能将两个&lt;div&gt; 放在同一对齐中,其中第一个&lt;div&gt; 在左侧,另一个在右侧?

到目前为止,这就是我所做的。

---------------
|             |
|             |
| <image>     |
|             |
|             |
---------------

---------------
|             |
|             |
|Name:        |
|Description: |
|Price:       |
|             |
---------------

另一个&lt;div&gt; 向下而不是向右。

这是我上面错误输出的代码。

CSS

#divforimg{
    position: left;

}

#divforinfo {
    position: right;
}

HTML

            <div class="modal-body">

                    <div id = 'divforimg'>
                    <img style="height:50%; width:50%;" id = 'appimage'>
                    </div>

                <div id = "divforinfo">
                    <i><p id = "appdesc"></p></i>
                    <strong>Price: </strong><label id = "appprice"></label><br>
                    <strong>Brand: </strong><label id = "appbrand"></label><br>
                    <strong>Color: </strong><label id = "appcolor"></label><br>
                    <strong>Model: </strong><label id = "appmodel"></label><br>
                    <strong>Available Quantity: </strong><label id = "appqty"></label><br>
                    <strong>Date Posted: </strong><label id = "appposted"></label><br>
                </div>


        </div>

别管上面的图片来源,包括其他字段。谢谢!

【问题讨论】:

    标签: html css twitter-bootstrap divider


    【解决方案1】:

    应该是给它们一个宽度和浮动它们的简单问题:

    CSS

    #divforimg{
        width:200px;
        float:left;
    
    }
    
    #divforinfo {
        width:200px;
        float:left;
    }
    

    要使其更像您的示例,请将第二个更改为 float:right;,它将粘在其容器的右侧。

    【讨论】:

    • 两个&lt;div&gt; 重新定位到模态的页脚-_- 选择器有什么问题吗?
    • 尝试在 divforinfo 后添加 clearfix `
    • 很好,它现在可以工作了,我可以知道 clearfix 是做什么用的吗?
    • 浮动元素不会用完任何高度。 clearfix 类型的“结束”浮动并向下拉伸父元素。更多细节在这里provinite.tumblr.com/post/59072840177/…
    猜你喜欢
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-03
    • 1970-01-01
    • 2014-10-26
    相关资源
    最近更新 更多