我有以下 HTML 代碼:<!DOCTYPE html><html><head> <title>test</title> <style> .left { width: 30px; background-color: green; } .right { background-color: red; width: 30px; } </style></head><body> <div class="left">Text</div> <div class="right">Text</div></body></html>紅色 div 出現在綠色 div 的正下方,但我想讓紅色 div 直接位于綠色 div 的右側 - 我應該怎么做?添加 float: right css 屬性不起作用,因為它會轉到頁面的另一側。
1 回答

守候你守候我
TA貢獻1802條經驗 獲得超10個贊
.left {
float: left;
width: 30px;
background-color: green;
}
.right {
float: right;
background-color: red;
width: 30px;
}
<div class="left">Text</div>
<div class="right">Text</div>
你必須使用浮動來實現這一點
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
.left {
float: left;
width: 30px;
background-color: green;
}
.right {
float: right;
background-color: red;
width: 30px;
}
</style>
</head>
<body>
<div class="left">Text</div>
<div class="right">Text</div>
</body>
</html>
- 1 回答
- 0 關注
- 166 瀏覽
添加回答
舉報
0/150
提交
取消