使用Bootstrap选择文本对齐中心

时间:2017-02-06 11:42:49

标签: html css twitter-bootstrap

您好我有一个bootstrap框架,并选择width dynamic: 的 HTML

<select class="form-control" id="selectCenter">
   <option data-ng-value="20" value="20">20</option>
   <option data-ng-value="50" value="50">50</option>
   <option data-ngvalue="100" value="100">100</option>
</select>

CSS bootstrap

.form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
    -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}

我尝试过使用css:

#selectCenter {
   text-align: center;
}

但它不起作用。 我可以将文本居中选择仅使用css吗?

1 个答案:

答案 0 :(得分:-1)

您的代码运行正常,您可以使用text-align:center尝试使用代码段

来解决此问题

#selectCenter {
   text-align: center;
}
.form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.42857143;
    color: #555;
    background-color: #fff;
    background-image: none;
    border: 1px solid #ccc;
    border-radius: 4px;
	
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
    -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
}
<select class="form-control" id="selectCenter">
   <option data-ng-value="20" value="20">20</option>
   <option data-ng-value="50" value="50">50</option>
   <option data-ngvalue="100" value="100">100</option>
</select>