通过将文本放在带有样式的DIV中来控制宽度:
<DIV style="width: 300px">
Text goes here.
</DIV>
Run Code Online (Sandbox Code Playgroud)
根据安吉拉在评论中提出的建议,以中心为中心:
<DIV style="width: 300px; margin: 0 auto">
Text goes here.<br>
And another line which is much longer.
</DIV>
Run Code Online (Sandbox Code Playgroud)
html:
<div id="centered"><!-- put your content here --></div>
Run Code Online (Sandbox Code Playgroud)
CSS:
body {
text-align:center; /* this is required for old versions of IE */
}
#centered {
width:400px; /* this is the width of the center column (px, em or %) */
text-align:left; /*resets the text alignment back to left */
margin:0 auto; /* auto centers the div in standards complaint browsers */
}
Run Code Online (Sandbox Code Playgroud)
就是这样,享受吧!