coding a tabular form in html - html

I'm trying to create a form that clients would complete via the web, so far I've resorted to using various tables butted up against each other to get the view I'm looking for, one of the issues is that when the tables are next to each other the borders appear twice as thick.
I think I could probably turn certain borders on and off but this would be a pain to manage, is there a better way I should be doing this?
My form looks something like this (jsfiddle at http://jsfiddle.net/5AXKa/)
<html>
<head>
<style type="text/css">
#form table
{
width:100%;
}
td
{
border: 1px solid black;
}
table
{
border:1px solid black;
}
#form
{
width:1000px;
/*border:1px solid black;*/
}
.field
{
border-right:none;
}
table, tr, td
{
border-collapse:collapse;
}
#Logo
{
width:30%;
}
#TestName
{
width:40%;
}
#TestNumber
{
width:30%;
}
#heading
{
height:70px;
}
.title
{
text-align:center;
}
.Data
{
border-left:none;
border-right:none;
}
</style>
</head>
<body>
<div id="form">
<table>
<tr id="heading">
<td id="Logo">LOGO GOES HERE</td>
<td id="TestName">TEST NAME</td>
<td id="TestNumber">TEST NUMBER</td>
</tr>
</table>
<table id="CommonData">
<tr>
<td class="field">CLIENT:-</td>
<td class="data"></td>
<td class="field">SITE:-</td>
<td class="data"></td>
<td class="field">Contract NO:-</td>
<td class="data"></td>
</tr>
<tr>
<td class="field">DUTY:-</td>
<td class="data"></td>
<td class="field">TAG No:-</td>
<td class="data"></td>
<td class="field">Loop No:-</td>
<td class="data"></td>
</tr>
<tr>
<td class="field">SYSTEM No:-</td>
<td class="data"></td>
<td class="field">SYSTEM REF:-</td>
<td class="data"></td>
<td class="field">DWG No:-</td>
<td class="data"></td>
</tr>
<tr>
<td class="field">CTP No:-</td>
<td class="data"></td>
<td colspan="4"></td>
</tr>
</table>
<table>
<tr class="title">
<td>INSTRUMENT / APPLIANCE</td>
</tr>
</table>
<table style="float:left;width:50%">
<tr>
<td colspan="2">INSTRUMENT DETAILS:</td>
</tr>
<tr>
<td>MANUFACTURER</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>SERIAL No:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>SIZE:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>SERVICE DATA SHEET REF:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>POWER SUPPLY:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>MODEL NO:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>IP RATING:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>RANGE/SPAN</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
</table>
<table style="float:right; width:50%">
<tr>
<td>INSTRUMENT TYPE</td>
<td>TICK BOX</td>
</tr>
<tr>
<td>PROXIMITY SWITCH</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>LIMIT SWITCH</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>FLOAT SWITCH</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>ULTRASONIC</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>THERMOCOUPLE</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>PRESSURE SWITCH</td>
<td><input type="text" name="blah" style="width:100%"/></td>f
</tr>
<tr>
<td>TEMPERATURE SWITCH</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>FLOW SWITCH</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>CONDUCITIVITY METER</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>TURBIDITY METER</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>CHEMICAL RESIDUAL ANALYSER</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>FLOW METER</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>PH METER</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
</table>
<table>
<tr class="title">
<td>MONITOR / CONVERTER</td>
</tr>
<table>
<table>
<tr>
<td>PLANT UNIT:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
<td>INSTRUMENT TYPE:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>SERIAL No:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
<td>SPAN:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<tr>
<td>POWER SUPPLY:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
<td>OTHER:-</td>
<td><input type="text" name="blah" style="width:100%"/></td>
</tr>
<table>
</body>
</html>

Simplify your table structure. If possible, use a single table, with one item on one row—there is normally no need to simulate printed forms (where you try to put everything on one sheet of paper) when designing a web form. Don’t use all uppercase, and put heading-like items in bold to clarify the structure of the form. Do not set widths for cells—it is part of the basic benefits of using tables that you can leave width allocation to browsers.
Your problems with borders are just one symptom of too complicated a design. When using a single table, adjacent browsers collapse when you just set cellspacing=0 in the table tag or border-collapse: collapse in CSS.

Instead of using a bunch of tables with a single div, you can use divs and specify the margin around the div.

This is a beginning.
Use a fieldset for each column.
Put every label and input in a div.
CSS:
fieldset {
float: left;
}
label {
clear: both; // Start the label at a new line
display: block;
float: left;
width: 100px;
{
input {
display: block;
float: left;
}
HTML:
<div><label for="field1">Field1</label><input type="text" name="field1" id="field1" /></div>
<div><label for="field1">Field2</label><input type="text" name="field2" id="field2" /></div>
etc...

Related

Large default width of text input prevents table to fit the smallest cell

I have a text input in a data cell, and a header cell of the same column. I expect the hierarchy of calculating width would be header >> column >> text-input, since there's no explicit width setting of text-input. But it turns out the text input has a default width which makes it wider than the header, and thus determines the width of the column.
This the link to the code
.style-table {
text-align: left;
}
input[type=text] {
width: 100%;
box-sizing: border-box;
}
<table class="style-table">
<tbody>
<tr style="background-color:#4CAF50;color:white;">
<th>gears</th>
<th>rate</th>
</tr>
<tr>
<td class="style-header-column">X1</td>
<td class="style-input-td">
<input id="X1-text" type="text" value="0" />
</td>
</tr>
<tr>
<td class="style-header-column">X10</td>
<td class="style-input-td">
<input id="X2-text" type="text" value="0" />
</td>
</tr>
<tr>
<td class="style-header-column">X100</td>
<td class="style-input-td">
<input id="X3-text" type="text" value="0" />
</td>
</tbody>
</table>
http://jsfiddle.net/ricecakebear/5686z44L/.
So how do I remove the default width of the text input, and let header determins the width of the column? Thanks.
input has a browser default of size = "20"
Add size = "1" to the input to reset this.
In addition, include your original css (width = 100%). This will allow the input to expand to match the th.
Also include box-sizing property to account for border (or reset this instead)
fiddle
table {
border-collapse: collapse;
}
.style-table {
text-align: left;
}
input[type="text"] {
width: 100%;
box-sizing: border-box;
}
<table class="style-table">
<tbody>
<tr style="background-color:#4CAF50;color:white;">
<th>gears</th>
<th>rate</th>
</tr>
<tr>
<td class="style-header-column">X1</td>
<td class="style-input-td">
<input id="X1-text" type="text" value="0" size="1" />
</td>
</tr>
<tr>
<td class="style-header-column">X10</td>
<td class="style-input-td">
<input id="X2-text" type="text" value="0" size="1" />
</td>
</tr>
<tr>
<td class="style-header-column">X100</td>
<td class="style-input-td">
<input id="X3-text" type="text" value="0" size="1" />
</td>
</tbody>
</table>
<br>
<table class="style-table">
<tbody>
<tr style="background-color:#4CAF50;color:white;">
<th>gears</th>
<th>A longer heading</th>
</tr>
<tr>
<td class="style-header-column">X1</td>
<td class="style-input-td">
<input id="X1-text" type="text" value="0" size="1" />
</td>
</tr>
<tr>
<td class="style-header-column">X10</td>
<td class="style-input-td">
<input id="X2-text" type="text" value="0" size="1" />
</td>
</tr>
<tr>
<td class="style-header-column">X100</td>
<td class="style-input-td">
<input id="X3-text" type="text" value="0" size="1" />
</td>
</tbody>
</table>
You can add width in th as you want
.style-table {
text-align: left;
}
input[type=text] {
width: 100%;
box-sizing: border-box;
}
<table class="style-table">
<tbody>
<tr style="background-color:#4CAF50;color:white;">
<th width="60%">gears</th>
<th width="40%">rate</th>
</tr>
<tr>
<td class="style-header-column">X1</td>
<td class="style-input-td">
<input id="X1-text" type="text" value="0" />
</td>
</tr>
<tr>
<td class="style-header-column">X10</td>
<td class="style-input-td">
<input id="X2-text" type="text" value="0" />
</td>
</tr>
<tr>
<td class="style-header-column">X100</td>
<td class="style-input-td">
<input id="X3-text" type="text" value="0" />
</td>
</tbody>
</table>
You are using width:100%; for your input, you are not limiting the width of your column td.
So the input will take the default width.
.style-table {
text-align: left;
}
.style-input-td{
width:50px;
}
input[type=text] {
width: 100%;
box-sizing: border-box;
}
<table class="style-table">
<tbody>
<tr style="background-color:#4CAF50;color:white;">
<th>gears</th>
<th>rate</th>
</tr>
<tr>
<td class="style-header-column">X1</td>
<td class="style-input-td">
<input id="X1-text" type="text" value="0" />
</td>
</tr>
<tr>
<td class="style-header-column">X10</td>
<td class="style-input-td">
<input id="X2-text" type="text" value="0" />
</td>
</tr>
<tr>
<td class="style-header-column">X100</td>
<td class="style-input-td">
<input id="X3-text" type="text" value="0" />
</td>
</tbody>
</table>

Border tr that include th and table section

I am writing my final project at PHP and JS. I need help with the html and CSS styling.
This is my sign form, I want help in 2 things.
I want to do that the whole row (tr) that include th while be with border, now I know to do it only that every th have border.
I want to divide the table to sections and to style every section in other CSS code.
How can I do it?
This my HTML code:
<body>
<form>
<table id="t">
<tr>
<th>Basic info</th>
<th>Contact info</th>
<th>About me</th>
</tr>
<tr>
<td><input placeholder="First name"></td>
<td><input placeholder="Phone"></td>
<td rowspan="3"><textarea rows="8" placeholder="About me"></textarea></td>
</tr>
<tr>
<td><input placeholder="Last name"></td>
<td><input placeholder="Area"></td>
</tr>
<tr>
<td><input placeholder="Degree"></td>
<td><input placeholder="Email"></td>
</tr>
<tr><th colspan="2">Social networks</th></tr>
<tr>
<td><input row placeholder="Facebook link"></td>
<td><input row placeholder="Website link"></td>
</tr>
<tr>
<td><input row placeholder="Twitter link"></td>
<td><input row placeholder="Medium link"></td>
</tr>
<tr>
<td><input row placeholder="Instagram link"></td>
<td><input row placeholder="Google link"></td>
</tr>
<tr><td colspan="2"><button type="submit">שלח</button></td></tr>
</table>
</form>
</body>
This is my CSS:
table{
margin: 16px;
text-align: center;
}
td{
padding: 10px;
justify-content: space-between;
}
#t textarea{
width: 100%;
height: 100%;
}
tr>th{
margin-top: 10px;
border: 1px solid red;
}
For (1), tr's can only have borders when the table is border-collapse:collapse.
For (2), you can put rows in <thead>, <tbody>, <tfoot> sections and style those separately.
Maybe you can have multiple <tbody> sections and use nth-of-type to select them but I don't know.
Differences in the below
addition of thead, tbody, tfoot in the html
style tbody as an example
border-collapse:collapse on the table style
tr style on the first tr
table {
margin: 16px;
text-align: center;
border-collapse: collapse;
}
td {
padding: 10px;
justify-content: space-between;
}
#t textarea {
width: 100%;
height: 100%;
}
tbody {
font-style: italic;
}
<form>
<table id="t">
<thead>
<tr style="border:solid 1px">
<th>Basic info</th>
<th>Contact info</th>
<th>About me</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input placeholder="First name">
</td>
<td>
<input placeholder="Phone">
</td>
<td rowspan="3">
<textarea rows="8" placeholder="About me"></textarea>
</td>
</tr>
<tr>
<td>
<input placeholder="Last name">
</td>
<td>
<input placeholder="Area">
</td>
</tr>
<tr>
<td>
<input placeholder="Degree">
</td>
<td>
<input placeholder="Email">
</td>
</tr>
<tr>
<th colspan="2">Social networks</th>
</tr>
<tr>
<td>
<input row placeholder="Facebook link">
</td>
<td>
<input row placeholder="Website link">
</td>
</tr>
<tr>
<td>
<input row placeholder="Twitter link">
</td>
<td>
<input row placeholder="Medium link">
</td>
</tr>
<tr>
<td>
<input row placeholder="Instagram link">
</td>
<td>
<input row placeholder="Google link">
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2">
<button type="submit">שלח</button>
</td>
</tr>
</tfoot>
</table>
</form>

CSS height effect on cross-browser?

Running on Chrome displays the expected result. Running same code on Mozilla-Firefox displays unexpected result. So, what will be the solution to get the Chrome result in Mozilla-Firefox?
textarea{
height : 100%;
position:absolute;
}
<table>
<tr>
<td><input type="text"></td>
<td rowspan=4><textarea></textarea></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td rowspan=4><textarea></textarea></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
</table>
Don't forget! Height of an element is relative to its parent.
You want to set the height to an element which has no information how high is height. You have to give the parent element a height. Look at this:
tr, td, textarea {
height: 100%;
}
<table>
<tr>
<td><input type="text"></td>
<td rowspan=4><textarea></textarea></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
</table>
You can set the textarea to position: absolute. Tested and works on Firefox Mac.
.textarea-td {
position: relative;
}
textarea{
height : 100%;
position: absolute;
top: 0;
box-sizing: border-box
/* so it really takes the same height as the inputs */
}
<table>
<tr>
<td><input type="text"></td>
<td rowspan=4 class="textarea-td"><textarea></textarea></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
</table>
You can Try This type of Manner styling in your table then its resolves easily ,So Please mention height and widths for your table and for its inner elements always .
textarea{ height : 100%; }
td{padding-right:10px;}
<table width="100%">
<tr height="25">
<td><input type="text" style="width:100%;"></td>
<td rowspan=4><textarea style="width:100%;"></textarea></td>
</tr>
<tr height="25">
<td><input type="text" style="width:100%;"></td>
</tr>
<tr height="25">
<td><input type="text" style="width:100%;"></td>
</tr>
<tr height="25">
<td><input type="text" style="width:100%;"></td>
</tr>
</table>
I know this is a hack, but you can use position absolute to the textarea, so it can set its height to 100%.
.textarea-wrapper {
position: relative;
}
textarea{
height : 100%;
/* firefox fix */
position: absolute;
top: 0;
left: 0;
bottom: 0;
}
<table>
<tr>
<td><input type="text"></td>
<td class="textarea-wrapper" rowspan=4><textarea></textarea></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
</tr>
</table>

html table border not showing on web

I am having trouble getting a border on a table. Here is the html for the table it shows having a border in Dreamweaver but not on the live webpage. I also have other tables on the page and do not want them to have the borders just this one.
<table style="width: 100%;" border="1" bordercolor="#000000">
<tr>
<td colspan="2" align="center" valign="middle">Please comeplete form</td>
</tr>
<tr>
<td width="50%">Event Name:</td>
<td>
<input type="text" name="name" id="name"></td>
</tr>
<tr>
<td>Date (YYYY-MM-DD):</td>
<td>
<textarea name="date" id="date"></textarea></td>
</tr>
<tr>
<td>Link to page:</td>
<td>
<input type="text" name="link" id="link"></td>
</tr>
<tr>
<td>Status:</td>
<td>
<input type="text" name="status" id="status"></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><input type="submit" name="submit" id="submit" value="Submit"></td>
</tr>
</table>
You can add CSS to bring it up to standard
Something like:
table.mytable{
border: 1px solid #000000;
}
and then add a class="mytable" attribute to your table
You can initially style it like:
table,td,th {
border-collapse:collapse;
border: 1px solid #000000;
}
And in this way further you can add this as a class.

How to customize html table border?

I am trying to create a table in which the border will appear like a login box.
<table border="1">
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td><input type="submit" value="Log In" /></td>
</tr>
</table>
What happens is that even the table cells have border and the border sucks. I want to remove cell border. The border should only be wrapping around the table. I am totally new to this.
Thanks in advance.
Use CSS
<style type="text/css">
.loginbox {
border-collapse: collapse;
border-width: 1px;
border-style: solid
}
</style>
<table class="loginbox">
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Log In" /></td>
</tr>
</table>
FYI: I added colspan="2" to your last <td> in order to make the border go all the way around.
If you use the following css,
table {
border: thin solid black;
}
that will give you a border around the table only, you can see a jsfiddle for it at http://jsfiddle.net/2CdwW/
Use CSS to put the border on the table instead:
<table style="border: 1px solid black">
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Log In" /></td>
</tr>
</table>