How is this put in the center using CSS?

白昼怎懂夜的黑 提交于 2019-12-02 17:47:38

问题


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;
}

回答1:


Wrap the class .tab-unselected in a seperate div whose properties would be -

.center { margin: 0 auto; float: none; }

Now -

<div class="center">
    <div class="tab-selected" id="search">Search</div>
    <div class="tab-unselected" id="search">Tags</div>
    <div class="tab-unselected" id="search">Recruiters</div>
</div>



回答2:


horizontal-align does not exist. Use text-align: center instead. To horizontally center the element itself, use margin: 0 auto;, which equals:

margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin:left: auto;

The automatic right and left 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).




回答3:


Wrap them in a <div style="text-align: center;"> (or use some other way to apply that style to a containing element).




回答4:


Wrap them in a div

#center {
margin: 0 auto 0 auto; }

Then apply

<div id="center"> <YOURSTUFF HERE> </div>


来源:https://stackoverflow.com/questions/7746351/how-is-this-put-in-the-center-using-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!