Jump to content

[SOLVED] How to make forms with css


ryy705

Recommended Posts

Hello,

 

I am trying learn how to make a form using css instead of table.  But I am having problem with it.  If you would kindly copy and paste the following code you will see that the error message underneath the text area is not aligned with the text area.  What can I do to fix it?

I'll also accept any constructive criticism about the form.  I am trying to learn.

I thank you in advance.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="./test.css" media="screen" />
<title>Contact</title>
</head>
<body>
<div id="form">
<form method="post" action="">

<div class="row">
<label for="name">Name<br /><span class="small">Please enter your name (required)</span></label>

<input type="text" name="name" id="name" value="" /><br /><span class="err" id="nameErr">Invalid Entry</span>
</div>

<div class="row">
<label for="email">Email<br /><span class="small"> Please enter your email address (required)</span></label>

<input type="text" name="email" id="email" value="" /><br /><span class="err" id="emailErr">Invalid Entry</span>
</div>

<div class="rowTxt">
<label for="enq">Enquiry <br /><span class="small"> Please enter a general enquiry</span></label>

<textarea name="enq" id="enq" rows="5" cols="40"></textarea><br /><span class="err" id="enqErr">Invalid Entry</span>
</div>

<div class="row">
<input class="subButt" type="submit" name="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>

 

 

body{
    font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif; 
    font-size: small;
}

#form {
    float: left;
}

.row {
    height: 4em;
}

label {
    text-align: right;
    font-weight: bold; 
    display: block;
    float: left;
    width:  290px;
    padding: 0;
    margin: 0px 10px 20px 10px;
}

input,textarea {
    height: 1.5em;
    width:  15em;
    padding: 0;
    margin: 0px;
    border: 1px solid gray; 
    font: 11px "Lucida Sans Unicode", Verdana, Arial; 
    color: #666;
}

textarea {
    height: 10em;
    width:  15em;
}

input:focus, textarea:focus{
    border-width: 2px;
    border-color:    #d5dae7;
}

.small {
    display: block;
    padding: 0px;
    margin: 0px;
    font-size: xx-small;
    font-weight: normal;
    color: #666666;
}

.err {
    display: block;
    padding: 0px;
    margin: 0px;
    font-size: xx-small;
    font-weight: normal;
    color: #666666;
}

.subButt {
    clear: both;
    display: block;
    margin-left: auto;
    margin-right: auto;
    height: 30px;
    width:  200px;
    margin: 0px 0px 0px 250px;
    cursor:pointer;
    border:outset 1px #ccc;
    background:#999;
    color:#666;
    font-weight:bold;
    padding: 1px 2px;
}

.subButt:hover {
    color:black;
    border-bottom: 1px solid black;
    border-right: 1px solid black;
}

br {
    padding: 0px;
    margin: 0px;
}

.rowTxt {

}

Link to comment
Share on other sites

so i just looked at your code and the easist way was to make a label for it with no text

 

<div id="form">
<form method="post" action="">
	<div class="row">
		<label for="name">Name<br /><span class="small">Please enter your name (required)</span></label>
		<input type="text" name="name" id="name" value="" /><br />
			<span class="err" id="nameErr">Invalid Entry</span>
	</div>

	<div class="row">
		<label for="email">Email<br /><span class="small"> Please enter your email address (required)</span></label>
		<input type="text" name="email" id="email" value="" /><br />
			<span class="err" id="emailErr">Invalid Entry</span>
	</div>

	<div class="rowTxt">
		<label for="enq">Enquiry <br /><span class="small"> Please enter a general enquiry</span></label>

		<textarea name="enq" id="enq" rows="5" cols="40"></textarea><br />
		<label> </label>	<span class="err" id="enqErr">Invalid Entry</span>
	</div>

	<div class="row">
		<input class="subButt" type="submit" name="submit" value="Submit" />
	</div>
</form>
</div>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.