Position a list of text and text input fields - html

I am trying to achieve the following:
A list of text on the left and text input on the right.
This is my attempt, but it is neither working very well or is rather elegant:
.textbox {
width: 400px;
border: solid black 2px;
}
ul {
padding: 5px;
display: inline-block;
list-style-type: none;
}
<div class="textbox">
<h4>Info section</h4>
<ul>
<li>General</li>
<li>Board name</li>
<li>Board image</li>
<li>Short domains</li>
<li>Use short domains?</li>
<li>Get in touch</li>
<li>Add short domain</li>
<li>Delete board</li>
</ul>
<ul>
<li>
<input type="text">
</li>
<li>
<input type="text">
</li>
<li>
<input type="text">
</li>
<li>
<input type="text">
</li>
<li>
<input type="text">
</li>
<li>
<input type="text">
</li>
<li>
<input type="text">
</li>
</ul>
</div>
Can I do, what I want to achieve in another more elegant way?

Using Flexbox you can easily achieve what you want.There are many light weight frameworks which help for such use cases.One small example using such a framework,
Fiddle
<div>
<div class="row around-xs">
<div class="col-xs-6 start-xs">
General
</div>
<div class="col-xs-6">
<input type="text">
</div>
</div>
<div class="row around-xs">
<div class="col-xs-6 start-xs">
General
</div>
<div class="col-xs-6">
<input type="text">
</div>
</div>
<div class="row around-xs">
<div class="col-xs-6 start-xs">
General
</div>
<div class="col-xs-6">
<input type="text">
</div>
</div>
<div class="row around-xs">
<div class="col-xs-6 start-xs">
General
</div>
<div class="col-xs-6">
<input type="text">
</div>
</div>
<div class="row around-xs">
<div class="col-xs-6 start-xs">
General
</div>
<div class="col-xs-6">
<input type="text">
</div>
</div>
</div>
I recommend a framework because you can be more productive in short time.

This is how I would do it :
<div class="container">
<h3 class="container-heading">heading</h3>
<div class="form-item">
<p class="form-item-name">General</p>
<p class="form-item-field"><input type="text"></p>
</div>
</div>
css :
.form-item{width:100%;}
.form-item-name{width:50%; float:left;}
.form-item-field{width:50%; float:left;}

For UI like the one in your OP you can use table:
.textbox {
width: 400px;
border: solid black 2px;
}
.textbox h4 {
margin: 0;
}
table tr td:first-child {
width: 50%;
}
table tr td input {
width: 200px;
}
.textbox table {
padding: 10px;
}
<div class="textbox">
<h4>Info section</h4>
<table>
<tr>
<td>General</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>Board image</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>Board name</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>Board name</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>Add short domain</td>
<td>
<input type="text">
</td>
</tr>
</table>
</div>

Change HTML structure a bit and with Flexbox you can do this
.info {
width: 80%;
margin: 0 auto;
padding: 25px;
border: 1px solid black;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: flex;
margin: 5px;
}
input {
flex: 0 1 60%;
margin-left: auto;
}
<div class="info">
<h3>Info Section</h3>
<ul>
<li><label for="">Lorem ipsum dolor</label> <input type="text"> </li>
<li><label for="">Lorem ipsum dolor amet</label> <input type="text"> </li>
<li><label for="">Lorem </label> <input type="text"> </li>
<li><label for="">Lorem ipsum dolor</label> <input type="text"> </li>
<li><label for="">Lorem ipsum or</label> <input type="text"> </li>
<li><label for="">Lorem ipsum</label> <input type="text"> </li>
</ul>
</div>

First of all use semantic HTML: if you need improve a form on your site, use tags <form> <input> <label> etc.
<form>
<fieldset>
<h4>Info section</h4>
<div>
<label for="general">General</label>
<input id="general" type="text" placeholder="General">
</div>
<div>
<label for="name">Board name</label>
<input id="name" type="text" placeholder="Board name">
</div>
<div>
<label for="image">Board image</label>
<input id="image" type="image" placeholder="Board image">
</div>
<div>
<label for="domains">Short domains</label>
<input id="domains" type="text" placeholder="Short domains">
</div>
<div>
<label for="foo">Use short domains?</label>
<input id="foo" type="text" placeholder="Use short domains?">
</div>
<div>
<label for="touch">Get in touch</label>
<input id="touch" type="text" placeholder="Get in touch">
</div>
<div>
<label for="short_domain">Add short domain</label>
<input id="short_domain" type="text" placeholder="Add short domain">
</div>
<div>
<label for="bar">Delete board</label>
<input id="bar" type="text" placeholder="Delete board">
</div>
</fieldset>
</form>
jsfiddle-link
and I think in the last div instead label and input Delete board should be <button type="submit">Delete board</button> but I don't know clearly, maybe you need this input

