I understand css and have an external file, but I don't know how to move everything from this poll to the css file. The poll is under the div id "poll" so anything I change in css will affect the entire poll instead of specific parts. Can I split the question of the poll and the answers into separate divs or is there a better way to re-write the code?
I know that the poll still works but I like to be organized and the validator is showing many errors because of this.
<div id="poll">
<form method="post" action="http://poll.pollcode.com/t78ar8">
<table>
<tr>
<th colspan="2">What game site do you visit most?</th>
</tr>
<tr>
<td>
<input type="radio" name="answer" value="1" id="t78ar8answer1">
</td>
<td> <font face="Tahoma" size="2" color="000000"><label for="t78ar8answer1">Ign</label></font>
</td>
</tr>
<tr>
<td width="5">
<input type="radio" name="answer" value="2" id="t78ar8answer2">
</td>
<td>
<label for="t78ar8answer2">GameSpot</label>
</td>
</tr>
<tr>
<td width="5">
<input type="radio" name="answer" value="3" id="t78ar8answer3">
</td>
<td> <font face="Tahoma" size="2" color="000000"><label for="t78ar8answer3">GameFAQs</label></font>
</td>
</tr>
<tr>
<td width="5">
<input type="radio" name="answer" value="4" id="t78ar8answer4">
</td>
<td> <font face="Tahoma" size="2" color="000000"><label for="t78ar8answer4">GamerZone</label></font>
</td>
</tr>
<tr>
<td width="5">
<input type="radio" name="answer" value="5" id="t78ar8answer5">
</td>
<td> <font face="Tahoma" size="2" color="000000"><label for="t78ar8answer5">Mmohut</label></font>
</td>
</tr>
<tr>
<td colspan="2" height="10">
<center>
<input type="submit" value=" Vote ">
<input type="submit" name="view" value=" View ">
</center>
</td>
</tr>
</a> </font>
</td>
</tr>
</table>
</form>
</div>
Here's the jsfiddle http://jsfiddle.net/qX3Jp/ for a visual. Also, I know the code's format isnt right. I did that because it was all in one line and harder to read. If any additional information is needed, please ask before rejecting my question. Thanks
Here is a jsfiddle showing how i would do it. without a table because I hate tables and think that the only time they should be used is to display data and never for page layout.
also all of the styling has been separated from the markup.
for those too lazy to click the link... here is the code.
HTML:
<div id="poll">
<form method="post" action="http://poll.pollcode.com/t78ar8">
<h2 id="title">What game site do you visit most?</h2>
<div id="radio_btns">
<input type="radio" name="answer" value="1" id="t78ar8answer1">Ign<br />
<input type="radio" name="answer" value="2" id="t78ar8answer2">GameSpot<br />
<input type="radio" name="answer" value="3" id="t78ar8answer3">GameFAQs<br />
<input type="radio" name="answer" value="4" id="t78ar8answer4">GamerZone<br />
<input type="radio" name="answer" value="5" id="t78ar8answer5">Mmohut
</div>
<div id="submit_btns">
<input type="submit" value=" Vote ">
<input type="submit" name="view" value=" View ">
</div>
</form>
</div>
CSS:
#poll {
margin: 30px 0px 0px 5px;
font-family: Tahoma;
}
#radio_btns {
margin-bottom: 5px;
font-size: 13px;
}
#radio_btns input {
margin: 5px 10px 5px 5px;
}
#title {
margin-bottom: 3px;
font-size: 13px;
}
#submit_btns {
margin: 0px 0px 0px 60px;
}
notice that I broke the markup into sections and gave them ID's to make the CSS styling easier.
I went full form and removed what I see as unnecessary elements: tables + more. I put the font information in the body tag. Everything else in the CSS is layout related.
CSS:
* {
padding:0;
margin:0;
}
body {
font-family:Tahoma, Geneva, sans-serif;
font-size:14px;
color:#000;
}
label {
display:block;
}
fieldset {
border:none;
text-align:center;
}
legend {
font-weight:bold;
}
HTML:
<form method="post" action="http://poll.pollcode.com/t78ar8" id="poll">
<legend>What game site do you visit most?</legend>
<label for="t78ar8answer1"><input type="radio" name="answer" value="1" id="t78ar8answer1"> Ign</label>
<label for="t78ar8answer2"><input type="radio" name="answer" value="2" id="t78ar8answer2"> GameSpot</label>
<label for="t78ar8answer3"><input type="radio" name="answer" value="3" id="t78ar8answer3"> GameFAQs</label>
<label for="t78ar8answer4"><input type="radio" name="answer" value="4" id="t78ar8answer4"> GamerZone</label>
<label for="t78ar8answer5"><input type="radio" name="answer" value="5" id="t78ar8answer5"> Mmohut</label>
<fieldset>
<input type="submit" value=" Vote ">
<input type="submit" name="view" value=" View ">
</fieldset>
</form>
Related
I'm just trying to fit two areas together side by side like this:
but I am getting this:
I understand grids like by looking through w3schools and I try doing their examples of it but I still can't get it and I don't know why. Can someone please help me with this and also just roughly explain me grids. I tried watching Youtube videos and I almost get it, for example I know its kind of the same concept as tables in html.
Also code below:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body {
display:grid;
grid-template: 1fr 2fr;
grid-gap: 20px 20px 20px 20px;
}
table,td,th {
border: 1px solid black;
border-collapse:collapse;
}
th {
background-color:black;
color:white;
font-family:verdana;
}
.time {
background-color:#D3D3D3
}
.button {
border:0;
background:transparent;
text-decoration: underline;
font-weight:bold;
cursor:pointer;
}
td {
font-family:Calibri;
}
table {
display:inline-block;
}
form {
display:inline-block;
float:right;
}
</style>
</head>
<body>
<header>
<h1> Soccer Camp Registration</h1>
</header>
<div class="gridcontainer">
<colgroup>
<col class="times">
<colspan = "7">
</colgroup>
<div class="tables">
<table>
<tr class="days">
<th></th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td class="time">9:00 am-10:30am</td>
<td>Free Time</td>
<td rowspan="3">Technical Skills</td>
<td colspan="4">Training Session</td>
<td>Free Time</td>
</tr>
<tr>
<td class="time">10:30 am-12:00pm</td>
<td rowspan="3">Round Robin Games</td>
<td colspan="3" rowspan="2">Dribbling</td>
<td rowspan="2">Game Analysis</td>
<td> Agility</td>
</tr>
<tr>
<td class="time">1:00pm-2:30pm</td>
<td>Strength Training</td>
</tr>
<tr>
<td class="time">2:30pm-5:00pm</td>
<td colspan="3">Nutrition</td>
<td>Passing and Receiving</td>
<td colspan="2" rowspan="2">Campers Choice</td>
</tr>
<tr>
<td class="time">6:00pm-8:00pm</td>
<td colspan="5"> Night Games</td>
</tr>
</table>
</div>
<caption>July 2017 Weekly Schedule</caption>
<div class="forms">
<form method="POST" action="https://csunix.mohawkcollege.ca/tooltime/showit.pl">
<h2> Request Camp Information</h2>
<fieldset class="camplc">
<legend for="camplc"> Camper Location</legend>
<label for="province"> Province</label>
<select name="province" id="province">
<option value="BC"> British Columbia</option>
<option value="ON" >Ontario</option>
<option value="AB" >ALberta</option>
<option value="QC" >Quebec</option>
<option value="YK" > Yukon</option>
</select>
</fieldset>
<fieldset class="campid">
<legend for="campid"> Camper Identification</legend>
<label for="firstname"> First Name</label>
<input type="text" name="firstname" id="fn">
<br>
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="ln">
<br>
<label for="Gender">Gender</label>
<input type="radio" name="Gender" value="male" id="male">
<label for="male"> Male</label>
<input type="radio" name="Gender" value="female" id="female">
<label for="female">Female</label>
<br>
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="name#example.com">
<br>
<label for="age">Camper Age</label>
<select name="age" form="age">
<option value="8">8-9</option>
<option value="10" >10-12</option>
<option value="13" >13-15</option>
<option value="16" >16-19</option>
</select>
</fieldset>
<fieldset class="info">
<legend for="info"> Please Send me information about</legend>
<input type="checkbox" name="infoa" value="Camp Dates" id="cd">
<label for="campdates"> Camp Dates</label>
<br>
<input type="checkbox" name="infoa" value="Camp Fees" id="cf">
<label for="campdates"> Camp Fees</label>
<br>
<input type="checkbox" name="infoa" value="Transportation" id="tn">
<label for="campdates">Transportation</label>
</fieldset>
<fieldset class="questions">
<legend for="questions"> Question?</legend>
<textarea placeholder="Please enter any questions or comments here" rows ="5" cols="50"></textarea>
</fieldset>
<input type="submit" value="Request Info" class="button">
<input type="reset" value="Clear Form" class="button">
</form>
</div>
</div>
</body>
</html>
Try this code this is exactly as you gave your image hope it will work for you.
body {
/* display: grid;
grid-template-columns: 2fr 1fr;
grid-template-rows: 1fr; */
}
header { text-align: center;}
table,td,th {
border: 1px solid black;
border-collapse: collapse;
}
th {
background-color: black;
color: white;
font-family: verdana;
padding: 25px 67px;
}
.time { background-color:#D3D3D3 }
.button {
border: 0;
background:transparent;
text-decoration: underline;
font-weight:bold;
cursor: pointer;
}
td {
font-family: Calibri;
border: 1px solid #ccc;
padding: 20px;
}
table { display: inline-block; }
form {
display: inline-block;
border: 2px solid #262626;
/* float:right; */
}
.gridcontainer{
display: grid;
grid-template-columns: 2fr 1fr;
grid-template-rows: 1fr;
border: 2px solid #262626;
}
fieldset.camplc { padding: 20px 100px; }
fieldset.campid { padding: 10px 90px; }
fieldset.info { padding: 10px 85px; }
fieldset.questions { padding: 10px 90px; }
<header>
<h1> Soccer Camp Registration</h1>
</header>
<div class="gridcontainer">
<colgroup>
<col class="times">
<colspan = "6">
<!-- </colgroup> -->
<div class="tables">
<table>
<tr class="days">
<th></th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td class="time">9:00 am-10:30am</td>
<td>Free Time</td>
<td rowspan="3">Technical Skills</td>
<td colspan="4">Training Session</td>
<td>Free Time</td>
</tr>
<tr>
<td class="time">10:30 am-12:00pm</td>
<td rowspan="3">Round Robin Games</td>
<td colspan="3" rowspan="2">Dribbling</td>
<td rowspan="2">Game Analysis</td>
<td> Agility</td>
</tr>
<tr>
<td class="time">1:00pm-2:30pm</td>
<td>Strength Training</td>
</tr>
<tr>
<td class="time">2:30pm-5:00pm</td>
<td colspan="3">Nutrition</td>
<td>Passing and Receiving</td>
<td colspan="2" rowspan="2">Campers Choice</td>
</tr>
<tr>
<td class="time">6:00pm-8:00pm</td>
<td colspan="5"> Night Games</td>
</tr>
</table>
</div>
<caption>July 2017 Weekly Schedule</caption>
</colspan>
</colgroup>
<!-- <!-- <colgroup> -->
<col class="times">
<colspan = "4">
</colgroup>
<div class="forms">
<form method="POST" action="https://csunix.mohawkcollege.ca/tooltime/showit.pl">
<h2> Request Camp Information</h2>
<fieldset class="camplc">
<legend for="camplc"> Camper Location</legend>
<label for="province"> Province</label>
<select name="province" id="province">
<option value="BC"> British Columbia</option>
<option value="ON" >Ontario</option>
<option value="AB" >ALberta</option>
<option value="QC" >Quebec</option>
<option value="YK" > Yukon</option>
</select>
</fieldset>
<fieldset class="campid">
<legend for="campid"> Camper Identification</legend>
<label for="firstname"> First Name</label>
<input type="text" name="firstname" id="fn">
<br>
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="ln">
<br>
<label for="Gender">Gender</label>
<input type="radio" name="Gender" value="male" id="male">
<label for="male"> Male</label>
<input type="radio" name="Gender" value="female" id="female">
<label for="female">Female</label>
<br>
<label for="email">Email</label>
<input type="text" name="email" id="email" placeholder="name#example.com">
<br>
<label for="age">Camper Age</label>
<select name="age" form="age">
<option value="8">8-9</option>
<option value="10" >10-12</option>
<option value="13" >13-15</option>
<option value="16" >16-19</option>
</select>
</fieldset>
<fieldset class="info">
<legend for="info"> Please Send me information about</legend>
<input type="checkbox" name="infoa" value="Camp Dates" id="cd">
<label for="campdates"> Camp Dates</label>
<br>
<input type="checkbox" name="infoa" value="Camp Fees" id="cf">
<label for="campdates"> Camp Fees</label>
<br>
<input type="checkbox" name="infoa" value="Transportation" id="tn">
<label for="campdates">Transportation</label>
</fieldset>
<fieldset class="questions">
<legend for="questions"> Question?</legend>
<textarea placeholder="Please enter any questions or comments here" rows ="5" cols="50"></textarea>
</fieldset>
<input type="submit" value="Request Info" class="button">
<input type="reset" value="Clear Form" class="button">
</form>
</div>
</div>
Read the documentation and follow tutorials carefully. Even W3schools has nice tutorials on CSS grids. It was my starting point too when I was just learning CSS grids. So, it seems you haven't followed their tutorials or other tutorials as you should because you did things that I believe the tutorials would teach you not to do. Now lets break down what I mean by that.
First, the reason why CSS grids exist is NOT for you to still use display: inline-block or float on the elements you already positioned or want to position with display: grid;. I'm talking about this specific line:
table {
display:inline-block;
}
form {
display:inline-block;
float:right;
}
You used inline-block and float on the form and table, which are the elements you're trying to position with display-grid. That's not the goal. You need to stick with one. Either position them with display grid only, or use display inline-block. Even though you didn't really give display-grid on them, but these are the same elements that you will eventually assign the grid-area property after giving the display: grid to their parents.
so with that being said, here are the changes:
First I commented them out and instead used their wrapper divs to position them. By wrapper divs, I mean the div that you created with the class ="forms" and class="tables". Also, instead of giving display:grid to the body, I instead gave it to you gridcontainer div, which you created and again did not use.
Lastly, I also put the caption that is outside you tables div to be inside it because captions tag must be inserted immediately after the table tag. In short, compare the code bellow with the one you have to understand the changes I made and again, watch and read tutorials. Even w3schools that you mentioned as being the source you are learning css grids from explains enough for you to be able to achieve the tasks you wanted. And don't stop there. Keep learning other tutorials as well and happy coding. Here is the working code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.gridcontainer {
display:grid;
grid-template-areas: 'schedule info-table';
/*
grid-template: 1fr 2fr;
grid-gap: 20px 20px 20px 20px;
*/
}
table,td,th {
border: 1px solid black;
border-collapse:collapse;
}
th {
background-color:black;
color:white;
font-family:verdana;
}
.time {
background-color:#D3D3D3
}
.button {
border:0;
background:transparent;
text-decoration: underline;
font-weight:bold;
cursor:pointer;
}
td {
font-family:Calibri;
}
/*
table {
display:inline-block;
}
*/
/*
form {
display:inline-block;
float:right;
}
*/
.tables {
grid-area: schedule;
}
.forms {
grid-area: info-table;
border: 2px solid black;
height: 80vh;
}
table {
height: 70vh;
width: 100%;
}
h1 {
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
caption {
display: block;
border-bottom: 1px solid black;
height: 20px;
text-align: center;
}
</style>
</head>
<body>
<header>
<h1> Soccer Camp Registration</h1>
</header>
<div class="gridcontainer">
<!--Did not understand why you need this, so I just commented it out. Also,
the colspan was throwing sintax errors. Check it!!!!-->
<!--
<colgroup>
<col class="times">
<colspan="7">
</colgroup>
-->
<div class="tables">
<table>
<tr class="days">
<th></th>
<th>Sun</th>
<th>Mon</th>
<th>Tue</th>
<th>Wed</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td class="time">9:00 am-10:30am</td>
<td>Free Time</td>
<td rowspan="3">Technical Skills</td>
<td colspan="4">Training Session</td>
<td>Free Time</td>
</tr>
<tr>
<td class="time">10:30 am-12:00pm</td>
<td rowspan="3">Round Robin Games</td>
<td colspan="3" rowspan="2">Dribbling</td>
<td rowspan="2">Game Analysis</td>
<td> Agility</td>
</tr>
<tr>
<td class="time">1:00pm-2:30pm</td>
<td>Strength Training</td>
</tr>
<tr>
<td class="time">2:30pm-5:00pm</td>
<td colspan="3">Nutrition</td>
<td>Passing and Receiving</td>
<td colspan="2" rowspan="2">Campers Choice</td>
</tr>
<tr>
<td class="time">6:00pm-8:00pm</td>
<td colspan="5"> Night Games</td>
</tr>
</table>
<caption>July 2017 Weekly Schedule</caption>
</div>
<div class="forms">
<form method="POST"
action="https://csunix.mohawkcollege.ca/tooltime/showit.pl">
<h2> Request Camp Information</h2>
<fieldset class="camplc">
<legend for="camplc"> Camper Location</legend>
<label for="province"> Province</label>
<select name="province" id="province">
<option value="BC"> British Columbia</option>
<option value="ON">Ontario</option>
<option value="AB">ALberta</option>
<option value="QC">Quebec</option>
<option value="YK"> Yukon</option>
</select>
</fieldset>
<fieldset class="campid">
<legend for="campid"> Camper Identification</legend>
<label for="firstname"> First Name</label>
<input type="text" name="firstname" id="fn">
<br>
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="ln">
<br>
<label for="Gender">Gender</label>
<input type="radio" name="Gender" value="male" id="male">
<label for="male"> Male</label>
<input type="radio" name="Gender" value="female" id="female">
<label for="female">Female</label>
<br>
<label for="email">Email</label>
<input type="text" name="email" id="email"
placeholder="name#example.com">
<br>
<label for="age">Camper Age</label>
<select name="age" form="age">
<option value="8">8-9</option>
<option value="10">10-12</option>
<option value="13">13-15</option>
<option value="16">16-19</option>
</select>
</fieldset>
<fieldset class="info">
<legend for="info"> Please Send me information about</legend>
<input type="checkbox" name="infoa" value="Camp Dates" id="cd">
<label for="campdates"> Camp Dates</label>
<br>
<input type="checkbox" name="infoa" value="Camp Fees" id="cf">
<label for="campdates"> Camp Fees</label>
<br>
<input type="checkbox" name="infoa" value="Transportation"
id="tn">
<label for="campdates">Transportation</label>
</fieldset>
<fieldset class="questions">
<legend for="questions"> Question?</legend>
<textarea placeholder="Please enter any questions or comments
here" rows="5" cols="50"></textarea>
</fieldset>
<input type="submit" value="Request Info" class="button">
<input type="reset" value="Clear Form" class="button">
</form>
</div>
</div>
</body>
</html>
Here is the working link with the code on codepen: https://codepen.io/anon/pen/GPpXWM
I'd like to display both label and input in the same line using CSS for the following form. I tried using display, float and clear but not able to get the "look" I was coding for.
The form should look like this form
<header>
<title> Registration form </title>
<link rel="stylesheet" type="text/css" href="style.css">
</header>
<h2>Register here please ! </h2>
<form id="simpleform">
<fieldset>
<label for="name">Full Name </label>
<input type="text" name="name" id="name">
<label for="age">Age in Years </label>
<input type="number" name="age" id="age">
<label for="email">Email ID</label>
<input type="email" name="email" id="email">
<label for="email">Email ID</label>
<input type="email" name="email" id="email">
<label for="gender">Gender</label>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="Female">Female<br>
<label for="hobbies">Hobbies</label>
<input type="checkbox" name="hobbies" value="Reading"> Reading Books
<input type="checkbox" name="hobbies" value="movies"> Watching Movies
<input type="checkbox" name="hobbies" value="Singing"> Singing
<label for="country">Country</label>
<select name="country">
<option value="us">United States</option>
<option value="India">India</option>
</select>
<br>
<lable for="comments">Comments</lable>
<textarea name="comments" id="comments" rows=5 cols="50"></textarea>
<input type="submit">
<input type="reset" value="Start Again">
</fieldset>
</form>
I re-worked on my html and css and got this desired result
*{
margin: 0;
padding: 0;
}
body{
font-family:verdana sans-serif;
background-color: #99ffcc;
}
h2{
margin-top: 100px;
text-align: center;
color: blue;
}
#simpleform{
width: 500px;
margin: auto;
height: 400px;
border: 1px solid red;
background-color: #ccc;
}
label{
text-align: right;
clear: left;
float: left;
padding-right:13px;
margin-top: 12px;
width: 150px;
}
input,textarea {
margin-top: 12px;
width: auto;
}
input[type="email"]{
margin-top:16px;}
input[type="radio"]{
margin-top: 16px;
}
input[type="checkbox"]{
margin-top: 16px;
}
input[type="number"]{
margin-top:16px;
}
select{
margin-top: 13px;
}
#buttons{
margin-left:160px;
}
input[type="submit"]{
margin-right:80px;
background-color: white;
padding: 10px;
border-radius:10px;
border: 1px solid black;
}
input[type="reset"]{
margin-right:80px;
background-color: white;
padding: 10px;
border-radius:10px;
border: 1px solid black;}
input[type="submit"]:hover
{
background-color: aquamarine;
}
input[type="reset"]:hover
{
background-color: aquamarine;
}
input[type="text"],input[type="number"],input[type="email"]{
width:200px;
border: 1px solid black;
}
<html>
<header><title> Registration form </title>
<link rel="stylesheet" type="text/css" href="style.css">
</header>
<body>
<h2>Register here please ! </h2>
<form id="simpleform">
<div>
<label for="name">Full Name </label>
<input type="text" name="name" id="name">
</div>
<div>
<label for="age">Age in Years </label>
<input type="number" name="age" id="age">
</div>
<div>
<label for="email">Email ID</label>
<input type="email" name="email" id="email">
</div>
<div>
<label for="gender">Gender</label>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="Female">Female<br>
</div>
<div>
<label for="hobbies">Hobbies</label>
<input type="checkbox" name="hobbies" value="Reading"> Reading Books
<input type="checkbox" name="hobbies" value="movies"> Watching Movies
<input type="checkbox" name="hobbies" value="Singing"> Singing
</div>
<div>
<label for="country">Country</label>
<select name="country">
<option value="us">United States</option>
<option value="India">India</option>
</select><br>
</div>
<div>
<label for="comments" id="lable-comment">Comments</label>
<textarea name="comments" id="comments" rows=5 cols="50"></textarea>
</div>
<div id="buttons">
<input type="submit">
<input type="reset" value="Start Again"></div>
</form>
</body>
</html>
There are a lot of ways to get a 2-column layout but using a table is probably the most simple and straight-forward, example:
<form id="simpleform">
<fieldset>
<table>
<tr>
<td><label for="name">Full Name</label></td>
<td><input type="text" name="name" id="name"></td>
</tr>
<tr>
<td><label for="age">Age in Years</label></td>
<td><input type="number" name="age" id="age"></td>
</tr>
<tr>
<td><label for="email">Email ID</label></td>
<td><input type="email" name="email" id="email"></td>
</tr>
<tr>
<td><label for="gender">Gender</label></td>
<td>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="Female">Female
</td>
</tr>
<tr>
<td><label for="hobbies">Hobbies</label></td>
<td>
<input type="checkbox" name="hobbies" value="Reading"> Reading Books
<input type="checkbox" name="hobbies" value="movies"> Watching Movies
<input type="checkbox" name="hobbies" value="Singing"> Singing
</td>
</tr>
<tr>
<td><label for="country">Country</label></td>
<td>
<select name="country">
<option value="us">United States</option>
<option value="India">India</option>
</select>
</td>
</tr>
<tr>
<td><lable for="comments">Comments</lable></td>
<td>
<textarea name="comments" id="comments" rows=5 cols="50"></textarea>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit">
<input type="reset" value="Start Again">
</td>
</tr>
</table>
</fieldset>
</form>
Here is a sample code I got from my textbook and for some reason it's not displaying correctly. I just can't find the error.
It only show the second input text field "surname" and not the first input text "First name" also.
<html>
<head><title>Holiday Program</title></head>
<body style="background-color:cyan">
<form action="HolidayChoice.jsp"> <!--also try this with method="post"-->
<center>
<table style="background-color:lightblue”>
<tr>
<td>First Name<input type="text" name="clientFirstName"></td>
<td>Surname<input type="text" name="clientSurname"></td>
</tr>
<tr>
<td>Location :<br/>
<input type="radio" name="location" value="ocean"
checked=”true”>Ocean<br/>
<input type="radio" name="location" value="lake">Lake<br/>
<input type="radio" name="location" value="nature">
Nature Reserve<br/>
<input type="radio" name="location" value="casino">Casino<br/>
</td>
<td>Accommodation Type :<br/>
<input type="checkbox" name="hotel" value="1">Hotel<br/>
<input type="checkbox" name="camping" value="1">Camping<br/>
<input type="checkbox" name="caravan" value="1">Caravan<br/>
<input type="checkbox" name="bungalow" value="1">Bungalow
</td>
</tr>
<tr>
<td colspan="2">
<center>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</center>
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
You're using ” instead of " at line 6
So here is the problem illustrated with couple of printscreens for the different attempts I made to solve this problem. All this is happening in ASP.NET MVC 3 View.
I create my table like this :
<div id="drawForm">
<table id="drawTemplate" style="border:1px solid lightgrey;border-collapse: collapse">
#for (var i = 0; i < Model.Count; i++)
{
if (Model[i].Columns.Count > 0)
{
<tr>
#for (var j = 0; j < Model[i].Columns.Count; j++)
{
<td>
#Html.HiddenFor(x => x[i].Columns[j].RowNumber)
#Html.HiddenFor(x => x[i].Columns[j].ColumnNumber)
#Html.DisplayFor(x => x[i].Columns[j].QuestionText)
#Html.EditorFor(x => x[i].Columns[j].FieldValue)
</td>
}
</tr>
}
}
</table>
</div>
Notice the styling of the table, when the border is set to 1px I get this :
After some search about the topic I found some sort of solution by keeping everything the same only changing the table border value from 1 to 3px. After doing this I get :
Now I can see all the borders and I set the color of the border to red just to be more clear what I am meaning, in fact I can set it to lightgray and it's almost acceptable but one - it seems like some sort of a hack by doing this, and also - don't see something out of the ordinary which don't allow the normal rendering of the table and of course - I would really like to have a normal table layout and not to be forced to change the border width because of that.
I use some styling which is the same for both examples so I left it for the end :
#drawForm
{
margin: 0 auto;
width: 690px;
height: 800px;
border: 1px solid black;
}
#drawTemplate {
width: 690px;
}
tr
{
height: 50px;
border: 1px solid lightgrey;
}
td {
border: 1px solid lightgrey;
}
So the thing I would like to know is - why I get this problem at first place and of course - is there any way to deal with it besides this trick with the border width?
P.S
HTML output :
<table id="drawTemplate" >
<tr>
<td>
<input name="[0].Columns[0].RowNumber" type="hidden" value="1" />
<input name="[0].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[0].Columns[0].FieldValue" type="text" value="" />
</td>
<td>
<input name="[0].Columns[1].RowNumber" type="hidden" value="1" />
<input name="[0].Columns[1].ColumnNumber" type="hidden" value="2" />
<input class="text-box single-line" name="[0].Columns[1].FieldValue" type="text" value="yes" />
</td>
</tr>
<tr>
<td>
<input name="[1].Columns[0].RowNumber" type="hidden" value="2" />
<input name="[1].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[1].Columns[0].FieldValue" type="text" value="yes" />
</td>
</tr>
<tr>
<td>
<input name="[2].Columns[0].RowNumber" type="hidden" value="3" />
<input name="[2].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[2].Columns[0].FieldValue" type="text" value="yes" />
</td>
</tr>
<tr>
<td>
<input name="[3].Columns[0].RowNumber" type="hidden" value="4" />
<input name="[3].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[3].Columns[0].FieldValue" type="text" value="no" />
</td>
<td>
<input name="[3].Columns[1].RowNumber" type="hidden" value="4" />
<input name="[3].Columns[1].ColumnNumber" type="hidden" value="2" />
alabala
<input class="text-box single-line" name="[3].Columns[1].FieldValue" type="text" value="no" />
</td>
<td>
<input name="[3].Columns[2].RowNumber" type="hidden" value="4" />
<input name="[3].Columns[2].ColumnNumber" type="hidden" value="3" />
alabala
<input class="text-box single-line" name="[3].Columns[2].FieldValue" type="text" value="no" />
</td>
</tr>
<tr>
<td>
<input name="[4].Columns[0].RowNumber" type="hidden" value="5" />
<input name="[4].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[4].Columns[0].FieldValue" type="text" value="no" />
</td>
<td>
<input name="[4].Columns[1].RowNumber" type="hidden" value="5" />
<input name="[4].Columns[1].ColumnNumber" type="hidden" value="2" />
<input class="text-box single-line" name="[4].Columns[1].FieldValue" type="text" value="no" />
</td>
</tr>
<tr>
<td>
<input name="[5].Columns[0].RowNumber" type="hidden" value="6" />
<input name="[5].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[5].Columns[0].FieldValue" type="text" value="" />
</td>
</tr>
<tr>
<td>
<input name="[6].Columns[0].RowNumber" type="hidden" value="7" />
<input name="[6].Columns[0].ColumnNumber" type="hidden" value="1" />
alabala
<input class="text-box single-line" name="[6].Columns[0].FieldValue" type="text" value="no" />
</td>
</tr>
Try using this CSS declaration, it's enough for you to get a border for your table element and for each cell
#drawForm table {
border-collapse: collapse;
}
#drawForm table, .drawForm table td {
border: 1px solid #aaaaaa;
}
Also it seems like you'll be having that issue because you are looping through tr and td, where few td's are missed thus messing up your table as you need to declare rowspan and colspan
I am creating 1 of 3 nested tables within the <form> tag in my HTML document. I inserted input fields to create the text boxes to the right of the text. That all works my only problem is that the following cells: "First Name, Last Name, Address, City, State, Zip Code, and County" are not directly under one another in such a way as to keep the cells aligned and the text boxes aligned. How do I align each section? I hope I am explaining this well if not please ask for further clarification. Any help on this minor problem would be greatly appreciated.
Here's my code so far so you can see what I did:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<img src="j0182695_downsized.jpg" alt="Oatmeal Raisin cookies" style="float: left" >
</head>
<body background="back-225.gif">
<h1 style="text-align: center; color: red; font-family: Arial, Helvetica, sans-serif;">Cookies</h1>
<table width="500" border="0">
<tr>
<td align="center">About Us</td>
<td align="center">Contact Us</td>
<td align="center">Place an Order</td>
<td align="center">Sample Recipe</td>
</tr>
</table>
<form name="Web Order Form" id="Web Order Form">
<table border="0" cellpadding="2" width="65%">
<tr>
<td>Personal Information</td>
</tr>
<tr>
<td>First Name:
<input name="fname" id="fname" size="30" type="text" />
</td>
</tr>
<tr>
<td>Last Name:
<input name="lname" id="lname" size="30" type="text" />
</td>
</tr>
<tr>
<td>Address:
<input name="address" id="address" size="30" type="text" />
</td>
</tr>
<tr>
<td>City:
<input name="city" id="city" size="35" type="text" />
</td>
</tr>
<tr>
<td>State:
<input name="state" id="state" size="3" type="text" />
</td>
</tr>
<tr>
<td>Zip Code:
<input name="zip" id="zip" size="10" type="text" />
</td>
</tr>
<tr>
<td>Country:
<input name="country" id="country" size="10" type="text" />
</td>
</tr>
</table>
</form>
Just put the input boxes in another cell like this:
<tr>
<td>First Name:</td>
<td><input name="fname" id="fname" size="30" type="text" /></td>
</tr>
If you make all your rows like that, then the labels and input boxes will line up.
I posted an answer to your question over at Doctype: http://doctype.com/create-nested-table-html.
You should really look into using DIV's & CSS instead of Tables and Inline Styling for designing websites.
The following is an example of separating content from presentation. You have two main components on the page: A navigation menu (which is a list of links) and a contact form (which consists of a list of form elements). The HTML stands on its own and would display reasonably even without any styling.
First, styles are reset using Yahoo!'s reset stylesheet to ensure that the starting point is the same regardless of browser-specific defaults. Then, specific styles are applied until the resulting display reasonably matches the requirements.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link id="screen-reset" rel="stylesheet" type="text/css" media="screen"
href="http://yui.yahooapis.com/3.0.0/build/cssreset/reset-min.css">
<style type="text/css">
html { background:#eef; font-size:18px;}
body { background:#eee; margin:0 auto; width:95%;}
#main { clear:both; }
#hmenu { background:#fed; height:2em }
#hmenu li {
background:#fed;
display:block;
float:left;
padding:0 4px;
border-left:solid 4px #dcb;
}
#hmenu a {
display:block;
font-family:sans-serif;
font-size:1.5em;
font-weight:bold;
line-height:1.3333;
text-decoration:none;
}
form { padding:1em 0; }
fieldset {
background:#fff;
border:solid 1px #222;
padding:0.5em 0;
margin:0 auto;
width:90%;
}
legend {
background:#eee;
padding:0.1667em;
}
form li {
clear:both;
display:block;
padding:1em 0;
}
form li label {
display:block;
float:left;
font-family:sans-serif;
font-weight:bold;
padding:0 0.25em 0 0;
text-align:right;
width:35%;
}
form li input[type="text"] {
display:block;
float:left;
}
form input[type="submit"] {
margin:0 0 0 35%;
}
</style>
<title>Contact Form</title>
</head>
<body>
<div id="hmenu">
<ul>
<li>About Us</li>
<li>Contact Us</li>
<li>Place an Order</li>
<li>Sample Recipe</li>
</ul>
</div>
<div id="main">
<form name="web-order-form" id="web-order-form">
<fieldset>
<legend>Personal Information</legend>
<ul>
<li><label for="fname">First Name: </label>
<input name="fname" id="fname" size="30" type="text"></li>
<li><label for="lname">Last Name: </label>
<input name="lname" id="lname" size="30" type="text"></li>
<li><label for="address">Address: </label>
<input name="address" id="address" size="30"
type="text"></li>
<li><label for="city">City: </label>
<input name="city" id="city" size="35" type="text"></li>
<li><label for="state">State: </label>
<input name="state" id="state" size="3" type="text"></li>
<li><label for="zip">Zip Code: </label>
<input name="zip" id="zip" size="10" type="text"></li>
<li><label for="country">Country: </label>
<input name="country" id="country" size="10"
type="text"></li>
<li><input type="submit" name="submit-order" id="submit-order"
value="Place Order"></li>
</ul>
</fieldset>
</form>
</div>
</body>
</html>
Simply put the inputs into tds of their own:
<tr>
<td>First Name:</td>
<td><input name="fname" id="fname" size="30" type="text" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input name="lname" id="lname" size="30" type="text" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input name="address" id="address" size="30" type="text" /></td>
</tr>
And so on.
One easy option might be using flex style in table cell
<td style="display:flex">
<label>Flex</label>
<input type="text">
<input type="text">
</td>
It will show all elements in one row as long as there is enough space.