我是一個完全的CSS初學者(這實際上是我寫的第一個CSS),也是初學HTML的人,所以請原諒我,如果我錯過了某些明顯的東西或者我犯了一些嚴重的錯誤。現在,對問題:如何將CSS錶行的單元格大小與下一行的單元格大小分開?
我想創建一個佈局,我偶然發現了一個問題,禁止我做我想做的事情。這裏是什麼,我有一個截圖:
我想要做的就是簡單地寫着「家」 div
,「博客」等,使之寬,如下div
S,有效使其以與側邊欄相同的Y結束。像這樣:
HTML文件的主體包含background
類div
,該負責裝修的文字,而一切的不存在另一個div
稱爲container
。 container
設爲display: table
和裏面包含row
類的兩個div
S(標誌着display: table-row
),含導航div
和包含主欄和那些在第二第一(它們都是section
類的,標記display: table-cell
)。
這裏是整個文件,同時顯示的CSS,以及如何我試圖結構HTML:實現這個
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<title>mini</title>
<style type="text/css">
* {
font-family: "Ubuntu", Helvetica, Arial, sans-serif;
margin: 0;
}
body {
padding: 100px 0 0 0;
background: white;
color: #444444;
}
h1 {
font-size: 48px;
font-weight: bold;
letter-spacing: -0.083333em;
line-height: 1.3em;
text-transform: lowercase;
}
p {
line-height: 1.5em;
}
.container {
overflow: hidden;
padding: 24px 24px 24px 24px;
border-spacing: 35px 35px;
display: table;
}
.section {
position: relative;
padding: 24px 24px 24px 24px;
border-width: 1px;
border-style: solid;
border-color: #888888;
background: white;
display: table-cell;
}
.background {
position: absolute;
margin: -124px -124px -124px -124px;
z-index: -1;
float: right;
font-size: 54px;
line-height: 1em;
font-weight: bold;
color: #eeeeee;
}
.row {
display: table-row;
}
#sidebar {
width: 20%;
}
#navigation {
font-size: 24px;
font-weight: bold;
text-transform: lowercase;
}
#empty {
}
</style>
</head>
<body>
<div id="background" class="background">
bgtext
</div>
<div id="foreground" class="container">
<div class="row">
<div id="navigation" class="section">
navitext
</div>
</div>
<div class="row">
<div id="mainbody" class="section">
<h1>Main</h1>
maintext
</div>
<div id="sidebar" class="section">
<h1>Sidebar</h1>
sidetext
</div>
</div>
</div>
</body>
</html>
diplay:table type styles意味着你的CSS會像表格一樣工作。這可能不是你想要的。 –
我開始懷疑這一點。但是如果有一些方法可以將導航定義爲跨越兩列,那麼我想我們會找到某個地方。 –