Related

How to create multiple rows which contains two text boxes and labels above them in html/css?

I want to create three rows. In each row I want to have two textboxes with labels above them. Right now, I have this html code:
.firstRow, .secondRow, .thirdRow {
display: inline-block;
}
label, .textBox {
display: block;
}
<div class="firstRow">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
<div class="secondRow">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
<div class="thirdRow">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
The outcome is in this link:
https://jsfiddle.net/Lcav5xje/
What should I change?
Here is the snippet using simple display:flex;
also no need to add separate class for every row
.row {
display: flex;
}
.form-grp {
margin: 10px
}
.form-grp label {
display:block;
}
<div class="row">
<div class="form-grp">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
</div>
<div class="form-grp">
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
</div>
<div class="row">
<div class="form-grp">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
</div>
<div class="form-grp">
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
</div>
<div class="row">
<div class="form-grp">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
</div>
<div class="form-grp">
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
</div>
You can use grid to align the items.
example:
.row {
display: block;
}
.grid {
display: grid;
grid-template-rows: 1fr 1fr; /*Two columns*/
grid-auto-flow: column /*to align the input under the label*/;
justify-content: start; /*sticked to the left*/
grid-gap: 0 10px; /*horizontal space between inputs*/
}
<div class="row">
<div class="grid">
<label for="name1">Name1</label>
<input class="textBox" formControlName="name1" />
<label for="name2">Name2</label>
<input class="textBox" formControlName="name2" />
</div>
<div class="row">
<div class="grid">
<label for="name3">Name3</label>
<input class="textBox" formControlName="name3" />
<label for="name4">Name4</label>
<input class="textBox" formControlName="name4" />
</div>
</div>
<div class="row">
<div class="grid">
<label for="name5">Name5</label>
<input class="textBox" formControlName="name5" />
<label for="name6">Name6</label>
<input class="textBox" formControlName="name6" />
</div>
</div>
Try this code..
Demo
.firstRow,
.secondRow,
.thirdRow {
display: inherit;
}
.inner {
display: inline-block;
vertical-align: top;
}
<div class="firstRow">
<div class="inner">
<label for="name1">Name1</label>
<input class="textBox" formcontrolname="name1">
</div>
<div class="inner">
<label for="name2">Name2</label>
<input class="textBox" formcontrolname="name2">
</div>
</div>

Different buttons having the same function

