css - 如何使用 Bootstrap 类将样式赋予 chosen-select 和 align radio?

标签 css twitter-bootstrap jquery-chosen

我想为我的 chosen-select 下拉列表提供相同的样式,并希望在同一行内对齐 chosen-select 和单选按钮以及其他控件。

我正在尝试这样。请纠正我哪里错了?

      $(document).ready(function () {
                  $(".chosen-select").chosen({ no_results_text: "Oops, nothing found!" });

        });

        function submitForm() {
            if ($("#frmR").valid()) {
                var form = $("#frmR").serialize();
                $.post("/Portal/Registration/RegisterP", form, function (msg) {

                });
            }
      }

    function Shift() {
        window.history.back();
        return false;
    }
.form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 18px;
    line-height: 1.428571429;
    vertical-align: middle;
    background-color: #edf8f7;
    background-image: none;
    border: 1px solid #8dc6cd;
    /* border-radius: 4px; */
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
    -webkit-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;
    height: 49px;
}



input[type="checkbox"], input[type="radio"] {
    padding: 0;
    box-sizing: border-box;
    width: 30px;
    height: 30px;
    background-color: #edf8f7;
    /* background-image: none; */
    border: 1px solid #8dc6cd;
    border-radius: 0px;
}

input[type=checkbox], input[type=radio] {
    margin: 4px 0 0;
    margin-top: 1px\9;
    line-height: normal;
}

