Ich bin neu zu html/css, ich habe viele Male auf eine einfache HTML/CSS-Datei versucht, aber immer noch nicht funktioniert. Ich möchte den Inhalt im Browser zentrieren.Wie HTML-Inhalte in Browser-Center zu machen?
zwei Codequelle unter gleichen Verzeichnis sind, hier ist der Quellcode:
index.html:
<!DOCTYPE HTML>
<html>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<head>
<link rel="alternate stylesheet" type="text/css" href="style.css" />
</head>
<body>
<hr>
<h2>Head Title2</h2>
<p align="center">write something in the center</p>
<hr>
<h4>Content</h4>
<div class="centered">
Introduction<br>
Chapter<br>
<ol>
<li>Chapter-1<br>
<ol>
<li>Section-1</li>
<li>Section-2</li>
<li>Section-3</li>
<li>Section-4</li>
</ol>
</li>
<li>Chapter-2<br>
<ol>
<li>Section-1</li>
<li>Section-2</li>
<li>Section-3</li>
<li>Section-4</li>
</ol>
</li>
<li>Chapter-3<br>
<ol>
<li>Section-1<br>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</li>
<li>Section-2<br>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</li>
<li>Section-3<br>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</li>
</ol>
</li>
</ol>
<hr>
<h4>Reference</h4>
<ul>
<li>book1</li>
<li>book2</li>
<li>book3</li>
</ul>
</div>
<hr>
</body>
</html>
style.css:
h1 {
text-align: center;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 48px;
}
h2 {
text-align: center;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 44px;
}
h3 {
text-align: left;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 42px;
}
h4 {
text-align: left;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 40px;
}
p {
text-indent: 25px;
}
body {
margin: 0;
padding: 0;
text-align: center; /* !!! */
}
.centered {
margin: 0 auto;
width: 800px;
}
aber alle Inhalte sind in der linken Teil. es zeigt so:
Ich möchte den Inhalt im Mittelteil, und immer noch das gleiche Format. was soll ich machen ?
Außerdem fand ich meine h1-h4 CSS nicht funktioniert, wenn ich die Schriftgröße ändern, index.html hat sich überhaupt nicht geändert. warum ist es ?
danken für Ihre Hilfe, nachdem @ Code J.Sahbu liest, ich meine Quellcode wie folgt aktualisieren:
index.html:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<hr>
<h2>Head Title2</h2>
<p align="center">write something in the center</p>
<hr>
<h4>Content</h4>
Introduction<br>
Chapter<br>
<ol>
<li>Chapter-1<br>
<ol>
<li>Section-1</li>
<li>Section-2</li>
<li>Section-3</li>
<li>Section-4</li>
</ol>
</li>
<li>Chapter-2<br>
<ol>
<li>Section-1</li>
<li>Section-2</li>
<li>Section-3</li>
<li>Section-4</li>
</ol>
</li>
<li>Chapter-3<br>
<ol>
<li>Section-1<br>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</li>
<li>Section-2<br>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</li>
<li>Section-3<br>
<ol>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
</li>
</ol>
</li>
</ol>
<hr>
<h4>Reference</h4>
<ul>
<li>book1</li>
<li>book2</li>
<li>book3</li>
</ul>
<hr>
</body>
</html>
style.css:
h1 {
text-align: center;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 34px;
}
h2 {
text-align: center;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 30px;
}
h3 {
text-align: left;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 26px;
}
h4 {
text-align: left;
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 24px;
}
p {
text-indent: 25px;
}
body {
font-family: Cambria,Calibri,"Arial","Microsoft YaHei","黑体","宋体",sans-serif;
font-size: 20px;
margin-left: 20%;
margin-right: 20%;
min-width: 600px;
max-width: 1024px;
}
Dieser Stil ist eigentlich was ich will.
css Linie hinzufügen, body { Textausrichtung: Mitte; } – ashanrupasinghe