I have this back and confirm button. The problem is that when I click the back button it confirms the form. Basically my back and confirm button are having the same function.
I tried putting the back button outside the and it worked well. The problem is it would look like this:
The thing is I want the back button to go first and then the confirm button next. Like this:
I can only do that when the back button is inside the form. As I've said I'm having problems when I do that.
Here's my html:
.form__confirmation,
.form__confirmation2 {
padding: 0px 0px;
display: inline-block;
}
button {
font-size: 12px;
text-transform: uppercase;
font-weight: 700;
letter-spacing: 1px;
background-color: #011f4b;
border: 1px solid #DADDE8;
color: #fff;
padding: 18px;
border-radius: 5px;
outline: none;
-webkit-transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
position: relative;
left: 330px;
margin-bottom: 20px;
}
button:hover {
background-color: #1293e1;
}
button:active {
background-color: #1083c8;
}
<div class="container">
<div class="card">
<div class="form__name" style="font-family: Questrial; ">
Leave Application Form
</div>
<div class="time__container">
<div class="section">
<div class="box">
1
</div><span>Date & Time</span>
</div>
<form action="form-to-email.php" class="form__time" method="post">
<div class="date">
<label for="date">From</label> <input id="date" type="date" name="datefrom" required>
</div>
<div class="date">
<label for="date">To</label> <input id="date" type="date" name="dateto" required>
</div>
<div class="timezone">
<label for="timezone"></label>
</select>
</div>
</div>
<div class="message__container">
<div class="section">
<div class="box">
2
</div><span>Message</span>
</div>
<textarea cols="50" rows="5" name="message" required></textarea>
</div>
<div class="contact__container">
<div class="section">
<div class="box">
3
</div><span>Contact Information</span>
</div>
<div class="form__contact">
<div class="cname">
<label for="cname">Name</label> <input name="name" type="text" required>
</div>
<div class="cnum">
<label for="cnum">Phone Number</label> <input id="cnum" type="text" name="phoneno" required>
</div>
<div class="email">
<label for="cemail">Email</label> <input id="cemail" name="email" required>
</div>
</div>
</div>
<div class="contact__container">
<div class="section">
<div class="box">
4
</div><span>Send to</span>
</div>
<div class="form__contact">
<div class="cname">
<label for="cname">Manager</label> <select name="emailTo" required>
<option value=""></option>
<option value="email#gmail.com">TestingRenzo</option>
<option value="email#gmail.com">TestingPaul</option>
</select>
</div>
</div>
</div>
<a href="home.php">
<div class="form__confirmation2">
<button>Back</button>
</div>
</a>
<div class="form__confirmation" type="submit" name="submit">
<button>Confirm Information</button>
</div>
</form>
</div>
</div>
Try changing this [horribly invalid] code:
<a href="home.php">
<div class="form__confirmation2">
<button>Back</button>
</div>
</a>
<div class="form__confirmation" type="submit" name="submit">
<button>Confirm Information</button>
</div>
To this [valid] version instead:
<div class="form__confirmation2">
<a class="button" href="home.php">Back</a>
</div>
<div class="form__confirmation">
<button type="submit" name="submit">Confirm Information</button>
</div>
And add the .button class to your CSS:
button,
.button {
...
}
button:hover,
.button:hover {
...
}
button:active,
.button:active {
...
}
Your HTML is somewhat wrong. Try to minimize the DIV tags if you can then you will understand the problem. Also in the submit button DIV tag you have mentioned a wrong bootstrap class if I am not wrong.
You can use float:right in order to change the positioning of your buttons. This will leave your DOM structure intact.
<div class="form__confirmation" type="submit" name="submit" style="float:right;" >
<button>Confirm Information</button>
</div>
</form>
<a href="home.php">
<div class="form__confirmation2" style="float:right;">
<button>Back</button>
</div>
</a>
This is the entire code Snippet.
<div class="container">
<div class="card">
<div class="form__name" style="font-family: Questrial; ">
Leave Application Form
</div>
<div class="time__container">
<div class="section">
<div class="box">
1
</div><span>Date & Time</span>
</div>
<form action="form-to-email.php" class="form__time" method="post">
<div class="date">
<label for="date">From</label> <input id="date" type="date" name="datefrom" required>
</div>
<div class="date">
<label for="date">To</label> <input id="date" type="date" name="dateto" required>
</div>
<div class="timezone">
<label for="timezone"></label>
</select>
</div>
</div>
<div class="message__container">
<div class="section">
<div class="box">
2
</div><span>Message</span>
</div>
<textarea cols="50" rows="5" name="message" required></textarea>
</div>
<div class="contact__container">
<div class="section">
<div class="box">
3
</div><span>Contact Information</span>
</div>
<div class="form__contact">
<div class="cname">
<label for="cname">Name</label> <input name="name" type="text" required>
</div>
<div class="cnum">
<label for="cnum">Phone Number</label> <input id="cnum" type="text" name="phoneno" required>
</div>
<div class="email">
<label for="cemail">Email</label> <input id="cemail" name="email" required>
</div>
</div>
</div>
<div class="contact__container">
<div class="section">
<div class="box">
4
</div><span>Send to</span>
</div>
<div class="form__contact">
<div class="cname">
<label for="cname">Manager</label> <select name="emailTo" required>
<option value=""></option>
<option value="email#gmail.com">TestingRenzo</option>
<option value="email#gmail.com">TestingPaul</option>
</select>
</div>
</div>
</div>
<!-- CHANGED BUTTON TAGS -->
<div class="form__confirmation" type="submit" name="submit" style="float:right;" >
<button>Confirm Information</button>
</div>
</form>
<a href="home.php">
<div class="form__confirmation2" style="float:right;">
<button>Back</button>
</div>
</a>
</div>

Putting a checkbox, label and input box next to each other

