Css Align Div next to another Div - html

Can someone please help me with this css? I am very new and for some reason cannot figure something out that seems to be extremely simple. What I am trying to do is have gvw_field align next to the ew_field. I am not sure how to align the <div> 's next to each other.
http://jsfiddle.net/r45xfbex/
#gvw_field {
text-align:center;
}
<div class="clearfix">
<div id="ew_field">
<label for="ew">Empty Weight:</label>
<input type="text" name="ew" id="ew" value="">
</div>
<div id="gvw_field">
<label for="gvw" >Gross Vehicle Weight:*</label>
<input type="text" name="gvw" id="gvw" value="">
</div>
<div id="ft_field">
<label for="ft">Feet:</label>
<input type="text" name="ft" id="ft" value="">
</div>
</div>

Working jsFiddle Demo
The display: inline property will do it.
#gvw_field, #ew_field{
display: inline;
}
Readup about display property on MDN.
Working code snippet:
#gvw_field {
text-align:center;
}
#gvw_field, #ew_field{
display: inline;
}
<div class="clearfix">
<div id="ew_field">
<label for="ew">Empty Weight:</label>
<input type="text" name="ew" id="ew" value="">
</div>
<div id="gvw_field">
<label for="gvw" >Gross Vehicle Weight:*</label>
<input type="text" name="gvw" id="gvw" value="">
</div>
<div id="ft_field">
<label for="ft">Feet:</label>
<input type="text" name="ft" id="ft" value="">
</div>
</div>

Use floats to align each <div>
#gvw_field {
text-align:center;
}
.column{
width: 33.33%;
float: left;
}
<div class="clearfix">
<div class="column" id="ew_field">
<label for="ew">Empty Weight:</label>
<input type="text" name="ew" id="ew" value="">
</div>
<div class="column" id="gvw_field">
<label for="gvw" >Gross Vehicle Weight:*</label>
<input type="text" name="gvw" id="gvw" value="">
</div>
<div class="column" id="ft_field">
<label for="ft">Feet:</label>
<input type="text" name="ft" id="ft" value="">
</div>
</div>

use float and don't use same id for many items:
CSS:
.ft_field
{
float: right;
width: 50%;
}
label {
display: inline-block;
width: 170px;
}
.gvw_field {
float: right;
width: 50%;
}
HTML:
<div class="clearfix">
<div class="ew_field">
<label for="ew">Empty Weight:</label>
<input type="text" name="ew" id="ew" value=""/>
</div>
<div class="gvw_field">
<label for="gvw" >Gross Vehicle Weight:*</label>
<input type="text" name="gvw" id="gvw" value=""/>
</div>
<div class="ft_field">
<label for="ft">Feet:</label>
<input type="text" name="ft" id="ft" value=""/>
</div>
</div>
jsfiddle

You you need a display value of inline and also a given width.
#ew_field, #ft_field, #gvw_field {
text-align: center;
display: inline-block;
width: 150px; /* Adjust as needed */
}
See working demo here

Related

how to align form information together using flex

I need to do this only using flex but I am having some difficulty aligning my labels and input fields properly.This is what the end result is supposed to look like.
Any help would be appreciated!
<form>
<div class="details">
<label for="email">E-mail:</label>
<input type="email" id="email" name="email">
</div>
<div class="details">
<label for="tel">Telephone Number:</label>
<input type="tel" id="tel" name="tel">
</div>
<div class="details">
<label for="position">Position:</label>
<input type="text" id="position" name="position">
<input type="radio" name="availability" id="Part-Time" value="Part-Time">
<label for="radio">Part-Time</label>
<input type="radio" name="availability" id="Full-Time" value="Full-Time">
<label for="radio">Full-Time</label>
</div>
<div class="details">
<label for="date">Date:</label>
<input type="date" id="date" name="date">
<input type="checkbox" name="AM" id="AM" value="AM">
<label for="checkbox">AM</label>
<input type="checkbox" name="PM" id="PM" value="PM">
<label for="radio">PM</label>
</div>
<div class="details">
<label for="yearsofexperience">Years of Experience:</label>
<input type="text" id="yearsofexperience" name="yearsofexperience">
</div>
<div class="details">
</div>
<div class="details">
<label for="experience">Experience:</label>
<textarea name="experience" id="experience" rows="1" cols="20">Worked 5 years at Bayshore Veterinarian Services</textarea>
</div>
<div class="details">
<input type="submit" value="Apply Now">
</div>
</form>
I have tried all sorts of things but i cannot get them to line up. I have tried having two columns where column 1 contains the labels, while the other column contains the input field but i did not succeed.
I wrote some CSS to create the desired layout. It works without changing the provided HTML.
You can add the missing name input from the image though.
The .details > input:first-child selects the Apply Now button and set a margin-left: calc(25% + 6px), so it has a left space matching the labels and is align with other inputs.
You might as well consider using an actual <button> tag for submit though. If you do so later, you can change this selector to .details > button:first-child.
Hope this will help!
Example:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
form {
width: 600px;
display: flex;
flex-direction: column;
gap: 9px;
padding: 30px;
}
.details {
display: flex;
justify-content: flex-start;
align-items: center;
gap: 6px;
}
.details > label:first-child {
width: 25%;
display: flex;
justify-content: flex-end;
}
.details > input#date {
margin-right: 30px;
}
.details > input:first-child {
margin-left: calc(25% + 6px);
padding: 3px 6px;
}
<form>
<div class="details">
<label for="email">E-mail:</label>
<input type="email" id="email" name="email" />
</div>
<div class="details">
<label for="tel">Telephone Number:</label>
<input type="tel" id="tel" name="tel" />
</div>
<div class="details">
<label for="position">Position:</label>
<input type="text" id="position" name="position" />
<input type="radio" name="availability" id="Part-Time" value="Part-Time" />
<label for="radio">Part-Time</label>
<input type="radio" name="availability" id="Full-Time" value="Full-Time" />
<label for="radio">Full-Time</label>
</div>
<div class="details">
<label for="date">Date:</label>
<input type="date" id="date" name="date" />
<input type="checkbox" name="AM" id="AM" value="AM" />
<label for="checkbox">AM</label>
<input type="checkbox" name="PM" id="PM" value="PM" />
<label for="radio">PM</label>
</div>
<div class="details">
<label for="yearsofexperience">Years of Experience:</label>
<input type="text" id="yearsofexperience" name="yearsofexperience" />
</div>
<div class="details"></div>
<div class="details">
<label for="experience">Experience:</label>
<textarea name="experience" id="experience" rows="1" cols="20">
Worked 5 years at Bayshore Veterinarian Services</textarea
>
</div>
<div class="details">
<input type="submit" value="Apply Now" />
</div>
</form>

Input field multiple want 1 input field go to the top right side how?

