繁体   English   中英

如何将两个div彼此相邻放置并占据屏幕的整个宽度?

[英]How can I put two divs next to each other and have it take up the whole width of the screen?

我正在尝试将两个div相邻放置,并使它们都填满屏幕的宽度。 理想情况下,我希望它看起来像这样

我自己尝试过执行此操作,但是div的宽度最终太大,显示为两行。

这是我正在使用的代码:

<head>
<style>
.box {
    width: 50%;
    background-color: #202020;
    border: 2px solid #484848;
    border-radius: 10px;
    padding: 5px;
    margin-bottom: 5px;
}
p {
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, "sans-serif";
    color: #fff;
    margin: 0px;
}
</style>
</head>

<body>
<div class="box" style="float:right;">
  <p>Test</p>
</div>
<div class="box" style="float:left;">
  <p>Test</p>
</div>
</body>

我认为问题是由于div的填充和边框大小引起的,但我似乎无法解决。 任何帮助将非常感激! :)

只需使用另一个保存div的容器并使用display:flex

要使间隙使用正当内容:在空格之间减小框的宽度。

<head>
<style>
.box {
    width: 48%;
    background-color: #202020;
    border: 2px solid #484848;
    border-radius: 10px;
    padding: 5px;
    margin-bottom: 5px;
}
.wrapper {
  display:flex;
  justify-content:space-between;
  width:100vw;
}
p {
    font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, "sans-serif";
    color: #fff;
    margin: 0px;
}
</style>
</head>

<body>
<div class="wrapper">
<div class="box" style="float:right;">
  <p>Test</p>
</div>
<div class="box" style="float:left;">
  <p>Test</p>
</div>
</div>

</body>

 .container { display: flex; width: 100%; height: 100px; } .twin { margin:8px; height: inherit; border: 1px solid red; width: 50%; } 
 <html> <head> </head> <body> <div class="container"> <div class="twin"> </div> <div class="twin"> </div> </div> </body> </html> 

怎么放两个<div>具有相同的宽度和高度彼此相邻而无需滚动?</div><div id="text_translate"><p> 我目前正在制作一个简单的 html 页面,其中包含两个部分,每个部分都有内容,但第二个 div .right的最后一个内容位于页面底部并使页面可滚动。</p><p> 我尝试制作另一个 div 并放置一个flex-direction: column ,但它不起作用: </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"> body { margin: 0; }.main-container { display: flex; flex-direction: column; }.left { background: #ecece9; width: 50%; height: 100vh; }.right { background: #ffffff; width: 50%; height: 100vh; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="main-container"&gt; &lt;div class="left"&gt; &lt;h2&gt;content&lt;/h2&gt; &lt;/div&gt; &lt;div class="right"&gt; &lt;h2&gt;content should be on top&lt;/h2&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p><p> 如何将具有相同宽度和高度的两个&lt;div&gt;放置而无需滚动?</p></div>

[英]How can I put two <div> that has the same width and height next to each other without having to scroll?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将两个div相邻放置? 如何将两个div彼此相邻放置? 我怎样才能把我的 div 放在一起? 如何将两个以圆圈为单位的div相邻放置? 怎么放两个<div>具有相同的宽度和高度彼此相邻而无需滚动?</div><div id="text_translate"><p> 我目前正在制作一个简单的 html 页面,其中包含两个部分,每个部分都有内容,但第二个 div .right的最后一个内容位于页面底部并使页面可滚动。</p><p> 我尝试制作另一个 div 并放置一个flex-direction: column ,但它不起作用: </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"> body { margin: 0; }.main-container { display: flex; flex-direction: column; }.left { background: #ecece9; width: 50%; height: 100vh; }.right { background: #ffffff; width: 50%; height: 100vh; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="main-container"&gt; &lt;div class="left"&gt; &lt;h2&gt;content&lt;/h2&gt; &lt;/div&gt; &lt;div class="right"&gt; &lt;h2&gt;content should be on top&lt;/h2&gt; &lt;/div&gt; &lt;/div&gt;</pre></div></div><p></p><p> 如何将具有相同宽度和高度的两个&lt;div&gt;放置而无需滚动?</p></div> 如何让div占据屏幕的整个宽度? 我可以将两个div放在一起,当一个被移除时,另一个扩展以填充空间吗? 把两个div放在一起 CSS 将两个 div 并排放置 如何使跨度和输入彼此相邻并共同占据包含 div 宽度的 100%?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM