How to center button and placeholder's text vertically - html

I have a problem, I used bootstrap to make a website and used its input and button classes, of course as I can see that's not the problem in bootstrap. I don't know how to center placeholder/input text and button text vertically. I read about line-height but it didn't help me.
BUTTONS:
<a
href="#"
class="button-early-access btn bg-dark"
>Early access</a
>
INPUTS:
<form>
<div class="form-group">
<input
type="text"
class="form-control p-20 col-md-12"
id="firstLastName"
aria-describedby="firstLastNameFan"
placeholder="First and last name"
/>
</div>
<div class="form-group">
<input
type="email"
class="form-control col-md-12"
id="exampleInputEmail1"
aria-describedby="emailHelpFan"
placeholder="Enter email"
/>
</div>
<div class="form-group">
<input
type="text"
class="form-control"
id="teamFan"
placeholder="What is your favorite sports team?"
/>
</div>
<div class="form-group">
<input
type="text"
class="form-control"
id="topAthlete"
placeholder="Name one athlete you would like to meet?"
/>
</div>
<button type="submit" class="btn button-early-access">
Submit
</button>
</form>
.button-early-access {
background: linear-gradient(266.81deg, #009ebe -3.26%, #049c69 92.97%);
border-radius: 27px;
font-weight: bold;
color: white;
padding: 11px 35px;
}
.form-group input {
text-indent: 20px;
width: 100%;
/* min-width: 726px; */
font-size: 2em;
}

Try a different font besides Khula. That font has a lot of space for descenders, which is likely what you are seeing.

If you still want to use that font you have to correct the vertical inequality with padding.
.button-early-access {
background: linear-gradient(266.81deg, #009ebe -3.26%, #049c69 92.97%);
border-radius: 27px;
font-weight: bold;
color: white;
padding: 11px 35px 7px;
font-family: 'Khula', sans-serif;
}
.form-group input {
font-family: 'Khula', sans-serif;
text-indent: 20px;
width: 100%;
font-size: 2em;
padding-top: 8px;
}
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Khula:wght#300;700&display=swap" rel="stylesheet">
<form>
<div class="form-group">
<input
type="text"
class="form-control p-20 col-md-12"
id="firstLastName"
aria-describedby="firstLastNameFan"
placeholder="First and last name"
/>
</div>
<div class="form-group">
<input
type="email"
class="form-control col-md-12"
id="exampleInputEmail1"
aria-describedby="emailHelpFan"
placeholder="Enter email"
/>
</div>
<div class="form-group">
<input
type="text"
class="form-control"
id="teamFan"
placeholder="What is your favorite sports team?"
/>
</div>
<div class="form-group">
<input
type="text"
class="form-control"
id="topAthlete"
placeholder="Name one athlete you would like to meet?"
/>
</div>
<button type="submit" class="btn button-early-access">
Submit
</button>
<a
href="#"
class="button-early-access btn bg-dark"
>Early access</a
>
</form>

Related

Read-only form alignment needs to be consistent

I have a bit of an issue getting some of my form inputs to align well because they are read-only and hence do not take the same dimensions as the actual visible inputs. I've supplied two images to help you see:
UNALIGNED FORM SECTON
ALIGNED FORM SECTION
label[class="statlabel"] {
font-family: "Amaranth", sans-serif;
display: inline-block;
float: left;
width: 250px;
text-align: right;
padding-right: 10px;
clear: left;
padding-top: 15px;
}
.input CSS
.input {
font-size: 20px;
color: #5a5854;
background-color: #f2f2f2;
border: 1px solid #bdbdbd;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
padding: 5px 5px 5px 30px;
background-repeat: no-repeat;
background-position: 8px 9px;
display: inline-block;
margin-bottom: 10px;
text-indent: 15px;
width: 250px;
}
<a name="personalInfo"></a>
<h5 class="stath5"><span class="badge badge-secondary">2.</span> Please review your personal information</h5>
<EditForm Model="#Data.PersonalInfo" style="max-width:800px;" onkeydown="javascript: DisableEnterKey();">
<label id="fullNameLabel" class="statlabel" for="fullName">Full name:</label>
<span class="nameLabel"><label id="fullName">#Data.PersonalInfo.FullName</label></span>
<br />
<label id="statusLabel" class="statlabel" for="communityStatus">Spanish Lookout Community status:</label>
<span class="statuslabel"><label id="slcStatus">#Data.PersonalInfo.SLCStatus</label></span>
<br />
<label id="boxNumLabel" class="statlabel" for="boxNum">Box Number:</label>
<span class="boxLabel"><label id="boxNum">#Data.PersonalInfo.BoxNumber</label></span>
<br />
<div class="input-container">
<label class="statlabel" for="phone">Phone Number:</label>
<InputText type="tel" id="phone" class="input" #bind-Value="#Data.PersonalInfo.Phone" placeholder="What's your phone number?" />
</div>
<br /><hr class="statHR" />
<div class="input-container1">
<label class="statlabel" for="email">Email <span class="badge badge-success">Optional</span>:</label>
<InputText type="email" id="email" class="input" #bind-Value="#Data.PersonalInfo.Email" placeholder="What's your email address?" />
</div>
</EditForm>
</div>
To clarify, I want the first image to look like the second image. Any help would be invaluable. Thanks for your time!
this should get you started. Use Flex!
.row{
display:flex;
align-items:center;
border:solid black 1px;}
label{
width:25vw;}
EditForm{
display:flex;
flex-direction:column;
}
hr{
width:100%;}
<a name="personalInfo"></a>
<h5 class="stath5"><span class="badge badge-secondary">2.</span> Please review your personal information</h5>
<EditForm Model="#Data.PersonalInfo" style="max-width:800px;" onkeydown="javascript: DisableEnterKey();">
<div class='row'>
<label id="fullNameLabel" class="statlabel" for="fullName">Full name:</label>
<span class="nameLabel"><label id="fullName">#Data.PersonalInfo.FullName</label></span>
</div>
<div class='row'>
<label id="statusLabel" class="statlabel" for="communityStatus">Spanish Lookout Community status:</label>
<span class="statuslabel"><label id="slcStatus">#Data.PersonalInfo.SLCStatus</label></span>
</div>
<div class='row'>
<label id="boxNumLabel" class="statlabel" for="boxNum">Box Number:</label>
<span class="boxLabel"><label id="boxNum">#Data.PersonalInfo.BoxNumber</label></span>
</div>
<div class='row'>
<div class="input-container">
<label class="statlabel" for="phone">Phone Number:</label>
<input type="tel" id="phone" class="input" #bind-Value="#Data.PersonalInfo.Phone" placeholder="What's your phone number?" />
</div></div>
<div class='row'>
<hr class="statHR" />
</div>
<div class='row'>
<div class="input-container1">
<label class="statlabel" for="email">Email <span class="badge badge-success">Optional</span>:</label>
<input type="email" id="email" class="input" #bind-Value="#Data.PersonalInfo.Email" placeholder="What's your email address?" />
</div>
</div>
</EditForm>
</div>

HTML form input width

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.
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>
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>
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>
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!">

centering within a form within a section

Im using bootstrap 4 and have this form in a section that Im having issues with centering the button and making it the length of the two columns so that its even with input-boxes outer border. currently if i just have button at 100% width it appears centered but is longer than the inputs boxes so it looks off. Do I have it structured correctly? I used a form off there examples and am not sure if this is correct or if there is a better way.
here is my codepen:https://codepen.io/robot_head/full/qKQwqe/
html for that section:
<div class="container-fluid bg-3 text-center" id="contact">
<h3>CONTACT US</h3><br>
<div class="container">
<div class="col-sm-8 col-sm-push-2">
<form role="form">
<br style="clear:both">
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="control" id="firstname" name="firstname" placeholder="First Name" required>
</div>
<div class="form-group">
<input type="text" class="control" id="email" name="email" placeholder="Email" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" class="control" id="lastName" name="lastName" placeholder="Last Name" required>
</div>
<div class="form-group">
<input type="text" class="control" id="phone" name="phone" placeholder="Phone" required>
</div>
</div>
<button type="button" id="submit" name="submit" class="btn btn-primary pull-right">SEND</button>
</form>
</div>
</div>
</div>
css:
#contact{
background-color: #febb2e;
height: 500px;
color: #000;
}
.form-area
{
background-color: #FAFAFA;
padding: 10px 40px 60px;
margin: 10px 0px 60px;
border: 1px solid GREY;
}
.control{
display: block;
width: 100%;
height: 50px;
padding: 6px 10px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
border: 1px solid #fff;
border-radius: 10px;
}
button#submit {
background-color: #8d1f2d;
border-color: #8d1f2d;
width: 100%;
border-radius: 10px;
}
you can fix them in many ways, the reason for the issue is that the col-sm-6 class has a padding 15px on both sides, and your button does not have any padding. As a quick fix either you can wrap your button in a div with class col-sm-12 or just add a padding of 15px on left and right of the button.