I got some problem i needed help i have created a page where there multiple font control however in my prototype design on right side that a field where input are in top and right position how can i do it
I have created a snippet to test it out
.StyleForm {
margin-top: 230px;
padding-left: 50px;
}
.StyleFormRest {
padding-left: 50px;
}
.StyleFormRestRight {
text-align: right;
padding-right: 500px;
margin-bottom: 5px;
align-items: right;
}
#EmailDisplay,
#AddressDisplay,
#DescriptionDisplay {
width: 875px;
}
.createMargin {
margin-bottom: 15px;
}
.Email,
.ContactName,
.ContactNo,
.Address,
.Description {
font-size: 18px;
}
#PriceModeDisplay {
text-align: right;
}
.StyleFormRestRight .form-control {
display: inline-block;
}
<div class="mb-3 StyleForm">
<label for="Email" class="form-label"><b class="Email">Email</b></label>
<input type="email" class="col-6 form-control" id="EmailDisplay" disabled readonly>
</div>
<form class="row g-3 StyleFormRest">
<div class="col-4">
<label for="Contact Name" class="visually-hidden"><b class="ContactName">Contact Name</b></label>
<input type="text" class="form-control" id="ContactNameDisplay" disabled readonly>
</div>
<div class="col-2 createMargin">
<label for="Contact No" class="visually-hidden"><b class="ContactNo">Contact No.</b></label>
<input type="text" class="form-control" id="ContactNoDisplay" disabled readonly>
</div>
</form>
<div class="mb-3 StyleFormRest">
<label for="Address" class="form-label"><b class="Address">Address</b></label>
<input type="text" class="col-6 form-control" id="AddressDisplay" disabled readonly>
</div>
<div class="mb-3 StyleFormRest">
<label for="Description" class="form-label"><b class="Description">Description</b></label>
<textarea class="form-control" id="DescriptionDisplay" rows="3" disabled readonly></textarea>
</div>
<div class="mb-3 StyleFormRestRight">
<label for="PriceMode" class="form-label"><b class="PriceMode">Price Mode</b></label>
<input type="text" class="col-2 form-control pull-right" id="PriceModeDisplay" disabled readonly>
</div>
My snippet is showing something off as this is how my html page look like currently
So as u can see my price mode i have settle to make it at the right side however is there a way for this to go top of the page as what show in the prototype design ?
Prototype Design
I hope I understood what you want right.
You can simply create two columns by wrapping everything on the left in a div and wrapping what is on the right in another div and wrap both divs with another div with display flex
<div class="container">
<div>...here goes the content on the left...</div>
<div>...here goes the content on the right...</div>
</div>
.container{
display:flex;/*This is the new style*/
}
.StyleForm {
margin-top: 230px;
padding-left: 50px;
}
.StyleFormRest {
padding-left: 50px;
}
.StyleFormRestRight {
text-align: right;
padding-right: 500px;
margin-bottom: 5px;
align-items: right;
}
#EmailDisplay,
#AddressDisplay,
#DescriptionDisplay {
width: 875px;
}
.createMargin {
margin-bottom: 15px;
}
.Email,
.ContactName,
.ContactNo,
.Address,
.Description {
font-size: 18px;
}
#PriceModeDisplay {
text-align: right;
}
.StyleFormRestRight .form-control {
display: inline-block;
}
<div class="container"><!-- This is the container -->
<div><!-- This contains whats on the right -->
<div class="mb-3 StyleForm">
<label for="Email" class="form-label"><b class="Email">Email</b></label>
<input type="email" class="col-6 form-control" id="EmailDisplay" disabled readonly>
</div>
<form class="row g-3 StyleFormRest">
<div class="col-4">
<label for="Contact Name" class="visually-hidden"><b class="ContactName">Contact Name</b></label>
<input type="text" class="form-control" id="ContactNameDisplay" disabled readonly>
</div>
<div class="col-2 createMargin">
<label for="Contact No" class="visually-hidden"><b class="ContactNo">Contact No.</b></label>
<input type="text" class="form-control" id="ContactNoDisplay" disabled readonly>
</div>
</form>
<div class="mb-3 StyleFormRest">
<label for="Address" class="form-label"><b class="Address">Address</b></label>
<input type="text" class="col-6 form-control" id="AddressDisplay" disabled readonly>
</div>
<div class="mb-3 StyleFormRest">
<label for="Description" class="form-label"><b class="Description">Description</b></label>
<textarea class="form-control" id="DescriptionDisplay" rows="3" disabled readonly></textarea>
</div>
</div>
<div><!-- This contains whats on the left -->
<div class="mb-3 StyleFormRestRight">
<label for="PriceMode" class="form-label"><b class="PriceMode">Price Mode</b></label>
<input type="text" class="col-2 form-control pull-right" id="PriceModeDisplay" disabled readonly>
</div>
</div>
</div>

Label sticking next to another label

I am having a simple registration form, but one of the label fields sticks next to another label field.
Currently it looks like this:
Email should be under the Username, not next to it. Other form elements align nicely, but not these two.
label {
float: left;
}
input {
float: right;
}
<div class="form-wrapper">
<div>
<div>
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div>
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>
Why don't you just use flex, clean and less code.
.form-wrapper {
width: 400px;
border: 1px solid blue;
}
.username,
.useremail {
display: flex;
margin: 10px;
width: 350px;
justify-content: space-between;
font-weight: bold;
}
<div class="form-wrapper">
<div>
<div class="username">
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="useremail">
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>
If you are going with float you have to know about using clear property for it's next elements. So a best way to handle is, to create a after pseudo-element on the parent and clear:both.
In the below code have added 'field' class for each container and styled it with :after.
.field::after{
content: '';
display: block;
height: 0;
clear: both;
visibility: hidden;
}
label {
float: left;
}
input {
float: right;
}
<div class="form-wrapper">
<div>
<div class="field">
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="field">
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>
Labels and input fields are stacked from the left and the right, resp., due to the css float properties. Note that the label/input pairs render on individual lines when removing the css, though without proper vertical alignment.
The CSS display: table property and friends can be employed to rectify this. Basically they cause the renderer to apply table layouting to elements other than tableand descendants.
.d-t {
display: table;
}
.d-tr {
display: table-row;
}
.d-tr > label, .d-tr > input {
display: table-cell;
}
<div class="form-wrapper">
<div class="d-t">
<div class="d-tr">
<label for="user-name">Username:</label>
<input type="text" id="user-name" name="user-name" required>
</div>
<div class="d-tr">
<label for="user-email">Email:</label>
<input type="email" id="user-email" name="user-email" required>
</div>
</div>
</div>

Space between two row classes in HTML (Angular)

