我使用本教程中的CSS按钮:
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html
我需要在DIV的中间放一个按钮,以便集中.但我不能!
这是按钮的代码:
- <a class="button" href="#"><span>Bring world peace</span></a>
这里的CSS:
- .clear { /* generic container (i.e. div) for floating buttons */
- overflow: hidden;
- width: 100%;
- }
- a.button {
- background: transparent url('bg_button_a.gif') no-repeat scroll top right;
- color: #444;
- display: block;
- float: left;
- font: normal 12px arial,sans-serif;
- height: 24px;
- margin-right: 6px;
- padding-right: 18px; /* sliding doors padding */
- text-decoration: none;
- }
- a.button span {
- background: transparent url('bg_button_span.gif') no-repeat;
- display: block;
- line-height: 14px;
- padding: 5px 0 5px 18px;
- }
这是我试图使用的代码:
- <div align="center"><a class="button" href="#"><span>Bring world peace</span></a></div>
解决方法
不推荐使用div元素的align属性.你最好为这个div定义一个类,就像这样:
- <div class="centerize">
- <a class="button" href="#"><span>Bring world peace</span></a>
- </div>
和CSS:
- .centerize {
- text-align: center;
- }
请注意,设置text-align将仅影响div内的内容. div本身(应该是)块元素,并且取决于它位于文档结构中的位置,可能不会居中.
只要多一点确定,你可以这样做:
- .centerize {
- display: block;
- margin: 0 auto;
- text-align: center;
- }
现在,您可以将centerize应用于任何元素,该元素应占用整个浏览器的宽度并对齐其内容.