Unable to center button

I faced a problem about getting a button to center, I tried the text-align: center, but it didn't work.
.regis-btn {
border-radius: 0px;
text-align: center;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
}
<form action="" method="post" role="form">
<div class="form-group">
<label for="cellphone">Cellphone Number</label>
<input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
</div>
<div class="form-group">
<label for="name">Username</label>
<input type="text" class="form-control" id="name" placeholder="Username">
</div>
<div class="form-group">
<label for="seriesnum">Series Number</label>
<input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
</div>
<button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
<span> Register </span>
</button>
</form>
You can try this:
<div class="form-group text-center">
<button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;"></button>
</div>
text-align: center only centers the content within the element. So what you have done was to center the text within the button.
If your button is the only element in the row, wrap the button in a div instead.
I added a demo to show that it works:
.btn-container {
text-align: center;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form action="" method="post" role="form">
<div class="form-group">
<label for="cellphone">Cellphone Number</label>
<input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
</div>
<div class="form-group">
<label for="name">Username</label>
<input type="text" class="form-control" id="name" placeholder="Username">
</div>
<div class="form-group">
<label for="seriesnum">Series Number</label>
<input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
</div>
<div class="btn-container">
<button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
<span>Register</span>
</button>
</div>
</form>
Use margin: 0 auto; and display: block; for button.
.regis-btn {
border-radius: 0px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
text-align: center;
margin: 0 auto;
display: block;
}
<form action="" method="post" role="form">
<div class="form-group">
<label for="cellphone">Cellphone Number</label>
<input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
</div>
<div class="form-group">
<label for="name">Username</label>
<input type="text" class="form-control" id="name" placeholder="Username">
</div>
<div class="form-group">
<label for="seriesnum">Series Number</label>
<input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
</div>
<button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
<span>
Register
</span>
</button>
</form>
Use My code that is working very well.
.regis-btn {
border-radius: 0px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<form action="" method="post" role="form">
<div class="form-group">
<label for="cellphone">Cellphone Number</label>
<input type="text" class="form-control" id="cellphone" minlength="10" placeholder="Cellphone">
</div>
<div class="form-group">
<label for="name">Username</label>
<input type="text" class="form-control" id="name" placeholder="Username">
</div>
<div class="form-group">
<label for="seriesnum">Series Number</label>
<input type="text" class="form-control" id="seriesnum" placeholder="Series Number">
</div>
<div class="text-center">
<button type="button" class="btn regis-btn" id="register" style="background: #FFCC00;">
<span> Register </span>
</button>
</div>
</form>

How can I line up this button with the textboxes?

I would like the left side of the button flush with the textboxes. I'm using bootstrap 3 if that makes a difference. Here is my html code for the form. I can add my CSS if that's necessary as well. Thank you.
h1 {
font-size:83px;
}
.btn-primary {
background: #ffffff;
border-color: #ffffff;
color: #f05324;
}
.btn-default, .btn-default:hover, .btn-default:focus, .btn-default:active, .btn-default.active, .open > .dropdown-toggle.btn-default {
background: #ffffff;
border-color: #ffffff;
color: #f05324;
}
.panel-default {
border: none;
}
input[type="text"] {
color:white !important;
}
input[type="email"] {
color:white !important;
}
.model-content {
color:black !important;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
.text-center {
text-align: center;
}
.navbar-default {
background-color: #000000;
}
body {
background: #f05324 !important;
margin-bottom: 80px;
color: #ffffff;
}
.page-header, .panel-body, .panel, .panel-default, .col-lg-9, .row {
background: #f05324 !important;
}
.form-control{
background-color: #f05324;
color: #000000;
}
hr {
border-color: #ffffff;
background-color: #ffffff;
color: #ffffff;
}
.link {
color: #ffffff;
}
.page-header {
margin-top: 0;
}
.panel-body {
padding-top: 0;
}
.img-featured {
margin-top : 15px;
margin-bottom: 15px;
margin-right : 15px;
}
.img-project{
margin-top : 15px;
margin-bottom: 15px;
}
.show-onclick {
display: none;
}
.show-onclick1 {
display: none;
}
.block {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
margin-left: // half the width of your img
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<form class="form-horizontal" method="post" action="submit.php" enctype="multipart/form-data">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">NAME:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">EMAIL:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" name="email">
</div>
</div>
<div class="form-group">
<label for="phoneNumber" class="col-sm-2 control-label">PHONE:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="phone" name="phone">
</div>
</div>
<div class="form-group">
<label for="major" class="col-sm-2 control-label">MAJOR:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="major" name="major">
</div>
</div>
<hr>
<div class="form-group">
<label for="itemForSale" class="col-sm-2 control-label">ITEM FOR SALE:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="itemForSale1" name="itemForSale1">
</div>
</div>
<div class="form-group">
<label for="quantity" class="col-sm-2 control-label">QUANTITY:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="quantity1" name="quantity1">
</div>
</div>
<div class="form-group">
<label for="price1" class="col-sm-2 control-label">PRICE:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="price1" name="price1">
</div>
</div>
<div class="form-group">
<label for="itemOneImg1" class="col-sm-2 control-label">IMAGE 1:</label>
<div class="col-sm-10">
<input type="file" accept=".jpg, .jpeg, .png" class="form-control" name="itemOneImg1">
</div>
</div>
<div class="form-group">
<label for="itemOneImg2" class="col-sm-2 control-label">IMAGE 2:</label>
<div class="col-sm-10">
<input type="file" accept=".jpg, .jpeg, .png" class="form-control" name="itemOneImg2">
</div>
</div>
<input id="additional-files" type="button" value="Additional Projects" class="btn btn-default">
</form>
If you want the left edge of the button to match up with the left edge of the text boxes then you just need to add an offset using the Bootstrap grid as follows:
<form class="form-horizontal" method="post" action="submit.php" enctype="multipart/form-data">
...
<div class="form-group">
<label for="itemOneImg2" class="col-sm-2 control-label">IMAGE 2:</label>
<div class="col-sm-10">
<input type="file" accept=".jpg, .jpeg, .png" class="form-control" name="itemOneImg2">
</div>
</div>
<div class="form-group">
<!-- Adjust col-sm-X for the buttons to adjust their positioning
Could also add btn-block class to make the button span the column -->
<div class="col-sm-offset-2 col-sm-9">
<input id="additional-files" type="button" value="Additional Projects" class="btn btn-default">
</div>
<div class="col-sm-1">
<input id="submit" type="button" value="Submit" class="btn btn-default">
</div>
</div>
</form>
More details (and another example) can be found on the Bootstrap website: http://getbootstrap.com/css/#forms-horizontal
EDIT: Based on additional information in comments.