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
https://forums.phpfreaks.com/topic/124720-solved-how-to-make-forms-with-css/
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>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.