簡體   English   中英

我怎么放兩個 <div> 並排,左 <div> 占用權利未占用的空間的100% <div> ?

[英]How do I put two <div>s side-by-side, with the left <div> taking up 100% of the space not taken up by the right <div>?

我有一個基本問題。 兩個<div>身邊逐側,左側<div>需要能夠以具有“靈活”的寬度,如在當<div>上未顯示右,左<div>將然后拉伸到100%。

我的代碼目前如下,但不滿足上述要求。

<html>
        <head>
        <style>
        #container {
                display: block;
        }

        #box-left {
                width: 100%;
                height: 100px;
                background-color: red;
                float: left;
        }

        #box-right {
                width: 15%;
                height: 100px;
                background-color: blue;
                float: right;
        }
        </style>
        </head>
        <div id="container">
                <div id="box-left"></div>
                <div id="box-right"></div>
        </div>
        <body>

        </body>

任何指針將不勝感激。

#container {
  display: table;
  table-layout: fixed;
}
#id-right, #id-left {
  display: table-cell;
  float: none;
}
#id-left {
  /* no width */
}
#id-right {
  width: 15%;
}

不幸的是,這在IE6中不起作用,但除此之外,它還可以解決問題。

您是否嘗試過使用max-width:100%; 為“左框”?

如果顛倒#box-left#box-right在HTML #box-right顯示順序,並從CSS的#box-left中刪除width屬性,那么它應該可以描述:

#box-left {
        height: 100px;
        background-color: red;
        float: left;
}

...

<div id="container">
        <div id="box-right"></div>
        <div id="box-left"></div>
</div>

但是,您可能不希望該源順序,在這種情況下, <table>或CSS等效項是唯一允許您執行操作的HTML / CSS布局系統。

會將左div的寬度設置為您擁有的其余空間。 因此,由於您的方塊右為15%,因此將方塊左為85%

這是代碼:

#container {
                display: block;
        }

        #box-left {
                width: 85%;
                height: 100px;
                background-color: red;
                float: left;
        }

        #box-right {
                width: 15%;
                height: 100px;
                background-color: blue;
                float: right;
        }

我怎樣才能得到一個<div>漂浮在另外兩個之上<div> s 如果空間太窄,三個人都不能並排?</div><div id="text_translate"><p> 我有一個由兩個&lt;div&gt;並排組成的進度條,在&lt;dd&gt;內浮動到右側。 在進度條的左側,我在另一個&lt;div&gt;中有一些文本。 如果&lt;dd&gt;太窄,我希望&lt;div&gt;包含文本到進度條頂部的 go,而不是分成兩行。</p><p> 我正在使用 bootstrap.css 沒有修改: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> .col-6 { -ms-flex: 0 0 50%; flex: 0 0 50%; max-width: 50%; position: relative; width: 100%; padding-right: 15px; padding-left: 15px; }.my-0 { margin-top: 0;important. }:py-2 { padding-top. 0;5rem.important: };float-left { float. left:important; }.float-right { float: right;important. }:bg-success { background-color; #28a745 !important; } .bg-danger { background-color: #dc3545 !important; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;dd class="col-6 my-0"&gt; &lt;div class="float-left"&gt;Some text&lt;/div&gt; &lt;div class="py-2 float-right bg-success" style="width:10px;"&gt;&lt;/div&gt; &lt;div class="py-2 float-right bg-danger" style="width:90px;"&gt;&lt;/div&gt; &lt;/dd&gt;</pre></div></div><p></p><p> 我嘗試將z-index添加到&lt;div&gt; ,但無法達到我想要的效果。</p><p> 怎么做?</p></div></div>

[英]How can I get a <div> to float on top of two other <div>s if the space is too narrow for all three to stay side-by-side?

暫無
暫無

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

相關問題 如何使內部左div占用100%減去“右側固定寬度div” 我怎樣才能得到一個<div>漂浮在另外兩個之上<div> s 如果空間太窄,三個人都不能並排?</div><div id="text_translate"><p> 我有一個由兩個&lt;div&gt;並排組成的進度條,在&lt;dd&gt;內浮動到右側。 在進度條的左側,我在另一個&lt;div&gt;中有一些文本。 如果&lt;dd&gt;太窄,我希望&lt;div&gt;包含文本到進度條頂部的 go,而不是分成兩行。</p><p> 我正在使用 bootstrap.css 沒有修改: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> .col-6 { -ms-flex: 0 0 50%; flex: 0 0 50%; max-width: 50%; position: relative; width: 100%; padding-right: 15px; padding-left: 15px; }.my-0 { margin-top: 0;important. }:py-2 { padding-top. 0;5rem.important: };float-left { float. left:important; }.float-right { float: right;important. }:bg-success { background-color; #28a745 !important; } .bg-danger { background-color: #dc3545 !important; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;dd class="col-6 my-0"&gt; &lt;div class="float-left"&gt;Some text&lt;/div&gt; &lt;div class="py-2 float-right bg-success" style="width:10px;"&gt;&lt;/div&gt; &lt;div class="py-2 float-right bg-danger" style="width:90px;"&gt;&lt;/div&gt; &lt;/dd&gt;</pre></div></div><p></p><p> 我嘗試將z-index添加到&lt;div&gt; ,但無法達到我想要的效果。</p><p> 怎么做?</p></div></div> 如果空間足夠,則並排 div,否則以 100% 的寬度堆疊 如何在不指定寬度的情況下並排浮動兩個div,同時保持正確的div最小? 右側div沒有填滿右側 CSS-如何將div並排放置,左右之間沒有空格 我希望2個小部件並排填充div的100% 如何保持兩個並排的 div 元素高度相同? Safari 100%DIV在右側留有空間 右側的空div我的內容div占用了100%的高度空間
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM