如何使用 CSS 将其置于中心?
基本上我想将 div 标签放在页面中央下方。这在 CSS 中是如何完成的?我很难做到这一点,最好的选择是什么!?
HTML
<div class="tab-selected" id="search">Search</div>
<div class="tab-unselected" id="search">Tags</div>
<div class="tab-unselected" id="search">Recruiters</div>
CSS:
.tab-selected {
background: #FF00FF;
-moz-border-radius: 3px;
border-radius: 3px;
font: 13px helvetica;
color: #FFFFFF;
height: 15px;
display: inline;
}
.tab-unselected {
-moz-border-radius: 3px;
border-radius: 3px;
font: 13px helvetica;
color: #585858;
height: 15px;
display: inline;
margin: 5px 5px 5px 5px;
padding: 5px 5px 5px 5px;
position: relative;
width: 60px;
display: inline-block;
horizontal-align: center;
}
Basically I want to put the div tags below in the center of the page. How is this done in CSS? I am having such a hard time doing it what is the best option!?
HTML
<div class="tab-selected" id="search">Search</div>
<div class="tab-unselected" id="search">Tags</div>
<div class="tab-unselected" id="search">Recruiters</div>
CSS:
.tab-selected {
background: #FF00FF;
-moz-border-radius: 3px;
border-radius: 3px;
font: 13px helvetica;
color: #FFFFFF;
height: 15px;
display: inline;
}
.tab-unselected {
-moz-border-radius: 3px;
border-radius: 3px;
font: 13px helvetica;
color: #585858;
height: 15px;
display: inline;
margin: 5px 5px 5px 5px;
padding: 5px 5px 5px 5px;
position: relative;
width: 60px;
display: inline-block;
horizontal-align: center;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将类
.tab-unselected
包装在一个单独的div
中,其属性为 -现在 -
Wrap the class
.tab-unselected
in a seperatediv
whose properties would be -Now -
horizontal-align
确实不存在。使用text-align: center
代替。要使元素本身水平居中,请使用margin: 0 auto;
,它等于:自动
right
和left
margin 导致元素居中。如果您想垂直对齐元素,请使用
vertical-align: center
(这仅适用于内联元素)。horizontal-align
does not exist. Usetext-align: center
instead. To horizontally center the element itself, usemargin: 0 auto;
, which equals:The automatic
right
andleft
margin results in a centered element.If you want to vertically align an element, use
vertical-align: center
(this does only work on inline elements).将它们包装在
中(或使用其他方式将该样式应用于包含元素)。
Wrap them in a
<div style="text-align: center;">
(or use some other way to apply that style to a containing element).将它们包裹在 div 中
然后应用
Wrap them in a div
Then apply