From Pure CSS I want to combine aligned forms:
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form pure-form-aligned">
<fieldset>
<div class="pure-control-group">
<label for="name">Username</label>
<input id="name" type="text" placeholder="Username">
</div>
<div class="pure-control-group">
<label for="password">Password</label>
<input id="password" type="password" placeholder="Password">
</div>
<div class="pure-control-group">
<label for="email">Email</label>
<input id="email" type="email" placeholder="Email">
</div>
</fieldset>
</form>
with grouped inputs:
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form">
<fieldset class="pure-group">
<input type="text" placeholder="Username">
<input type="text" placeholder="Password">
<input type="email" placeholder="Email">
</fieldset>
</form>
so that the inputs are stacked while still allowing horizontally aligned labels to be placed to the left. How can I achieve this effect?
I came to a solution by applying the grouped input styling to a modified aligned form layout:
.pure-form-aligned .pure-group .pure-control-group {
margin: 0;
}
.pure-form.pure-form-aligned .pure-group .pure-control-group input {
display: inline-block;
position: relative;
margin: 0 0 -1px;
border-radius: 0;
top: -1px;
}
.pure-form-aligned .pure-group .pure-control-group:first-child input {
top: 1px;
border-radius: 4px 4px 0 0;
margin: 0;
}
.pure-form-aligned .pure-group .pure-control-group:last-child input {
top: -2px;
border-radius: 0 0 4px 4px;
margin: 0;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form pure-form-aligned">
<fieldset class="pure-group">
<div class="pure-control-group">
<label for="name">Username</label>
<input id="name" type="text" placeholder="Username">
</div>
<div class="pure-control-group">
<label for="password">Password</label>
<input id="password" type="password" placeholder="Password">
</div>
<div class="pure-control-group">
<label for="email">Email</label>
<input id="email" type="email" placeholder="Email">
</div>
</fieldset>
</form>
You can wrap the <label>s in a div and place that div on the left side of the <fieldset>. Like this :-
div.labels{
display : inline-block;
height : 100px;
}
div.labels div{
display : flex;
align-items : center;
justify-content : right;
height : 33.33%;
}
fieldset.pure-group{
height : 100px;
display : inline-block;
}
fieldset.pure-group input{
height : 33.33%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/forms-min.css" rel="stylesheet" />
<form class="pure-form">
<div class="labels">
<div>
<label>Name</label>
</div>
<div>
<label>Password</label>
</div>
<div>
<label>Email</label>
</div>
</div>
<fieldset class="pure-group">
<input type="text" id="name" placeholder="Username">
<input type="text" placeholder="Password">
<input type="email" placeholder="Email">
</fieldset>
</form>
Related
<form action="add.jsp" method="post">
<div class="form-group">
<label>Order ID</label>
<input type="text" name="Order_ID" class="form-control">
<label>Order Date</label>
<input type="text" name="Order_Date" class="form-control">
<label>Customer Name</label>
<input type="text" name="Customer_Name" class="form-control">
<label>Customer Number</label>
<input type="text" name="Customer_ID" class="form-control">
<label>Order Amount</label>
<input type="text" name="Order_Amount" class="form-control">
<label>Notes</label>
<input type="text" name="Notes" class="form-control">
</div>
</form>
I have this type of box design for input
But I want this type of input area(Underlined)
You can try:
input {
border: none;
border-bottom: 1px solid #ccc;
}
You can easily do this with border-bottom property. But before that, you'll need to reset the default border first using border: none;
Follow this -
input
input {
border: none;
border-bottom: 1px solid #ccc;
}
Order: <input type="text" name="Order_ID" class="form-control">
Added css code in <input> changed border with border-bottom
So will like this, example:
border: 0;
outline: 0;
background: transparent;
border-bottom: 1px solid black;
Then output will like this
input.form-control {
border: 0;
outline: 0;
background: transparent;
border-bottom: 1px solid black;
}
.form-group {
display: grid;
grid-template-columns: min-content auto;
grid-gap: 10px;
white-space: nowrap;
}
<form action="add.jsp" method="post">
<div class="form-group">
<label>Order ID</label>
<input type="text" name="Order_ID" class="form-control">
<label>Order Date</label>
<input type="text" name="Order_Date" class="form-control">
<label>Customer Name</label>
<input type="text" name="Customer_Name" class="form-control">
<label>Customer Number</label>
<input type="text" name="Customer_ID" class="form-control">
<label>Order Amount</label>
<input type="text" name="Order_Amount" class="form-control">
<label>Notes</label>
<input type="text" name="Notes" class="form-control">
</div>
</form>
for your oritantion to have the input at the right of the label you can use css-grid. will look the cleanest. For only havin a bottom broder, remoev all border of the input with border: none; and add a border at the bottom with border-bottom. Note that border-bottom has to come after border as otherwise all border will be removed.
.form-group {
display: grid;
grid-template-columns: min-content auto;
grid-gap: 10px;
white-space: nowrap;
}
.form-group input {
border: none;
border-bottom: 1px solid grey;
}
<form action="add.jsp" method="post">
<div class="form-group">
<label>Order ID</label>
<input type="text" name="Order_ID" class="form-control">
<label>Order Date</label>
<input type="text" name="Order_Date" class="form-control">
<label>Customer Name</label>
<input type="text" name="Customer_Name" class="form-control">
<label>Customer Number</label>
<input type="text" name="Customer_ID" class="form-control">
<label>Order Amount</label>
<input type="text" name="Order_Amount" class="form-control">
<label>Notes</label>
<input type="text" name="Notes" class="form-control">
</div>
</form>
Here is one way, just need to add CSS and adjust borders.
Run the snippet to see.
.form-group {
display: grid;
grid-template-columns: min-content auto;
grid-gap: 15px;
}
label {
font-size: 18px;
color: #333;
height: 20px;
width: 150px;
text-align: left;
}
input {
margin: 8px 0;
height: 20px;
box-sizing: border-box;
border: none;
border-bottom: 2px solid blue;
}
<form action="add.jsp" method="post">
<div class="form-group">
<label>Order ID</label>
<input type="text" name="Order_ID" class="form-control">
</div>
<div class="form-group">
<label>Order Date</label>
<input type="text" name="Order_Date" class="form-control">
</div>
<div class="form-group">
<label>Customer Name</label>
<input type="text" name="Customer_Name" class="form-control">
</div>
<div class="form-group">
<label>Customer Number</label>
<input type="text" name="Customer_ID" class="form-control">
</div>
<div class="form-group">
<label>Order Amount</label>
<input type="text" name="Order_Amount" class="form-control">
</div>
<div class="form-group">
<label>Notes</label>
<input type="text" name="Notes" class="form-control">
</div>
</form>
I'm trying to make a contact form in Reactjs for my website, but I'm unable to make the form itself be displayed as a block. Right now, the form is being displayed as if it were on the same line, despite the display being set to block.
I'm not sure why I'm having this problem
Relevant Code
ContactPage.js
import React from 'react';
// CSS import statements
import '../css/Base.css';
import '../css/ContactPage.css';
// Component import statements
function Contact() {
return(
<div className='container'>
<div className='contact-form'>
Fields marked with an * are required.
<label for="name">Name *</label>
<input type="text" name="name" />
<label for="email">Email *</label>
<input type="text" name="email" />
<label for="subject">Subject *</label>
<input type="text" name="subject" />
<label for="message">Message *</label>
<input type="text" name="message" />
<button>Submit</button>
</div>
</div>
)
}
export default Contact;
ContactPage.css
.contact-form {
display: block;
padding: 0px 10px;
}
Try this.
ContactPage.js
import React from 'react';
// CSS import statements
import '../css/Base.css';
import '../css/ContactPage.css';
// Component import statements
function Contact() {
return(
<div className='container'>
<div id='contact-form'>
Fields marked with an * are required.
<div className='row'>
<div className="label">
<label for="name">Name *</label>
</div>
<div class="form-input">
<input type="text" name="name" className="form-control"/>
</div>
</div>
<div className='row'>
<div className="label">
<label for="email">Email *</label>
</div>
<div className="form-input">
<input type="text" name="email" className="form-control"/>
</div>
</div>
<div className='row'>
<div className="label">
<label for="subject">Subject *</label>
</div>
<div className="form-input">
<input type="text" name="subject" className="form-control"/>
</div>
</div>
<div className='row'>
<div className="label">
<label for="message">Message *</label>
</div>
<div className="form-input">
<input type="text" name="message" className="form-control"/>
</div>
</div>
<div className='form-button'>
<button>Submit</button>
</div>
</div>
</div>
)
}
export default Contact;
ContactPage.css
#contact-form {
display: block;
padding: 0px 10px;
}
.row:after{
content: "";
display: table;
clear: both;
}
.form-button{
margin-top:10px;
}
.label {
float: left;
width: 15%;
margin-top: 6px;
}
.form-input{
float: left;
width:50%;
margin-top: 6px;
}
Preview --> https://codesandbox.io/s/vigilant-lumiere-ue3k1?file=/src/App.js
Re-edit your contact form structure to this:
HTML
<div className='contact-form'>
Fields marked with an * are required.
<div class="form-group">
<label for="name">Name *</label>
<input type="text" name="name" />
</div>
<div class="form-group">
<label for="email">Email *</label>
<input type="text" name="email" />
</div>
<div class="form-group">
<label for="subject">Subject *</label>
<input type="text" name="subject" />
</div>
<div class="form-group">
<label for="message">Message *</label>
<input type="text" name="message" />
</div>
<button>Submit</button>
</div>
Wrap it inside a div called form-group and in your css
ContactPage.css
.contact-form {
display: block;
padding: 0px 10px;
}
.contact-form .form-group {
width:100%;
display:block;
position: relative;
}
.contact-form .button {
display:block;
margin:0 auto;
}
I have this form:
I want the last name input to be on the same line as the first name. I used float-left for both of them but it doesn't work.
.first-name {
float: left;
margin-right: 20px;
}
.last-name {
float: left;
}
input,
label {
display: block;
}
<form action="" method="POST">
<section>
<div class="first-name">
<label for="first-name">First name</label>
<input type="text" id="first-name" required> </div>
<div class="last-name">
<label for="last-name">Last name </label>
<input type="text" id="last-name" required></div>
<br style="clear:both;" />
</section>
<section>
<label for="company">Company </label>
<input type="text" id="company" required>
<label for="email">E-mail</label>
<input type="email" id="email" required>
</section>
<input class="submit" type="submit" value="REGISTER">
</form>
Use flexbox to solve this.
section.justify-content-btw {
display: flex;
justify-content: space-between;
}
input,
label {
display: block;
}
<form action="" method="POST">
<section class="justify-content-btw">
<div class="first-name">
<label for="first-name">First name</label>
<input type="text" id="first-name" required> </div>
<div class="last-name">
<label for="last-name">Last name </label>
<input type="text" id="last-name" required></div>
<br style="clear:both;" />
</section>
<section>
<label for="company">Company </label>
<input type="text" id="company" required>
<label for="email">E-mail</label>
<input type="email" id="email" required>
</section>
<input class="submit" type="submit" value="REGISTER">
</form>
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!">
This question already has answers here:
Justify elements with fix space (variable width)
(2 answers)
Closed 6 years ago.
I have designed the following HTML form :
div{
display: inline-block;
}
fieldset{
display: inline-block;
}
<body>
<form action="index.html" method="post">
<h1><center>FCNB Loan Request</center></h1>
<center>
<fieldset>
<div>
<label for="name">Branch Name and Code:</label>
<input type="text" id="name" name="user_name">
<label for="pfnumber">PF Number:</label>
<input type="text" id="name" name="pfnumber">
<label for="cpname">Contact Person Name:</label>
<input type="text" id="name" name="cpname">
<label for="cnumber">Contact Number:</label>
<input type="text" id="name" name="cnumber">
</div>
<hr> </hr>
<!-- Input Fields -->
<div>
<label for="customer">Customer:</label>
<input type="text" id="name" name="customer">
<label for="cif">CIF Number:</label>
<input type="text" id="name" name="cif">
<label for="dfgt">If exporter, mention DGFT No. : </label>
<input type="text" id="name" name="dfgt">
<label for="activity">Activity:</label>
<input type="text" id="name" name="activity">
</div>
<hr />
</fieldset>
</center>
</form>
</body>
The form elements are aligned in a centered manner without covering the width of the screen. I would like the form elements to be aligned in a "justified" manner, ie, to cover the width of the screen. How can this be done?
I have added the following snippet to the style:
form label, form input {
display: block;
margin-bottom: 10px;
}
This will make your label and input tag take the full width of browser and also add some margin bottom to it.
div{
display: inline-block;
}
fieldset{
display: inline-block;
}
form label, form input {
display: block;
margin-bottom: 10px;
}
<body>
<form action="index.html" method="post">
<h1><center>FCNB Loan Request</center></h1>
<center>
<fieldset>
<div>
<label for="name">Branch Name and Code:</label>
<input type="text" id="name" name="user_name">
<label for="pfnumber">PF Number:</label>
<input type="text" id="name" name="pfnumber">
<label for="cpname">Contact Person Name:</label>
<input type="text" id="name" name="cpname">
<label for="cnumber">Contact Number:</label>
<input type="text" id="name" name="cnumber">
</div>
<hr> </hr>
<!-- Input Fields -->
<div>
<label for="customer">Customer:</label>
<input type="text" id="name" name="customer">
<label for="cif">CIF Number:</label>
<input type="text" id="name" name="cif">
<label for="dfgt">If exporter, mention DGFT No. : </label>
<input type="text" id="name" name="dfgt">
<label for="activity">Activity:</label>
<input type="text" id="name" name="activity">
</div>
<hr />
</fieldset>
</center>
</form>
</body>
Hi change width:100% with form elements,
form label, form input {
width:100%;
}
div{
display: inline-block;
}
fieldset{
display: inline-block;
}
form label, form input {
width:100%;
}
<body>
<form action="index.html" method="post">
<h1><center>FCNB Loan Request</center></h1>
<center>
<fieldset>
<div>
<label for="name">Branch Name and Code:</label>
<input type="text" id="name" name="user_name">
<label for="pfnumber">PF Number:</label>
<input type="text" id="name" name="pfnumber">
<label for="cpname">Contact Person Name:</label>
<input type="text" id="name" name="cpname">
<label for="cnumber">Contact Number:</label>
<input type="text" id="name" name="cnumber">
</div>
<hr> </hr>
<!-- Input Fields -->
<div>
<label for="customer">Customer:</label>
<input type="text" id="name" name="customer">
<label for="cif">CIF Number:</label>
<input type="text" id="name" name="cif">
<label for="dfgt">If exporter, mention DGFT No. : </label>
<input type="text" id="name" name="dfgt">
<label for="activity">Activity:</label>
<input type="text" id="name" name="activity">
</div>
<hr />
</fieldset>
</center>
</form>
</body>