input[type=checkbox], input[type=radio] {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 0;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

input {
    line-height: normal;
}

button, input, optgroup, select, textarea {
    margin: 0;
    font: inherit;
    color: inherit;
}

* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

input[type="radio" i] {
    margin: 3px 3px 0px 5px;
}

input[type="radio" i] {
    -webkit-appearance: radio;
    box-sizing: border-box;
}

input[type="radio" i], input[type="checkbox" i] {
    background-color: initial;
    margin: 3px 0.5ex;
    padding: initial;
    border: initial;
}

input {
    -webkit-appearance: textfield;
    background-color: white;
    -webkit-rtl-ordering: logical;
    user-select: text;
    cursor: auto;
    padding: 1px;
    border-width: 2px;
    border-style: inset;
    border-color: initial;
    border-image: initial;
}

input, textarea, select, button {
    text-rendering: auto;
    color: initial;
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: start;
    margin: 0em;
    font: 13.3333px Arial;
}

input, textarea, select, button, meter, progress {
    -webkit-writing-mode: horizontal-tb;
}
label {
    display: inline-block;
    margin-bottom: 5px;
    /* font-weight: bold; */
    color: #6b7b8a;
    font-size: 18px;
    font-weight: bold;
}

label {
    display: inline-block;
    max-width: 100%;
    margin-bottom: 5px;
    font-weight: 700;
}
body {
    background: #fff;
    font-family: 'Roboto', sans-serif;
    color: #54667a;
    line-height: 22px;
}

body {
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 1.42857143;
    color: #333;
    background-color: #fff;
}
label>input[type="radio"]{
  vertical-align: -30%;
}
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.7.0/chosen.min.css" rel="stylesheet" />

<script 
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" > </script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js" > </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js" > </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.7.0/chosen.jquery.js" > </script>
</head>
<body>
<form  id="frmR" action="#" method="post">    
                     <div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
</ul></div>
                     <div class="col-xs-6 remove-padding">
                         <h4>Type</h4>
                     </div>
                     <div class="col-xs-6">
                         <button type="submit" id="register-submit-btn" onclick="submitForm(); return false;" class="btn-primarySmall pull-right">
                             Register
                         </button>
                    </div>
                         <div class="row">
                             <div class="col-xs-12">
                                 <div class="col-xs-12">
                                     <div>
                                         <label class="">Type</label>
                                         <label><input type="radio" name="Type" checked="" value="Walk-In">Walk-In</label>
                                         <label><input type="radio" name="Type" value="Telephonic">Telephonic</label>
                                     </div>
                                 </div>
                                 <div class="col-xs-12 remove-padding">
                                     <hr />
                                     <h4>Personal Information</h4>
                                     <hr />
                                 </div>

                                 <div class="col-xs-4">
                                     <div class="form-group">
                                         <label>First Name<span style="color:#FF0000">*</span></label>
                                         <input class="form-control" type="text" placeholder="First Name" name="vFirstName" id="vFirstName" required="required" />
                                     </div>
                                 </div>

                                    
                                  <div class="col-xs-4">
                                     <div class="form-group">
                                         <label>Country<span style="color:#FF0000"></span></label>
                                         <select class="form-control chosen-select" data-val="true" data-val-required="The Country field is required." id="vCountry" name="vCountry" required="required"><option value="">-- Select your country--</option>
                                            <option value="1">Australia</option>
                                            <option value="120">Lithuania</option>
                                            <option value="174">Rwanda</option>
                                            <option value="175">Saint Helena</option>
                                            <option value="176">Saint Kitts And Nevis</option>
                                            </select>                                         
                                     </div>
                                 </div>
                                   <div class="col-xs-4">
                                     <div class="form-group">
                                         <label>Gender<span style="color:#FF0000"></span></label>
                                         <label class="checkbox-label"><input type="radio" name="vGender" checked="" value="1">Male</label>
                                         <label class="checkbox-label"><input type="radio" name="vGender" value="2">Female</label>
                                     </div>
                                 </div>

  
                            </div>
                        </div>
</form>
</body>
</html>

最佳答案

您可以试试这个来对齐选择和单选控件...

$(document).ready(function () {
                  $(".chosen-select").chosen({ no_results_text: "Oops, nothing found!" });

        });

        function submitForm() {
            if ($("#frmR").valid()) {
                var form = $("#frmR").serialize();
                $.post("/Portal/Registration/RegisterP", form, function (msg) {

                });
            }
      }

    function Shift() {
        window.history.back();
        return false;
    }
.form-control {
    display: block;
    width: 100%;
    height: 34px;
    padding: 6px 12px;
    font-size: 18px;
    line-height: 1.428571429;
    vertical-align: middle;
    background-color: #edf8f7;
    background-image: none;
    border: 1px solid #8dc6cd;
    /* border-radius: 4px; */
    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
    box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
    -webkit-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;
    height: 49px;
}



input[type="checkbox"], input[type="radio"] {
    padding: 0;
    box-sizing: border-box;
    width: 30px;
    height: 30px;
    background-color: #edf8f7;
    /* background-image: none; */
    border: 1px solid #8dc6cd;
    border-radius: 0px;
}

input[type=checkbox], input[type=radio] {
    margin: 4px 0 0;
    margin-top: 1px\9;
    line-height: normal;
}
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.7.0/chosen.min.css" rel="stylesheet" />

<script 
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" > </script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js" > </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.6/jquery.validate.unobtrusive.min.js" > </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.7.0/chosen.jquery.js" > </script>
</head>
<body>
<form  id="frmR" action="#" method="post">    
                     <div class="validation-summary-valid" data-valmsg-summary="true"><ul><li style="display:none"></li>
</ul></div>
                     <div class="col-xs-6 remove-padding">
                         <h4>Type</h4>
                     </div>
                     <div class="col-xs-6">
                         <button type="submit" id="register-submit-btn" onclick="submitForm(); return false;" class="btn-primarySmall pull-right">
                             Register
                         </button>
                    </div>
                        <div class="row">
                            <div class="col-xs-12">
                                <div class="col-xs-12">
                                    <div>
                                         <label class="">Type</label>
                                         <label><input type="radio" name="Type" checked="" value="Walk-In">Walk-In</label>
                                         <label><input type="radio" name="Type" value="Telephonic">Telephonic</label>
                                    </div>
                                </div>
                                <div class="col-xs-12 remove-padding">
                                     <hr />
                                     <h4>Personal Information</h4>
                                     <hr />
                                </div>
							</div>
							<div class="row" style="margin-left: 15px!important;"/>
                                 <div class="col-xs-4">
                                     <div class="form-group">
                                         <label>First Name<span style="color:#FF0000">*</span></label>
                                         <input class="form-control" type="text" placeholder="First Name" name="vFirstName" id="vFirstName" required="required" />
                                     </div>
                                 </div>                              
                                 <div class="col-xs-4">
                                     <div class="form-group">
                                         <label>Country<span style="color:#FF0000"></span></label>
                                         <select class="form-control chosen-select" data-val="true" data-val-required="The Country field is required." id="vCountry" name="vCountry" required="required"><option value="">-- Select your country--</option>
                                            <option value="1">Australia</option>
                                            <option value="120">Lithuania</option>
                                            <option value="174">Rwanda</option>
                                            <option value="175">Saint Helena</option>
                                            <option value="176">Saint Kitts And Nevis</option>
                                            </select>                                         
                                     </div>
                                 </div>
                                   <div class="col-xs-4">
                                     <div class="form-group" style="padding-top: 10px;">
                                         <label>Gender<span style="color:#FF0000"></span></label>
                                         <label class="checkbox-label"><input type="radio" name="vGender" checked="" value="1">Male</label>
                                         <label class="checkbox-label"><input type="radio" name="vGender" value="2">Female</label>
                                     </div>
                                 </div>
                            </div>
                        </div>
</form>
</body>
</html>

关于css - 如何使用 Bootstrap 类将样式赋予 chosen-select 和 align radio?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44860665/

相关文章:

CSS - WebKit 表格单元显示 100% 缺少 1 个像素的宽度?

javascript - Bootstrap 模板中的鼠标悬停淡入淡出效果

javascript - 如何禁用 jquery 选择的页面加载事件中的选项?

javascript - 选择在 chrome 上工作,但不在 firefox/IE 上工作

html - 无法使用 Chosen 插件更改下拉列表的宽度

html - 垂直对齐具有多个跨度的 div 内的多行文本

html - float 文本到右侧 CSS

jquery - 垂直 Owl Carousel slider

css - 如何使文本水平和垂直居中?

css - Bootstrap center 导航栏中间