代码之家  ›  专栏  ›  技术社区  ›  Niel Sinel

如何定位两个<div>?引导模式的左侧和右侧各有一个?

  •  0
  • Niel Sinel  · 技术社区  · 10 年前

    假设我在模态的主体中有一个引导模态。我有两个 <div> 这个 <div> 左侧包含一个图像,而 <div> 右侧包含图像的标题。

    目标输出!

    让我们假设这是一个引导模式体:

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

    不管两个div之间的空间如何,让我们假设它只是一个小空间。所以问题是我怎么才能把两个 <div> 在第一个 <div> 在左边,另一个在右边?

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

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

    其他的 <div> 而是向右向下。

    这是我针对上述错误输出的代码。

    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>
    

    不允许上面的图像源和其他字段。非常感谢。

    1 回复  |  直到 10 年前
        1
  •  1
  •   CollinD    10 年前

    应该是一个简单的问题,既给它们一个宽度,又让它们浮动:

    CSS格式

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

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