如何在Bootstrap中删除选择框的圆角?

时间:2018-07-12 06:37:39

标签: html css twitter-bootstrap bootstrap-4

我已经编写了这段代码来在引导程序中创建一个选择框,但是我想删除的角是圆的。怎么做?我尝试了很多,但是找不到任何解决方案。请帮助我。

这也是jsfiddle.net的链接

https://jsfiddle.net/ankitshri774/2redLfnc/7/

body {
  background-color: #E8E8E8;
}

label {
  float: left;
}

#main_container {
  background-color: white;
  margin-left: 10px;
  padding-left: 13px;
  margin-right: 10px;
  padding-right: 13px;
  padding-top: 13px;
  margin-top: 10px;
  box-sizing: border-box;
}

#container {
  background-color: aqua;
}

.select-wrapper {
  border: 1px solid black;
  border-radius: 0px;
}
<!doctype html>

<html lang="en">

<head>
  <title>Master Page</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="masterpage1.css">


  <!-- jQuery library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

  <!-- Latest compiled JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>


<body>



  <div id="main_container">

    <form>


      <div id="partymaster">
        <h3>Party Master</h3>
        <hr/>
      </div>

      <div class="row">

        <div class="col-md-4">
          <div class="form-group">
            <label>Category
                        <span style="color:red">*</span>
                    </label>
            <span class="select-wrapper"><select name="category" class="form-control no-radius">
                <option>A</option>      
                </select>
</span>
          </div>


        </div>


      </div>


    </form>


  </div>
</body>




</html>

4 个答案:

答案 0 :(得分:0)

将以下行添加到您的CSS文件中:

.no-radius{
    border-radius:0px !important;
}

答案 1 :(得分:0)

在下面使用代码(设置!important以防止覆盖)

border-radius4px,因为您设置为选择form-control类,并且默认情况下是引导程序定义

.no-radius{
  border-radius: unset!important;
}

请参见小提琴:https://jsfiddle.net/2redLfnc/29/

body{
    background-color:#E8E8E8;
       
    }
    
    
        label{
            float: left;
        }
        
        #main_container{
            background-color: white;
            margin-left: 10px;
            padding-left:13px;
            margin-right: 10px;
            padding-right:13px;
            padding-top: 13px;
            margin-top: 10px;
            box-sizing: border-box;
        }
    
        #container
        {
            background-color: aqua;
        }
    
       


       .select-wrapper{
        border: 1px solid black;
        border-radius: 0px;
    }

.no-radius{
  border-radius: unset!important;
}
<!doctype html>

<html lang="en">
    
<head>
<title>Master Page</title>                  
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">        
<link rel="stylesheet" href="masterpage1.css">


<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    

    <body >

            

            <div id="main_container">

    <form>
    
   
   <div id="partymaster">
       <h3>Party Master</h3>
       <hr/>
   </div>

   <div class="row">
      
            <div class="col-md-4">
                <div class="form-group">
                    <label>Category
                        <span style="color:red">*</span>
                    </label>
                    <span class="select-wrapper"><select name="category" class="form-control no-radius">
                <option>A</option>      
                </select>
</span>
                </div>
           
            
</div>


</div>


</form>


</div>
</body>




    </html>

答案 2 :(得分:0)

问题是form-control类将半径设置为4px。因此,您不能在同一元素上用不同的类覆盖它(至少我不知道该怎么做)。 因此,作为快速解决方案,我定义了一个不同的类form-control-without-radius,并在我的updated fiddle中使用了该类。

.form-control-without-radius {
  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;
} 

但是,这是整个布局的根本变化,我想它会与许多其他UI组件发生冲突。因此,您可能必须构建自己的自定义Bootstrap。有人发现使用sass很容易,而使用Bootstrap Theme Builder则让我感到更多乐趣。还有其他的。如果您对BT不太熟悉,这听起来像一个可怕的想法-但我的经验只是积极的,所以我会去做;-)

更新:我在其他帖子中看到了unset !important的想法,好主意!当然,这会使整个过程变得更简单。已相应更新my fiddle

答案 3 :(得分:0)

使用rounded-0,但只能在Bootstrap-4中使用。

body {
  background-color: #E8E8E8;
}

label {
  float: left;
}

#main_container {
  background-color: white;
  margin-left: 10px;
  padding-left: 13px;
  margin-right: 10px;
  padding-right: 13px;
  padding-top: 13px;
  margin-top: 10px;
  box-sizing: border-box;
}

#container {
  background-color: aqua;
}

.select-wrapper {
  border: 1px solid black;
  border-radius: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" />
<div id="main_container">
  <form>
    <div id="partymaster">
      <h3>Party Master</h3>
      <hr/>
    </div>
    <div class="row">
      <div class="col-md-4">
        <div class="form-group">
          <label>Category
            <span style="color:red">*</span>
          </label>
          <span class="select-wrapper">
            <select name="category" class="form-control rounded-0">
              <option>A</option>      
            </select>
          </span>
        </div>
      </div>
    </div>
  </form>
</div>