はい、あなたが指摘したすべての要素で可能です。
次の 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;
}
お役に立てば幸いです。