Behar
Behar

Reputation: 269

select input is bigger than input field in bootstrap 4

I have a select field and two input fields but the select tag is bigger than the other two (see picture). I am using Bootstrap 4.3. Can someone help me to make it as big as the other one? I would appreciate your help!

Here is my code:

<div class="container content-center" id="margin">
    <form name="formcalc">
        <div class="form-group row">
            <label for="staticEmail" class="col-sm-2 col-form-label">Output 1</label>
            <select class="col-sm-10 form-control" id="mySelect" onchange="myFunction();setOne();">
                <option value="0">CHF 0</option>
                <option value="75000">CHF 75'000</option>
                <option value="100000">CHF 100'000</option>
            </select>
        </div>
        <fieldset disabled>
            <div class="form-group row">
                <label for="staticEmail" class="col-sm-2 col-form-label">Output 2</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="n1" name="txtres" value="CHF " readonly>
                </div>
            </div>
            <div class="form-group row">
                <label for="staticEmail" class="col-sm-2 col-form-label">Output 3</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="n2" name="txtres2" value="CHF " readonly>
                </div>
            </div>
        </fieldset>
        <button type="button" class="btn btn-outline-danger" id="toggle" data-toggle="modal"
            data-target="#exampleModal">
            button
        </button>
    </form>
    <hr class="featurette-divider">

    <section class="container">
        <p class="lead" id="demo"></p>
    </section>
</div>

picture

Upvotes: 2

Views: 1610

Answers (3)

Doug F
Doug F

Reputation: 884

You can do as you did with the select element and not have it in a div, like so:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css" integrity="sha384-PDle/QlgIONtM1aqA2Qemk5gPOE7wFq8+Em+G/hmo5Iq0CCmYZLv3fVRDJ4MMwEA" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/js/bootstrap.min.js" integrity="sha384-7aThvCh9TypR7fIc2HV4O/nFMVCBwyIUKL8XCtKE+8xgCgl/PQGuFsvShjr74PBp" crossorigin="anonymous"></script>  <title>JS Bin</title>
</head>
<body>
<div class="container content-center" id="margin">
    <form name="formcalc">
        <div class="form-group row">
            <label for="staticEmail" class="col-sm-2 col-form-label">Output 1</label>
            <select class="col-sm-10 form-control" id="mySelect" onchange="myFunction();setOne();">
                <option value="0">CHF 0</option>
                <option value="75000">CHF 75'000</option>
                <option value="100000">CHF 100'000</option>
            </select>
        </div>
        <fieldset disabled>
            <div class="form-group row">
                <label for="staticEmail" class="col-sm-2 col-form-label">Output 2</label>
             
                    <input type="text" class="form-control col-sm-10" id="n1" name="txtres" value="CHF " readonly>
           
            </div>
            <div class="form-group row">
                <label for="staticEmail" class="col-sm-2 col-form-label">Output 3</label>
          
                    <input type="text" class="form-control col-sm-10" id="n2" name="txtres2" value="CHF " readonly>
              
            </div>
        </fieldset>
        <button type="button" class="btn btn-outline-danger" id="toggle" data-toggle="modal"
            data-target="#exampleModal">
            button
        </button>
    </form>
    <hr class="featurette-divider">

    <section class="container">
        <p class="lead" id="demo"></p>
    </section>
</div>
</body>
</html>

Upvotes: 0

kukkuz
kukkuz

Reputation: 42352

Instead of giving col-sm-10 on the select element, wrap the select in a <div class="col-sm-10"> - see demo below:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

<div class="container content-center" id="margin">
  <form name="formcalc">
    <div class="form-group row">
      <label for="staticEmail" class="col-sm-2 col-form-label">Output 1</label>
      <div class="col-sm-10">
        <select class="form-control" id="mySelect" onchange="myFunction();setOne();">
          <option value="0">CHF 0</option>
          <option value="75000">CHF 75'000</option>
          <option value="100000">CHF 100'000</option>
        </select>
      </div>
    </div>
    <fieldset disabled>
      <div class="form-group row">
        <label for="staticEmail" class="col-sm-2 col-form-label">Output 2</label>
        <div class="col-sm-10">
          <input type="text" class="form-control" id="n1" name="txtres" value="CHF " readonly>
        </div>
      </div>
      <div class="form-group row">
        <label for="staticEmail" class="col-sm-2 col-form-label">Output 3</label>
        <div class="col-sm-10">
          <input type="text" class="form-control" id="n2" name="txtres2" value="CHF " readonly>
        </div>
      </div>
    </fieldset>
    <button type="button" class="btn btn-outline-danger" id="toggle" data-toggle="modal" data-target="#exampleModal">
            button
        </button>
  </form>
  <hr class="featurette-divider">

  <section class="container">
    <p class="lead" id="demo"></p>
  </section>
</div>

Upvotes: 1

Goose
Goose

Reputation: 4821

The <fieldset> element is causing its own padding. You should either move the <select> inside the <fieldset>, give it its own <fieldset>, or remove <fieldset> from the inputs.

Upvotes: 0

Related Questions