HTML中如何实现三个div的水平定位?
P粉419164700
P粉419164700 2023-08-21 19:20:03
0
2
443
<p>我正在创建一个样本网站,其中有三个水平分区。 我希望最左边的分区宽度为25%,中间的分区宽度为50%,右边的分区宽度为25%,以便分区水平填满100%的空间。</p> <pre class="brush:php;toolbar:false;">&lt;html&gt; &lt;title&gt; 网站标题 &lt;/title&gt; &lt;div id="the whole thing" style="height:100%; width:100%" &gt; &lt;div id="leftThing" style="position: relative; width:25%; background-color:blue;"&gt; 左侧菜单 &lt;/div&gt; &lt;div id="content" style="position: relative; width:50%; background-color:green;"&gt; 随机内容 &lt;/div&gt; &lt;div id="rightThing" style="position: relative; width:25%; background-color:yellow;"&gt; 右侧菜单 &lt;/div&gt; &lt;/div&gt; &lt;/html&gt;</pre> <p>https://i.stack.imgur.com/NZDJe.jpg</p> <p>当我执行这段代码时,divs会重叠显示。我希望它们并排显示!</p> <p>我该怎么做?</p>
P粉419164700
P粉419164700

répondre à tous(2)
P粉478445671

我知道这是一个非常老的问题。我在这里发布这个问题的解决方案,使用了FlexBox。下面是解决方案:

#container {
  height: 100%;
  width: 100%;
  display: flex;
}
#leftThing {
  width: 25%;
  background-color: blue;
}
#content {
  width: 50%;
  background-color: green;
}
#rightThing {
  width: 25%;
  background-color: yellow;
}
<div id="container">

  <div id="leftThing">
    左侧菜单
  </div>

  <div id="content">
    随机内容
  </div>

  <div id="rightThing">
    右侧菜单
  </div>

</div>

只需要在容器中添加display:flex!不需要使用浮动。

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!