3

I have this code below which is a simple html form. What i'm trying to do is make all of the inputs have max widths inside the form-panel and look something like the image below.

I tried setting max-width for all the inputs inside the panel but it doesn't seem to be working. Any help would be greatly appreciated.

enter image description here

input[type="text"],
input[type="email"],
input[type="password"] {
  padding: 4px 20px;
  height: 35px;
  border: 1px solid black;
  margin: 10px;
  border-radius: 3px;
  max-width: 100%;
}

.form-panel {
  display: table;
  background-color: #b7bcbe;
}
<body>
  <div class="form-panel">
    <div class="form-name">
      <input type="text" name="fname" placeholder="First Name">
      <input type="text" name="lname" placeholder="Last Name">
      <br>
    </div>
    <div class="form-email">
      <input type="email" name="email" placeholder="Email Address">
      <br>
    </div>
    <div class="form-password">
      <input type="password" name="password" placeholder="Password">
      <input type="password" name="cpassword" placeholder="Comfirm Password">
    </div>
  </div>
  <input type="submit" class="btn btn-default submit-button" value="Sign up!">


</body>

3 Answers 3

6

You can use flex-box instead of table.

As you use display: table - the column will have the same width (there is no colspan option)

Use display: flex for each columns and set flex-grow: 1 so that all elements will grow up and fill the parent.

input[type="text"],
input[type="email"],
input[type="password"] {
  padding: 4px 20px;
  height: 35px;
  border: 1px solid black;
  margin: 10px;
  border-radius: 3px;
  flex-grow: 1;
}

.form-row {
  flex-direction: row;
  display: flex;
}

.form-panel {
  background-color: #b7bcbe;
}
<body>
  <div class="form-panel">
    <div class="form-row form-name">
      <input type="text" name="fname" placeholder="First Name">
      <input type="text" name="lname" placeholder="Last Name">
      <br>
    </div>
    <div class="form-row form-email">
      <input type="email" name="email" placeholder="Email Address">
      <br>
    </div>
    <div class="form-row form-password">
      <input type="password" name="password" placeholder="Password">
      <input type="password" name="cpassword" placeholder="Comfirm Password">
    </div>
  </div>
  <input type="submit" class="btn btn-default submit-button" value="Sign up!">


</body>

Sign up to request clarification or add additional context in comments.

Comments

1

You have written common css for all input elements..write separate css for that particular input field and put important.

input[type="text"],
input[type="email"],
input[type="password"] {
  padding: 4px 20px;
  height: 35px;
  border: 1px solid black;
  margin: 10px;
  border-radius: 3px;
  max-width: 100%;
}

.form-panel {
  display: table;
  background-color: #b7bcbe;
}
<body>
  <div class="form-panel">
    <div class="form-name">
      <input type="text" name="fname" placeholder="First Name">
      <input type="text" name="lname" placeholder="Last Name">
      <br>
    </div>
    <div class="form-email">
      <input type="email" name="email" style="width: 100%;max-width: 86%;" placeholder="Email Address">
      <br>
    </div>
    <div class="form-password">
      <input type="password" name="password" placeholder="Password">
      <input type="password" name="cpassword" placeholder="Comfirm Password">
    </div>
  </div>
  <input type="submit" class="btn btn-default submit-button" value="Sign up!">


</body>

5 Comments

explain what you did
You have to set inline Css for the particular input tag.
I mean inside your answer when other OP see it they understand what to do
@A.Sakkeer hmmm that works but isit the best way to do?
I have changed my inline style for that 'Email Address Field'.
1

just add this line:

.form-email input {width: calc(100% - 20px);}
                                       ^--------[margin-left + margin-right]

input[type="text"],
input[type="email"],
input[type="password"] {
  padding: 4px 20px;
  height: 35px;
  border: 1px solid black;
  margin: 10px;
  border-radius: 3px;
  max-width: 100%;
}

.form-panel {
  display: table;
  background-color: #b7bcbe;
}

.form-email input {width: calc(100% - 20px);}
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <div class="form-panel">
    <div class="form-name">
      <input type="text" name="fname" placeholder="First Name">
      <input type="text" name="lname" placeholder="Last Name">
      <br>
    </div>
    <div class="form-email">
      <input type="email" name="email" placeholder="Email Address">
      <br>
    </div>
    <div class="form-password">
      <input type="password" name="password" placeholder="Password">
      <input type="password" name="cpassword" placeholder="Comfirm Password">
    </div>
  </div>
  <input type="submit" class="btn btn-default submit-button" value="Sign up!">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.