I am trying to put a checkbox, label and input box next to each other.
I separated it into divs and and put divs side-by-side.
I was able to get the buttons center but they are to close together which I am trying to fix too.
My question is how can I get <div class="col-centered border"> into a smaller border and put a checkbox, label and input box next to each other. In the end I want the buttons and all as a container.
html
<div class="col-centered border">
<form>
<div class="first">
<div class="form-group">
<input type="checkbox" class="form-check-input">
<label for="ssn">SSN:</label>
<input type="text" class="form-control-file" id="ssn" placeholder="Social Security Number">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="lastname">Lastname:</label>
<input type="text" class="form-control-file" id="lastname" placeholder="Password">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="role">Role:</label>
<input type="text" class="form-control-file" id="role" placeholder="Password">
</div>
</div>
<div class="second">
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="userId">User ID:</label>
<input type="text" class="form-control-file" id="userId" placeholder="User Id">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="office">Office</label>
<input type="text" class="form-control-file" id="office" placeholder="Office">
</div>
<input type="checkbox">Include Subordinates
</div>
<div class="center-block lower-button">
<div class="center-block">
<button type="submit" class="btn btn-default btn-md left-button">Search</button>
<button type="submit" class="btn btn-default btn-md right-button">Reset</button>
</div>
</div>
</form>
</div>
css
.first {
width: 100px;
float: left;
padding-left: 450px;
}
.second {
width: 200px;
float: right;
padding-right: 950px;
}
.col-centered{
padding-top: 30px;
float: none;
margin: 0 auto;
}
.btn-beside {
position: center;
left: 100%;
top: 0;
margin-left: -10px;
}
.lower-button{
padding-top:250px;
padding-left:575px;
}
.left-button{
padding-right: -14px;
}
.form-group{
text-align: center;
}
I am using bootstrap
Here's a Fiddle for you to take inspiration from.
HTML
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
</span>
<span class="input-group-addon">
<label for="tbox">My Label</label>
</span>
<input type="text" id="tbox" class="form-control">
</div>
</div>
</div>
</div>
As per the official documentation for Bootstrap.

How to align label and text box in line through html?

With the below code, the summary and it's text box are aligned inline.But the text box for description is appearing below the label 'description'. How can I make it align inline? Please help me in resolving this.
.left {
width: 30%;
float: left;
text-align: right;
}
.right {
width: 65%;
margin-left: 10px;
float: left;
}
<body>
<div class="container">
<div class="row">
<div class="col-sm-5 col-sm-push-3 col-xs-4 col-xs-push-2">
<h1 class="text-center" style="font-family:Colonna MT;font-size:50px;color:ForestGreen ;">Post Your Ad</h1>
<form action="post" class="login-form">
<div>
<label class="left">Summary:</label>
<input class="right" type="text" name="Summary" size="50">
</div>
<div>
<label class="left">Description:</label>
<input class="right" type="text" name="Description" style="height:100px;width:400px">
</div>
</form>
</div>
</div>
</div>
Try like this: Demo
If you need multi line text box, use textarea instead of input type text
<div class="form-group row">
<label for="inputEmail3" class="col-md-6 col-sm-12 form-control-label text-right">Summary</label>
<div class="col-md-6 col-sm-12">
<input type="text" class="form-control" name="Summary" size="50">
</div>
</div>
<div class="form-group row">
<label for="inputEmail3" class="col-md-6 col-sm-12 form-control-label text-right">Description</label>
<div class="col-md-6 col-sm-12">
<textarea class="form-control" name="Description"></textarea>
</div>
</div>
Edit:
As you mentioned, its not form-control class, its form-control-label.. You can get more info here
Updated Demo: To change the height, try chnaging the value of rows="8" for <textarea>
If you're using Bootstrap (as the classes on your code suggest). I would recommend using their form layout options. Sounds like you want a Horizontal Form:
Docs
For Example:
<form class="form-horizontal">
<div class="form-group">
<label for="summary" class="col-sm-2 control-label">Summary</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="summary" />
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="description" style="height:100px;width:400px" />
</div>
</div>
</form>
<input class="right" type="text" name="Description" style="height:100px;width:400px;">
Remove width from input of description, also please change to textarea, instead of input.
You have already used bootstrap framework.so that there is no need to write extra css for inline forms. follow the following code
<div class="form-group">
<label class="col-lg-3 control-label ">City</label>
<div class="col-lg-9">
<div class="form-inline">
<div class="form-group ">
<div class="col-lg-12">
<label class="sr-only" for="city">City</label>
<input type="text" id="city" name="city" class="form-control " placeholder="E.g. Thrissur" >
</div>
</div>
<div class="form-group ">
<div class="col-lg-12">
<label class="sr-only" for="county">County</label>
<input type="text" id="county" name="county" class="form-control " placeholder="E.g. India" >
</div>
</div>
</div>
</div>
</div>
Like this?
https://jsfiddle.net/d6tscd18/
.left {
width: 30%;
display: inline-block;
text-align: right;
}
.right {
width: 65%;
margin-left: 10px;
display: inline-block;
}
try this:
<html>
<head>
<title>sample</title>
<style type="text/css">
.left {
width: 30%;
display: inline-block;
text-align: right
}
.right {
margin-left: 10px;
display: inline-block;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-5 col-sm-push-3 col-xs-4 col-xs-push-2">
<h1 class="text-center" style="font-family:Colonna MT;font- size:50px;color:ForestGreen ; text-align: center">Post Your Ad</h1>
<form action="post" class="login-form">
<div>
<label class="left">Summary:</label>
<input class="right" type="text" name="Summary" size="50" style="width:400px">
</div>
<div>
<label class="left">Description:</label>
<input class="right" type="text" name="Description" style="height:100px;width:400px">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
If you have trouble getting it in place you can also force a table layout without using tables:
.login-form {
display: table;
}
.login-form>div {
display: table-row;
}
.cell {
display:table-cell;
vertical-align: top;
}
...
Adding a div around the inputs and a "cell" class (and shouldn't it be a textarea?):
...
<form action="post" class="login-form">
<div>
<label class="left cell">Summary:</label>
<div class="cell">
<input class="right" type="text" name="Summary" size="50">
</div>
</div>
<div>
<label class="left cell">Description:</label>
<div class="cell">
<textarea class="right" name="Description" style="height:100px;width:400px"></textarea>
</div>
</div>
</form>
...
Check it here
Remove the style attribute from the description input type, it will then appear as the summary input box.
<form action="post" class="login-form">
<div>
<label class="left">Summary:</label>
<input class="right" type="text" name="Summary" size="50" style="width:400px">
</div>
<div>
<label class="left">Description:</label>
<input class="right" type="text" name="Description">

Space text boxes after their label

With style sheets I float name, email left and nickname and school right but I would like their text boxes to start at the same point. How can I achieve this with CSS?
<div id="container" align="center">
<div id="name">Name:
<input id="name_text" type="text">
</div>
<div id="nickname">Nickname:
<input id="nickname_text" type="text">
</div>
<div id="email">Email Address:
<input id="email_text" type="text">
</div>
<div id="school">School:
<input id="school_text" type="text">
</div>
</div>
You have to use this way:
There should be <label> to make sure when the user clicks on the label text, it focuses on the respective input.
The <strong> tag has a display: inline-block making it easy to set the width.
You don't need so many ids.
You need to give name attribute to all the <input /> fields.
label strong {display: inline-block; width: 150px; text-align: left; margin: 0 0 10px;}
<div id="container" align="center">
<div id="name">
<label>
<strong>Name:</strong>
<input id="name_text" type="text" />
</label>
</div>
<div id="nickname">
<label>
<strong>Nickname:</strong>
<input id="nickname_text" type="text" />
</label>
</div>
<div id="email">
<label>
<strong>Email Address:</strong>
<input id="email_text" type="text" />
</label>
</div>
<div id="school">
<label>
<strong>School:</strong>
<input id="school_text" type="text" />
</label>
</div>
</div>
li {
list-style-type: none;
}
li p {
display: inline-block;
width: 120px;
text-align: left;
font-family: "Times New Roman";
font-style: oblique;
font-size: 14px;
}
<div id="container" align="center">
<ul>
<li>
<p>Name:</p>
<input type="text">
</li>
<li>
<p>Nickname:</p>
<input type="text">
</li>
<li>
<p>Email Address:</p>
<input type="text">
</li>
<li>
<p>School:</p>
<input type="text">
</li>
</ul>
</div>
Codepen
A little modification,copy this code and check it.
<html>
<head>
<style>
label strong {display: inline-block; width: 150px; text-align: left; margin: 0 0 10px;}
</style>
</head>
<body>
<center>
<div id="Holder" style="width:50%;">
<div id="L_div" style="float:left;">
<div id="container" align="center">
<div id="name">
<label>
<strong>Name:</strong>
<input id="name_text" type="text" />
</label>
</div>
<div id="email">
<label>
<strong>Email Address:</strong>
<input id="email_text" type="text" />
</label>
</div>
</div>
</div>
<div id="R_div" style="float:right;">
<div id="nickname">
<label>
<strong>Nickname:</strong>
<input id="nickname_text" type="text" />
</label>
</div>
<div id="school">
<label>
<strong>School:</strong>
<input id="school_text" type="text" />
</label>
</div>
</div>
</div>
</div>
</center>
</body>
</html>
If you are a fresher in css use this site W3school for guidence
Regds