是的,它可以爲你記錄的所有元素。
藉此HTML:
<body>
<div class="canvas">
<p>This is a really lovely but meaningless piece of text</p>
<div class="form-container">
<form>
<input type="text" name="example" placeholder="Enter some example text" />
</form>
</div>
</div>
</body>
所以我們要居中的一些元素。讓我們從包含DIV #canvas開始並從那裏移動。
/* First a very crude reset on <body> and declare it's dimensions */
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
/* Next we must declare a definitive width of our #canvas to allow
us to centre itself and elements within it. */
#canvas {
width:960px;
position:relative;
margin: 0 auto; /* This 'auto' on left/right margin centers it
}
/* Note that <p> tags are auto 100% width so centering them is not
going to do anything with the above technique. Instead: */
#canvas p {
text-align: center;
}
/* Now form elements, no need to style <form> it is a meta container
and really shouldn't be used for anything other than that, lets
style the actual input elements instead */
#canvas form input {
width: 30%; /* Lets define a width so that we can center it in */
margin: 0 auto;
}
希望幫助你。
看看我的答案。 #canvas的定位正是你所要求的。 – 2012-07-25 07:40:23