I'm working on a php application, attempting to dynamically select from a MySQL database and populate a page with configurable cells based on table rows that users can use to manage their configuration. I'm trying to make every cell look roughly like this:
However, I'm not quite sure how to get there. My first thought was to use a separate div for each element of the cell:
.stockcellcontainertext {
position: absolute;
vertical-align: middle;
text-align: center;
left: 0;
width: 15%;
height: 100%;
margin: auto;
}
.stockcellcontainercheckbox {
display: inline-block;
position: absolute;
vertical-align: middle;
right: 0;
width: 75%;
height: 100%;
margin: auto;
}
And then I tried a more basic approach with <table>
<form action="update_client.php" method="get">
<table style="width: 100%;">
<tr>
Symbol: <br>
<input type="text" name="symbol000" value="GOOG">
</tr>
<tr>
<input type="checkbox" name="input0" value="Hull's Moving Average" checked>
<label for="input0">input0</label>
<input type="checkbox" name="input1" value="Moving Average 200-Days" checked>
<label for="input1">input1</label>
<input type="checkbox" name="input2" value="Moving Average 50-Days" checked>
<label for="input2">input3</label>
</tr>
</table>
</form>
But both of them seem to push the checkboxes down a rank, I can't seem to get them in side-by-side.
Output
Approach with table
<table> with rows in each <td>
Example
<form action="">
<table>
<tr>
<td>
<label for="">Label</label><br>
<input type="text">
</td>
<td>
<div><input type="checkbox"><label for="">Input 1</label></div>
<div><input type="checkbox"><label for="">Input 2</label></div>
<div><input type="checkbox"><label for="">Input 3</label></div>
</td>
<td>
<div><input type="checkbox"><label for="">Input 4</label></div>
<div><input type="checkbox"><label for="">Input 5</label></div>
<div><input type="checkbox"><label for="">Input 6</label></div>
</td>
<td>
<div><input type="checkbox"><label for="">Input 7</label></div>
<div><input type="checkbox"><label for="">Input 8</label></div>
<div><input type="checkbox"><label for="">Input 9</label></div>
</td>
<td>
<input type="submit">
</td>
</tr>
</table>
</form>
Approach with flexbox
The row is display: flex and the columns have flex: 1. The checkboxes are wrapped in <li> (could also be <div>).
Example
.my-form {
border: 5px solid blue;
width: 700px;
}
.my-form>.row {
display: flex;
align-items: center;
}
.my-form .col {
flex: 1;
padding: 15px;
}
.my-form label {
display: inline-block;
margin-bottom: 10px;
}
.my-form input {
padding: 10px;
border: 2px solid #000;
}
.my-form input[type="submit"] {
width: 100%;
border-radius: 20px;
}
.my-form input+label {
margin-left: 10px;
}
.my-form ul {
list-style: none;
padding: 0;
}
<form class="my-form" action="">
<div class="row">
<div class="col">
<label>Text Value:</label><br>
<input type="text" placeholder="Textinput1">
</div>
<div class="col">
<ul>
<li><input type="checkbox"><label for="">input1</label></li>
<li><input type="checkbox"><label for="">input2</label></li>
<li><input type="checkbox"><label for="">input3</label></li>
</ul>
</div>
<div class="col">
<ul>
<li><input type="checkbox"><label for="">input4</label></li>
<li><input type="checkbox"><label for="">input5</label></li>
<li><input type="checkbox"><label for="">input6</label></li>
</ul>
</div>
<div class="col">
<ul>
<li><input type="checkbox"><label for="">input7</label></li>
<li><input type="checkbox"><label for="">input8</label></li>
<li><input type="checkbox"><label for="">input9</label></li>
</ul>
</div>
<div class="col">
<input type="submit">
</div>
</div>
</form>
Hints
how-can-i-add-padding-to-input-type-button
how-to-style-input-and-submit-button-with-css
css-webkit-appearance-none-is-causing-checkbox-to-not-be-checked
Related
how can I align the labels & inputs to the right
like that all of then appear in the same line
.radioContainer{
width: fit-content;
margin: 5px;
margin-top: 20px;
background-color: aqua;
padding-bottom: 25px;
}
<div class="radioContainer" style="margin-bottom: 40px; margin-right: 0px; ">
<label class="title" for="">fav food</label>
<label for="burger">burger</label>
<input type="checkbox" id="burger">
<br>
<label for="fries">fries</label>
<input type="checkbox" id="fries">
<br>
<label for="onionRings">onion rings</label>
<input type="checkbox" id="onionRings">
<br>
<label for="cackes">cakes</label>
<input type="checkbox" id="cackes" >
<small></small>
</div>
To have them in the same line, I would start by removing <br /> from your code. Then set the css for input and label to be inline-block, something like:
.radioContainer{
width: fit-content;
margin: 5px;
margin-top: 20px;
background-color: aqua;
padding-bottom: 25px;
}
label, input { display: inline-block; }
<div class="radioContainer" style="margin-bottom: 40px; margin-right: 0px; ">
<label class="title" for="">fav food</label>
<label for="burger">burger</label>
<input type="checkbox" id="burger">
<label for="fries">fries</label>
<input type="checkbox" id="fries">
<label for="onionRings">onion rings</label>
<input type="checkbox" id="onionRings">
<label for="cackes">cakes</label>
<input type="checkbox" id="cackes" >
<small></small>
</div>
To make all inputs inline, just remove all the <br /> tags.
Example:
<div class="radioContainer" style="margin-bottom: 40px; margin-right: 0px; ">
<label class="title" for="">fav food</label>
<label for="burger">burger</label>
<input type="checkbox" id="burger">
<label for="fries">fries</label>
<input type="checkbox" id="fries">
<label for="onionRings">onion rings</label>
<input type="checkbox" id="onionRings">
<label for="cackes">cakes</label>
<input type="checkbox" id="cackes">
<small></small>
</div>
Codepen: https://codepen.io/manaskhandelwal1/pen/jOMeqex
I understood your Question that you want them still below each other but aligned to the right side. So i made a solution using flexbox instead of the hard breaks. I commented the Code where i made changes and why, html and css.
Basically i used a colum and put each item-combination (label and checkbox)in a new row-div.
.radioContainer{
width: fit-content;
margin: 5px;
margin-top: 20px;
background-color: aqua;
padding-bottom: 25px;
/*make item a flexbox-container*/
display: flex;
/*combination of flex-direction and flex-wrap*/
flex-flow: column wrap;
}
.row{
/*make item a flexboc container*/
display: flex;
/*flex-flow: row nowrap; this is the default value of flex, which is why you dont need it,
just wanted to leave it in as a comment so you know whats happening*/
/*Align the contents on the end of each row*/
justify-content: flex-end;
}
<div class="radioContainer" style="margin-bottom: 40px; margin-right: 0px; ">
<!--removed the hard breaks and added row-divs around each item combination-->
<div class="row">
<label class="title" for="">fav food</label>
</div>
<div class="row">
<label for="burger">burger</label>
<input type="checkbox" id="burger">
</div>
<div class="row">
<label for="fries">fries</label>
<input type="checkbox" id="fries">
</div>
<div class="row">
<label for="onionRings">onion rings</label>
<input type="checkbox" id="onionRings">
</div>
<div class="row">
<label for="cackes">cakes</label>
<input type="checkbox" id="cackes" >
</div>
<small></small>
</div>
How can I align a radiobuttonlist horizontally? This one is to capture a gender value , male/female. I want to keep the name input css the same. This is the html:
<label for="temp">Gender</label>
<label for="one">Male</label>
<input type="radio" id="one" name="first_item" value="1" />
<label for="two">Female</label>
<input type="radio" id="one" name="first_item" value="2" />
The css:
.grid-container {
display: grid;
grid-column-gap: 5px;
grid-template-columns: auto auto;
background-color: #2196f3;
padding: 10px;
}
.left-griditem {
}
input,
label {
display: block;
}
Here is a codepen. Currently the buttons are in a vertical position.
If you want only the radio buttons, add this style:
#genderArea input, #genderArea label{
display: inline;
}
and use this HTML:
<div class="grid-container">
<div class="left-griditem">
<label for="name">Name</label>
<input id="name" type="text" name="name">
<label for="temp">Gender</label>
<span id="genderArea">
<label for="one">Male</label>
<input type="radio" id="one" name="first_item" value="1" />
<br>
<label for="two">Female</label>
<input type="radio" id="one" name="first_item" value="2" />
</span>
</div>
<div class="right-griditem">2</div>
</div>
You have to wrap particular row which you want to make under a div/ a tag.
.grid-container {
display: grid;
grid-column-gap: 5px;
grid-template-columns: auto auto;
background-color: #2196f3;
padding: 10px;
}
.left-griditem {}
input,
label {
display: inline-block;
}
div.item>label:first-child {
width: 70px;
font-weight: bold;
}
div.item:first-child>input,
div.item:first-child>label {
display: block
}
body {
background: hsl(221, 64%, 24%);
color: hsl(235, 9%, 39%);
font-family: "Open Sans", sans-serif;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
margin: 2rem 1rem 1rem 1rem;
}
div {
background: #fff;
padding: 1vw 2vw;
}
<div class="grid-container">
<div class="left-griditem">
<div class="item">
<label for="name">Name</label>
<input id="name" type="text" name="name">
</div>
<div class="item">
<label for="temp">Gender</label>
<label for="one">Male</label>
<input type="radio" id="one" name="first_item" value="1" />
<label for="two">Female</label>
<input type="radio" id="two" name="first_item" value="2" />
</div>
</div>
<div class="right-griditem">2</div>
</div>
Try this simple code using table, tr and td tags
<table>
<tr>
<td>
<label for="one">Male</label>
</td>
<td>
<input type="radio" id="one" name="first_item" value="1" />
</td>
<td style="widht:20px;"></td>
<td>
<label for="two">Female</label>
</td>
<td>
<input type="radio" id="one" name="first_item" value="2" />
</td>
</tr>
</table>
This approach gives you the flexibility to put controls, the way you want
Change this:
input,
label {
display: block;
}
To this:
input,
label {
display: inline;
}
I have a large number of inputs I need to display. I am trying to condense them into like groups. The first group I am have is going to have 6 inputs in 3 columns but the third input box is big, so I want the next rows input to line up with the bottom of the larger text box. Form Layout
I have tried to float them, list them, use a table, but all without successs
I have looked at a lot of CSS code snippets and cannot figure out how to get this layout. Any help would be greatly appreciated.
Edit: I found a way to make it work, but would like a more elegant solution. HTML:
.row1 {
float: left;
background-color: #ffffff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
font-family: Raleway, sans-serif;
text-align: center;
text-decoration: none;
padding: 5px;
}
.row2{
float: left;
background-color: #ffffff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
font-family: Raleway, sans-serif;
text-align: center;
text-decoration: none;
padding: 5px;
}
.row3{
float: left;
display: inline-block;
clear: left;
position: relative;
margin-top: -80px;
}
<div class="row1">
<label>
<span>Full Project Number</span><br>
<input type="text" name="project" id="project">
</label>
</div>
<div class="row1">
<label>
<span>Client</span><br>
<input type="text" name="client" id="client">
</label>
</div>
</div>
<div class="row2 fasttimesatseedmonthigh">
<label id="descrp">
<span>Project Description</span><br>
<textarea name="name" type="text" cols="50" rows="10"></textarea>
</label>
</div>
<div class="row3">
<div class="row1">
<label for="drawing">
<span>Drawing Number</span><br>
<input type="text" name="drawing" id="drawing">
</label>
</div>
<div class="row1">
<label>
<span>Assigned By:</span><br>
<input type="text" name="assigned" id="assigned" style="width: 75px;">
</label>
</div>
<div class="row1">
<label class="form-row">
<span>Date</span><br>
<?php
$stamp=date("Y/m/d");?>
<input type="text" name="date" id="date" value="<?php echo(htmlspecialchars($stamp))?>"/>
</label>
</div>
</div>
It works but like I said not as nice as I would like it.
How about a good ol' table with row&colspan?
.grid{
border: solid 1px black;
table-layout: fixed;
font-family: Raleway, sans-serif;
border-spacing: 10px;
}
.grid td{
text-align: center;
vertical-align: top;
font-size: 9pt;
}
.grid td.wide{
width: 200px;
}
.grid td.normal{
width: 100px;
}
.grid td input{
width: 100%;
}
<table class="grid">
<tr>
<td colspan="2" class="wide">
<label>
<span>Full Project Number</span><br>
<input type="text" name="project" id="project">
</label>
</td>
<td colspan="2" class="wide">
<label>
<span>Client</span><br>
<input type="text" name="client" id="client">
</label>
</td>
<td colspan="2" rowspan="2">
<label id="descrp">
<span>Project Description</span><br>
<textarea name="name" type="text" cols="20" rows="8"></textarea>
</label>
</td>
</tr>
<tr>
<td colspan="1" class="normal">
<label for="drawing">
<span>Drawing Number</span><br>
<input type="text" name="drawing" id="drawing">
</label>
</td>
<td colspan="1" class="normal">
<label>
<span>Assigned By</span><br>
<input type="text" name="assigned" id="assigned">
</label>
</td>
<td colspan="2" class="wide">
<label class="form-row">
<span>Date</span><br>
<input type="text" name="date" id="date">
</label>
</td>
</tr>
</table>
Plis no hate.
I am having some difficulty with the compatibility of my CSS for the HTML check boxes. For some versions of IE as well as when I place the live html into my PowerPoint, the center div will overlap with the left and the entire page is shifted left. I am not quite sure why this occurs.
html,
body {
height: 90%;
width: 90%;
padding: 5px;
margin: auto;
}
#googleMap {
height: 90%;
width: 90%;
padding: 5px;
margin: auto;
}
.Title {
font-size: 1.5em;
font-weight: bold;
text-align: center;
}
#left_check {
position: absolute;
left: 10%;
}
#padded-left {
position: absolute;
padding-left: 1.4em;
}
#right_check {
float: right;
}
#mid_check {
text-align: center;
margin-left: auto;
margin-right: auto;
}
#left_align {
display: inline-block;
text-align: left;
}
<ul style="list-style-type:none">
<div id="left_check">
<li>
<form>
<input id="united_states1" type="checkbox" name="location" value="united_states">United States (domestic)
<br>
<div id="padded-left">
<input id="west1" type="checkbox" class="location" value="west_coast">West
<br>
<input id="east1" type="checkbox" class="location" value="central_us">East
<br>
<input id="cent1" type="checkbox" class="location" value="east_coast">Central
</div>
</form>
</li>
</div>
<div id="right_check">
<li>
<form>
<input id="euro1" type="checkbox" class="location" value="europe">Europe
<br>
<input id="africa1" type="checkbox" class="location" value="africa">Africa
<br>
<input id="asia1" type="checkbox" class="location" value="asia">Asia
<br>
<input id="aust1" type="checkbox" class="location" value="australia">Australia
</form>
</li>
</div>
<div id="mid_check">
<div id="left_align">
<li>
<form>
<input id="canada1" type="checkbox" class="location" value="canada">Canada
<br>
<input id="centr_am1" type="checkbox" class="location" value="central_america">Central America
<br>
<input id="south_am1" type="checkbox" class="location" value="south_america">South America
<br>
<input id="ocean1" type="checkbox" class="location" value="oceanic">Oceanic
</form>
</li>
</div>
</div>
</ul>
Original CSS (Problems with some pc IE)
With Flex
IE Problems (new)
This is how you can do it, if I got your question right.
ul {
display: flex;
padding: 0px !important;
}
ul > div {
/* width: 30%; */
flex-grow: 1;
}
ul > div#right_check {
order: 3;
}
ul > div#mid_check {
order: 2;
}
ul > div#left_check {
order: 1;
}
div#mid_check li {
text-align: center;
}
div#right_check li form,
div#mid_check li form {
text-align: left;
}
div#right_check li {
text-align: right;
}
form {
height: 39px;
width: auto;
display: inline-block;
}
#map-canvas {
height: 500px;
width: 100%;
background: #AFAFAF;
}
div.frame {
width: 80%;
margin: auto;
}
<div class='frame'>
<div id="map-canvas"></div>
<ul style="list-style-type:none">
<div id="left_check">
<li>
<form>
<input id="united_states1" type="checkbox" name="location" value="united_states">United States (domestic)
<br>
<div id="padded-left">
<input id="west1" type="checkbox" class="location" value="west_coast">West
<br>
<input id="east1" type="checkbox" class="location" value="central_us">East
<br>
<input id="cent1" type="checkbox" class="location" value="east_coast">Central
</div>
</form>
</li>
</div>
<div id="right_check">
<li>
<form>
<input id="euro1" type="checkbox" class="location" value="europe">Europe
<br>
<input id="africa1" type="checkbox" class="location" value="africa">Africa
<br>
<input id="asia1" type="checkbox" class="location" value="asia">Asia
<br>
<input id="aust1" type="checkbox" class="location" value="australia">Australia
</form>
</li>
</div>
<div id="mid_check">
<div id="left_align">
<li>
<form>
<input id="canada1" type="checkbox" class="location" value="canada">Canada
<br>
<input id="centr_am1" type="checkbox" class="location" value="central_america">Central America
<br>
<input id="south_am1" type="checkbox" class="location" value="south_america">South America
<br>
<input id="ocean1" type="checkbox" class="location" value="oceanic">Oceanic
</form>
</li>
</div>
</div>
</ul>
</div>
Is this what you trying to get?
I just started coding a small page for myself after not doing any web design for a couple of years. As I now learned, laying out the page with tables is not state-of-the-art anymore (not sure if it ever really was).
Now I am trying to layout my page with CSS but couldn't find anything on:
How to align 7 checkboxes horizontally and put the corresponding label centered below the checkboxes?
How to align 2 selects horizontally and put the corresponding label centered above the selects?
The initial pure table-code was the following:
.form fieldset {
display: table;
border: 1px solid #c6c7cc;
border-radius: 5px;
}
.form label {
display: table-cell;
text-align: right;
padding: 5px;
}
.form input,
.form select {
display: table-cell;
}
.form .cssRow {
display: table-row;
}
.form .submit {
display: table-cell;
caption-side: bottom;
display: table-caption;
text-align: center;
}
<table>
<tr>
<td align="right">Name</td>
<td align="left">
<input name="name" type="text">
</td>
</tr>
<tr>
<td align="right">Day(s) of week</td>
<td align="center">
<table>
<tr>
<td align="center">
<input type="checkbox" name="day[]" value="mo" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="tu" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="we" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="th" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="fr" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="sa" checked>
</td>
<td align="center">
<input type="checkbox" name="day[]" value="su" checked>
</td>
</tr>
<tr>
<td align="center">Mo</td>
<td align="center">Tu</td>
<td align="center">We</td>
<td align="center">Th</td>
<td align="center">Fr</td>
<td align="center">Sa</td>
<td align="center">Su</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">Validity</td>
<td align="center">
<table>
<tr>
<td>Valid from</td>
<td>Valid to</td>
</tr>
<tr>
<td>
<select>
<option>January</option>
<option>February</option>
</select>
</td>
<td>
<select>
<option>January</option>
<option>February</option>
</select>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="submit" value="Refresh">
</td>
</tr>
</table>
My CSS attempt so far looks like this:
<div class="form">
<fieldset>
<legend>Search</legend>
<div class="cssRow">
<label for="name">Name</label>
<input name="name" type="text" size="30" maxlength="30">
</div>
<div class="cssRow">
<label for="day[]">Day(s) of week</label>
<input name="day[]" type="text" value="ToDo" size="30" disabled>
</div>
<div class="cssRow">
<label>Validity</label>
<input type="text" value="ToDo" size="30" disabled>
</div>
<div class="submit">
<input type="submit" name="submit" value="Suchen">
</div>
</fieldset>
</div>
To illustrate my problem, I created the following JSFiddle: http://jsfiddle.net/c9a7ezyk/
Any suggestions are welcome, although I prefer a simple solution, as I am just (re)learning HTML and CSS.
I prefer a slightly different approach to the other answer, where the <input> element is nested inside of a <label>, this implicitly associates the label with the input to give all kinds of nice bonuses.
It also makes for a simpler to follow markup, with less nested containers.
Example
<label>
<input type="checkbox">
<span class="label">Sunday</span>
</label>
And then
label {
display: inline-block;
text-align: center;
}
span.label {
display: block;
}
Notice how clicking the labels check the associated checkbox properly. Selects behave exactly the same way. Because <input> and <select> are inlines by default, it means that they'll be affected by text-align: center.
Checkbox with label:
<div class="checkbox-label">
<label for="checkbox">Sunday</label>
<div class="checkbox-container">
<input name="checkbox" type="checkbox">
</div>
</div>
.checkbox-label {
display: inline-block
}
.checkbox-container {
text-align: center;
}
Notice that the checkbox is inline so you can put it in a container and use text-align: center
Also notice that I use display: inline-block on .checkbox-label so that they can be aligned horizontally (block elements, default for div, takes up a whole line and drops the following element beneath it)
I use the same principals for the selects
You can see the whole thing here:
http://codepen.io/Vall3y/pen/QwdWOe
Semantic Purity
I am a bit of an HTML purist, so here is an HTML form without any extra markup:
The legends are floated to the left and vertically centered using a line-height that matches the legends height
The inputs are wrapped in a label with display: inline-block which is given a width to force the text below / above the input
The fieldset:before properties allow us to vertically center the labels with vertical-align: middle
Full Example
The background colours are just to illustrate the layout.
* {
margin: 0;
padding: 0;
}
fieldset {
border: none;
height: 70px;
}
fieldset:before {
content: '';
display: inline-block;
vertical-align: middle;
height: 100%;
background: #F90;
width: 0;
}
legend {
height: 100%;
line-height: 70px;
width: 150px;
text-align: center;
background: #F90;
float: left;
}
input[type=checkbox] {
margin: 0 5px;
}
.days label {
background: #F90;
width: 30px;
display: inline-block;
vertical-align: middle;
text-align: center;
}
.validity label {
background: #F90;
width: 100px;
display: inline-block;
vertical-align: middle;
text-align: center;
}
<form>
<fieldset class="days">
<legend>Day(s) of Week</legend>
<label for="monday">
<input type="checkbox" id="monday" />Mo
</label>
<label for="tuesday">
<input type="checkbox" id="tuesday" />Tu
</label>
<label for="wednesday">
<input type="checkbox" id="wednesday" />We
</label>
<label for="thursday">
<input type="checkbox" id="thursday" />Th
</label>
<label for="friday">
<input type="checkbox" id="friday" />Fr
</label>
<label for="saturday">
<input type="checkbox" id="saturday" />Sa
</label>
<label for="sunday">
<input type="checkbox" id="sunday" />Su
</label>
</fieldset>
<fieldset class="validity">
<legend>Validity</legend>
<label for="from">Valid From
<select id="from">
<option>Option</option>
</select>
</label>
<label for="to">Valid to
<select id="to">
<option>Option</option>
</select>
</label>
</fieldset>
</form>
Demo here
Here is the code:
<html>
<body>
<div>Name <input type="text"></input></div><br>
<div>Day(s) of week</div>
<div style="margin-left: 120px;margin-top: -25px;">
<div><input type="checkbox" checked><br>Mo</input></div>
<div style="
width: 10px;
margin-left: 30px;
margin-top: -37px;">
<input type="checkbox" checked><br>Tu</input></div>
<div style="
width: 10px;
margin-left: 60px;
margin-top: -37px;">
<input type="checkbox" checked><br>We</input></div>
<div style="
width: 10px;
margin-left: 90px;
margin-top: -37px;">
<input type="checkbox" checked><br>Th</input></div>
<div style="
width: 10px;
margin-left: 120px;
margin-top: -37px;">
<input type="checkbox" checked><br>Fr</input></div>
<div style="
width: 10px;
margin-left: 150px;
margin-top: -37px;">
<input type="checkbox" checked><br>Sa</input></div>
<div style="
width: 10px;
margin-left: 180px;
margin-top: -37px;"><input type="checkbox" checked><br>Su</input>
</div>
</div>
<br>
<div>Validity
<select>
<option>January</option>
<option>February</option>
</select>
<select>
<option>January</option>
<option>February</option>
</select>
</div>
</body>
</html>