国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Wie erreicht man eine horizontale Positionierung von drei Divs in HTML?
P粉419164700
P粉419164700 2023-08-21 19:20:03
0
2
682
<p>Ich erstelle eine Beispielwebsite mit drei horizontalen Partitionen. Ich m?chte, dass die Partition ganz links 25 % breit ist, die mittlere Partition 50 % breit und die rechte Partition 25 % breit, sodass die Partitionen horizontal 100 % des Raums ausfüllen. </p> <pre class="brush:php;toolbar:false;"><html> <Titel> Webseitentitel </title> <div id="das Ganze" style="height:100%; width:100%" > <div id="leftThing" style="position: relative; width:25%; background-color:blue;"> linkes Menü </div> <div id="content" style="position: relative; width:50%; background-color:green;"> zuf?lliger Inhalt </div> <div id="rightThing" style="position: relative; width:25%; hintergrundfarbe:gelb;"> rechtes Menü </div> </div> </html></pre> <p>https://i.stack.imgur.com/NZDJe.jpg</p> <p>Wenn ich diesen Code ausführe, erscheinen die Divs überlappend. Ich m?chte, dass sie nebeneinander erscheinen! </p> <p>Was soll ich tun? </p>
P粉419164700
P粉419164700

Antworte allen(2)
P粉478445671

我知道這是一個非常老的問題。我在這里發(fā)布這個問題的解決方案,使用了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">
    左側(cè)菜單
  </div>

  <div id="content">
    隨機內(nèi)容
  </div>

  <div id="rightThing">
    右側(cè)菜單
  </div>

</div>

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

P粉842215006

我建議不要使用浮動來處理這種情況,我更傾向于使用inline-block。

還有一些需要考慮的要點:

  • 內(nèi)聯(lián)樣式對于可維護性來說不好
  • 選擇器名稱中不應(yīng)該有空格
  • 你忽略了一些重要的HTML標簽,比如<head><body>
  • 你沒有包含doctype

這是一個更好的格式化文檔的方式:

<!DOCTYPE html>
<html>
<head>
<title>網(wǎng)站標題</title>
<style type="text/css">
* {margin: 0; padding: 0;}
#container {height: 100%; width:100%; font-size: 0;}
#left, #middle, #right {display: inline-block; *display: inline; zoom: 1; vertical-align: top; font-size: 12px;}
#left {width: 25%; background: blue;}
#middle {width: 50%; background: green;}
#right {width: 25%; background: yellow;}
</style>
</head>
<body>
<div id="container">
    <div id="left">左側(cè)菜單</div>
    <div id="middle">隨機內(nèi)容</div>
    <div id="right">右側(cè)菜單</div>
</div>
</body>
</html>

這里還有一個jsFiddle供參考。

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage