CSS and form width problems

W

William Krick

When I use the <form> tag and give it a background color, by default,
the form's width is 100%.

I would like it to behave like a table and have it constrict to fit the
content inside of it.

Is this possible with CSS?

Or do I have to resort to something ugly like putting a table around
the form?
 
J

Jim Moe

William said:
When I use the <form> tag and give it a background color, by default,
the form's width is 100%.

I would like it to behave like a table and have it constrict to fit the
content inside of it.
form { display: table; }
But that is not supported by IE.
Another way is to float the element: form { float: left; }. In the
absence of an explicit width rule, it shrinks to fit its contents. But
then you have to deal with a floating element.
 
B

BootNic

William Krick said:
When I use the <form> tag and give it a background color, by
default, the form's width is 100%.

I would like it to behave like a table and have it constrict to fit
the content inside of it.

Is this possible with CSS?

Or do I have to resort to something ugly like putting a table around
the form?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content=
"text/html; charset=windows-1252">
<style type="text/css">
form{
display:table;
color:#0000FF;
background-color:#E6E6FA;
border:#800080 0.1em solid;
}
input{
display:block;
margin:0.3em;
}
</style>
<!--[if IE]>
<style type="text/css">
form{
width:1px;
overflow:visible;
}
</style>
<![endif]-->
<title></title>
</head>
<body>
<form action="#">
<div>
<input><input type="submit">
</div>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top