簡體   English   中英

與自動寬度並排的DIV定位問題。

[英]DIV positioning issue for side-by- side with auto width.

我有2個DIV。 如下所示:

<div id="myForm" style="border: 1px solid black;width:500px;height:300px;margin-top: 10px;">
    <div class="leftcolumn">
        <div><input type="text" name="title" id="title" placeholder="Type title here" style="width:auto;" /></div>
        <div><textarea name="desc" id="desc" placeholder="Type description here" style="width:auto;"></textarea></div>
    </div>
    <div class="rightcolumn">
        <div>
         <label style="text-align: right;">Owner:</label>
         <input type="text" name="owner" id="owner" style="width: 100px;">
        </div>
        <div>
            <label style="text-align: right;">Estimate:</label>
            <input type="text" name="estimate" id="estimate" style="width: 100px;">
        </div>
    </div>
</div>

然后下面是我正在使用的css:

.leftcolumn { width: auto; border: 1px solid red; float: left}
.rightcolumn { width: 200px; border: 1px solid red; float: right}

下面是我面臨的問題的屏幕截圖: 在此處輸入圖片說明

將CSS更改為:

.leftcolumn { width: auto; border: 1px solid red; margin-right: 204px;}
.rightcolumn { width: 200px; border: 1px solid red; float: right}

並在html中替換左右:

<div id="myForm" style="border: 1px solid black;width:500px;height:300px;margin-top: 10px;">
    <div class="rightcolumn">
        <div>
            <label style="text-align: right;">Owner:</label>
            <input type="text" name="owner" id="owner" style="width: 100px;">
        </div>
        <div>
            <label style="text-align: right;">Estimate:</label>
            <input type="text" name="estimate" id="estimate" style="width: 100px;">
        </div>
    </div>
    <div class="leftcolumn">
        <div><input type="text" name="title" id="title" placeholder="Type title here" style="width:auto;" /></div>
        <div><textarea name="desc" id="desc" placeholder="Type description here" style="width:auto;"></textarea></div>
    </div>

</div>

查看資料

與其在左邊的列中使用浮點數,不如將右邊距設置為200px(如果需要一些間距則為210px);

.leftcolumn { margin-right: 210px; border: 1px solid red}

這將使右列在邊距內浮動。

您還需要反轉html中div的順序。 您希望右列位於左列之前。 不管“ myForm”的寬度如何,這都會為您提供所需的流暢布局。

基本並排嵌套<div>定位</div><div id="text_translate"><p> <a href="http://sas98.user.srcf.net/guestlist/index.php" rel="nofollow noreferrer">HTML</a>和<a href="http://sas98.user.srcf.net/guestlist/style.css" rel="nofollow noreferrer">CSS</a> 。</p><p> 這真的不應該像我想象的那樣困難 - 我相信解決方案非常簡單。</p><p> 我正在努力完成兩件事:</p><p> 1) 讓#left和#right在.container中與#footer並排坐在原處。 理想情況下, #right將只是一個分隔線(其中沒有文本),它與#topstrip和#bottomstrip相接,右側將有第三個 div。</p><p> 2)要有一個與#navbar水平但在左邊的標志。</p></div>

[英]Basic side-by-side nested <div> positioning

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM