繁体   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