I have 3 rows with 2 columns in each row on my HTML page with some labels and inputs.
I see a lot of space between the rows which I tried removing but didn't work. Is there a way to do it?
Here's the HTML Code :
<div >
<h1>
New Patient Record
</h1>
</div>
<div class="row" style="padding-bottom: 0px;">
<div class="column"></div>
<div class="column">
<label > <strong>Date</strong> </label>
<input type="date" name="date" id="date" class="form-control" [(ngModel)]="institutes.date">
</div>
</div>
<div class="row" style="padding-top:0px" >
<div class="container" style="padding-left: 7.5%" >
<form #institutesForm="ngForm" (ngSubmit)="instituteLogins(institutesForm)">
<div class="form-group">
<div class="row">
<div class="column">
<h2><strong> Symptoms</strong> </h2>
<input type="text" name="symtoms" id="symtoms" class="form-control"[(ngModel)]="institutes.symtoms">
<br>
<h2><strong>Diagnosis</strong></h2>
<label> <strong>Condition</strong> </label>
<input type="text" name="condition" id="condition" class="form-control"[(ngModel)]="institutes.condition">
<label><strong> Advice </strong></label>
<input type="text" name="advice" id="advice" class="form-control"[(ngModel)]="institutes.advice">
<br>
</div>
<div class="column">
<h2> <strong>Prescription</strong> </h2>
<br>
<label><strong> Medication </strong></label>
<input type="text" name="medication" id="medication" class="form-control"[(ngModel)]="institutes.medication">
<label><strong> Medicine Type </strong></label>
<input type="text" name="type" id="type" class="form-control"[(ngModel)]="institutes.type">
<label><strong>Course</strong></label>
<input type="text" id="course" name="course" class="form-control"[(ngModel)]="institutes.course">
<label><strong> How many per day? </strong></label>
<input type="text" name="cday" id="cday" class="form-control"[(ngModel)]="institutes.cday">
<br>
</div>
<div class="row">
<div class="column"></div>
<div class="column">
<button id="record" class="btn btn-primary" type="submit" >Add Record</button>
</div>
</div>
</div>
<br><br>
</div>
</form>
</div>
Here's what all I tried: I tried to adjust row spacing using margins, and padding but none of them worked. Is there any other alternative for this?
.modal-dialog.cascading-modal.modal-avatar .modal-header img {
width: 130px;
margin-left: auto;
margin-right: auto;
}
.modal-dialog.cascading-modal.modal-avatar .modal-header {
margin: -6rem 2rem -1rem 2rem;
}
.More{
color: blue;
margin-right: 100px;
}
.column{
margin : 100px;
}
.row{
margin:0;
padding:0;
align-items: baseline;
}
Changing:
.column{
margin: 100px;
}
To
.column{
margin-left : 100px;
margin-right: 100px;
}
Will remove the space between the rows. Is that the end result you're looking for?
Adjusting the margin-left helped me solve the issue.
Also using to add number of empty spaces vertically solved my UI design issues.
For the space between both rows, you can add the padding-bottom
style="margin-top:-50px"

How to create a placeholder that starts from the top of the input box?

I am trying to create a message input box in a bootstrap form, however the box has to be of sufficient height so the user could read his message, the place holder of "message" would stay in the middle, also when I write the text it keeps going horizontally without considering margins, I am a newbie programmer so please don't be too harsh.
.theform {
margin-left: 200px;
margin-right: 200px;
margin-top: 50px;
border: 5px solid;
padding: 20px 20px 20px 20px;
}
.theform h1 {
font-size: 50px;
text-decoration: underline;
}
#formGroupExampleInput {
height: 50px;
}
.form-control {
font-size: 30px;
}
#messagebox {
height: 200px;
margin-right: 40px;
line-height: 0px;
}
#message {
height: 200px;
margin-right: 40px;
line-height: -20px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<div class="theform" id="link3">
<h1 class="text-center">Contact</h1>
<form>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input" size="50">
</div>
</div>
</fieldset>
<fieldset class="form-group">
<label for="formGroupExampleInput">Example label</label>
<div class="row">
<div class="col-md-6">
<input type="text" class="form-control" id="messagebox" placeholder="Message" size="50">
</div>
</div>
</fieldset>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
You have to use a textarea instead of an input. If you want to center the placeholder vertically, you also have to use some JS, just to adjust the textare.
Just look into this codepen for an example implementation of a vertical centered textarea:
https://codepen.io/desandro/pen/gICqd
NO JS REQUIRED
you can fix this issue by puting the text area :
<textarea name="" id="" cols="30" rows="10"></textarea>
by default in text area the placeholder is sent to the top left.
Don't make the mistake of puting input instead because when you will give it a huge height the placeholder will be sent to the middle left !!!