I need to align labels and inputs of my form using CSS. The result should be something like this (I hope this simple scheme is clear):
Label1: ______
Labellll2: ______
Button
So, my HTML and CSS look as follows. The problem is that labels are placed on top of inputs, and also the button is on the right side instead of a bottom.
<form width="200px" name="optform" method="post" action="#">
<div class = "boxx">
<label for="param1">Param1:</label>
<input type="text" class="input-text" value="5" size="11" maxlength="11" name="param1" id="param1">
<label for="param2">Param1:</label>
<input type="text" class="input-text" value="5" size="11" maxlength="11" name="param2" id="param2">
</div>
<div class="buttons">
<a href="#">
<img src="images/opt.png" alt=""/> Run
</a>
</div>
div.boxx {
width: 500px;
}
div.boxx .input-text{
border:1px solid #A9C7F5;
color: #00557F;
font: 12px Arial;
float:left;
width:66%;
margin:0 0 0.5em 0.25em;
}
div.boxx label{
display:block;
font: 13px Arial;
color:#00557F;
width:33%;
float:left;
text-align:left;
padding-right: 8px;
}
.buttons a, .buttons button {
-moz-border-bottom-colors: none;
-moz-border-image: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DFF4FF;
border-color: #EEEEEE #DEDEDE #DEDEDE #EEEEEE;
border-style: solid;
border-width: 1px;
color: #565656;
cursor: pointer;
font-family: Verdana,arial,sans-serif;
font-size: 11px;
font-weight: bold;
line-height: 130%;
margin: 10px 10px 0 0;
padding: 4px 10px 3px 7px;
text-decoration: none;
}
.buttons button {
overflow: visible;
padding: 4px 10px 3px 7px;
width: auto;
}
The label needs to be
display:inline-block;
and the width is too large of either your label or input boxes. Padding and margins will cause problems with percentage widths because they are not taken into account.
Here is the updated css
div.boxx {
width: 500px;
}
div.boxx .input-text{
border:1px solid #A9C7F5;
color: #00557F;
font: 12px Arial;
width:60%;
margin:0 0 0.5em 0.25em;
}
div.boxx label{
display:block;
font: 13px Arial;
color:#00557F;
width:33%;
float:left;
text-align:left;
padding-right: 8px;
}
.buttons a, .buttons button {
-moz-border-bottom-colors: none;
-moz-border-image: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DFF4FF;
border-color: #EEEEEE #DEDEDE #DEDEDE #EEEEEE;
border-style: solid;
border-width: 1px;
color: #565656;
cursor: pointer;
font-family: Verdana,arial,sans-serif;
font-size: 11px;
font-weight: bold;
line-height: 130%;
margin: 10px 10px 0 0;
padding: 4px 10px 3px 7px;
text-decoration: none;
}
.buttons button {
overflow: visible;
padding: 4px 10px 3px 7px;
width: auto;
}
I know modern CSS people hate tables, but in this case (and with many alignment issues with divs) I recomment a nice little table.
<table>
<tr>
<td>Label1: </td><td><input type="text" /></td>
</tr><tr>
<td>Label2: </td><td><input type="text" /></td>
</tr><tr>
<td>Label3: </td><td><input type="text" /></td>
</tr>
</table>
<input type="button" />
Try something like this http://jsfiddle.net/mmyxD/
Is there a reason for all the margins/padding? Your width's are forcing the elements onto new lines.
You can also use divs and spans. Something like this:
<form action="">
<div class="row"><span class="label">label1:</span><span class="formw"><input type="text" size="25"></span></div>
<div class="row"><span class="label">label2:</span><span class="formw"><input type="text" size="25"></span></div>
<div class="spacer"> </div>
</form>
and css:
div.row {
clear: both;
padding-top: 10px;
}
div.row span.label {
float: left;
width: 33%;
text-align: left;
}
div.row span.formw input{
width: 100%;
}
div.row span.formw {
float: right;
width: 66%;
text-align: left;
}
Related
someone recommend me to use the fieldset but it didn't work,
here is the code
.block{
display: inline-block;
border: 2px solid white;
}
.title2{
color: white;
font-size: 1.5em;
text-align: center;
}
<fieldset class="block">
<legend class="title2">
Services
</legend>
</fieldset>
it show like this
I want is like this
here is the underline
Try this code:
Because your theme can override your fieldset style, you can just use !important to fix.
fieldset.block {
font-family: sans-serif!important;
border: 5px solid #1F497D!important;
background: #eee!important;
border-radius: 5px!important;
padding: 15px!important;
}
fieldset.block legend.title2 {
background: #1F497D!important;
color: #fff!important;
padding: 5px 10px!important;
font-size: 32px!important;
border-radius: 5px!important;
box-shadow: 0 0 0 5px #ddd!important;
margin-left: 20px!important;
}
<fieldset class="block">
<legend class="title2">Services</legend>
<p>Some text.</p>
</fieldset>
I am trying to style - newsletter - input - submit so that when you see the web in your phone the three elements show up one under the other- and all the boxes in the same size and align.
Does anyone have an easy solution for this? Ill appreciate your help very much. Regards and thanks! http://vtwg.eu/michael/index.html
V
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">NEWSLETTER</label>
<input type="text" name="Name" id="Name" />
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
input {
padding: 5px;
width: 120px;
font-family: arial, sans-serif;
font-size: 1em;
margin: 0px 0px 4px 0px;
border: 3px solid black;
background: white;
}
.submit-button {
float: center;
font-size: 1em;
}
label {
font-family: arial;
text-align: center;
width: 120px;
padding: 5.5px;
background:#57007F;
border: 3px solid black;
margin-left: 20px;
}
If you want to change design elements for mobie view, you should use media query. In the snippet media query set to max-width of viewport equal 480px. You can change this value as you wish. When you narrow browser window
down to less than 480px, you'll see the diference.
input {
display: inline-block;
padding: 5px;
width: 120px;
font-family: arial, sans-serif;
font-size: 1em;
margin: 0px 0px 4px 0px;
border: 3px solid black;
background: white;
}
.submit-button {
font-size: 1em;
display: inline-block;
}
label {
font-family: arial;
text-align: center;
width: 120px;
padding: 5.5px;
background:#57007F;
border: 3px solid black;
margin-left: 20px;
display: inline-block;
}
#media screen and (max-width: 480px) {
input, .submit-button, label {
display: block;
width: 120px;
margin: 5px;
box-sizing: border-box;
}
}
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">NEWSLETTER</label>
<input type="text" name="Name" id="Name" />
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
Write styles in media query with respect to the resolution.
HTML:
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">NEWSLETTER</label>
<input type="text" name="Name" id="Name" />
<input type="submit" name="submit" value="SUBMIT" class="submit-button" />
</form>
</div>
CSS:
input {
padding: 5px;
width: 120px;
font-family: arial, sans-serif;
font-size: 1em;
margin: 0px 0px 4px 0px;
border: 3px solid black;
background: white;
}
.submit-button {
float: center;
font-size: 1em;
}
label {
font-family: arial;
text-align: center;
width: 120px;
padding: 5.5px;
background:#57007F;
border: 3px solid black;
margin-left: 20px;
}
#media only screen and (max-width: 767px) {
label,
#Name,
.submit-button
{
width: 100%;
display: block;
margin: 5px 0;
box-sizing: border-box;
}
}
I am currently working on a web development project.
The problem is that all other CSS are working fine but there is a CSS class for a form just doesn't work. I've no idea what to do.
.actLeadClaims form {
margin:40px 25px;
padding: 10px 20px;
background: #f4f7f8;
border-radius: 8px;
width:465px;
font-family: 'Helvetica Neue', sans-serif;
}
.actLeadClaims h1 {
margin: 0 0 30px 0;
text-align: center;
}
.actLeadClaims input[type="text"],
.actLeadClaims input[type="password"],
.actLeadClaims input[type="date"],
.actLeadClaims input[type="datetime"],
.actLeadClaims input[type="email"],
.actLeadClaims input[type="number"],
.actLeadClaims input[type="search"],
.actLeadClaims input[type="tel"],
.actLeadClaims input[type="time"],
.actLeadClaims input[type="url"],
.actLeadClaims textarea,
.actLeadClaims select {
background: rgba(255,255,255,0.1);
border: none;
font-size: 16px;
height: auto;
margin: 0;
outline: 0;
padding: 15px;
width: 400px;
background-color: #e8eeef;
color: black;
box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
margin-bottom: 30px;
font-family: 'Helvetica Neue', sans-serif;
}
.actLeadClaims input[type="radio"],
.actLeadClaims input[type="checkbox"] {
margin: 0 4px 8px 0;
}
.actLeadClaims select {
padding: 6px;
height: 32px;
border-radius: 2px;
}
.actLeadClaims button {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #4bc970;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #3ac162;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
}
.actLeadClaims fieldset {
margin-bottom: 30px;
border: none;
}
.actLeadClaims legend {
font-size: 1.4em;
margin-bottom: 10px;
}
.actLeadClaims label {
display: block;
margin-bottom: 8px;
font-family: 'Helvetica Neue', sans-serif;
}
.actLeadClaims label.light {
font-weight: 300;
display: inline;
}
.actLeadClaims .number {
background-color: #5fcf80;
color: #fff;
height: 30px;
width: 30px;
display: inline-block;
font-size: 0.8em;
margin-right: 4px;
line-height: 30px;
text-align: center;
text-shadow: 0 1px 0 rgba(255,255,255,0.2);
border-radius: 100%;
}
<div class="actLeadClaims">
<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<label>Product Name:</label>
<input type="text" name="productName">
<label>Product Brand:</label>
<input type="text" name="productBrand">
<label>Product Series:</label>
<input type="text" name="productSeries">
<label>Comment:</label>
<textarea rows="6" name="productDesciption"></textarea>
<label>Picture:</label>
<input type="file" name="coverToUpload" id="coverToUpload"></br></br>
</fieldset>
<input type="submit" value="Add" name="uploadProduct">
</form>
</div>
However, all these code end up look like this:
Firstly, you've used BR tag in a wrong way. BR is written <br> or <br /> not </br>.
After that, you didn't specify what's your problem but I guess it's about locating labels regularly and make the form look good. If it's so, try the solution below. First, you correct BR tags:
<div class="actLeadClaims">
<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<label>Product Name:</label>
<input type="text" name="productName">
<label>Product Brand:</label>
<input type="text" name="productBrand">
<div class="clear"></div>
<label>Product Series:</label>
<input type="text" name="productSeries">
<label>Comment:</label>
<textarea rows="6" name="productDesciption"></textarea>
<div class="clear"></div>
<label>Picture:</label>
<input type="file" name="coverToUpload" id="coverToUpload"><br><br>
</fieldset>
<input type="submit" value="Add" name="uploadProduct">
</form>
</div>
Then add/modify CSS codes this way:
.actLeadClaims input[type="radio"],
.actLeadClaims input[type="checkbox"] {
margin: 0 4px 8px 0;
}
.actLeadClaims select {
padding: 6px;
height: 32px;
border-radius: 2px;
}
.actLeadClaims button {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #4bc970;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #3ac162;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
}
.actLeadClaims fieldset {
margin-bottom: 30px;
border: none;
}
.actLeadClaims legend {
font-size: 1.4em;
margin-bottom: 10px;
}
.actLeadClaims label {
margin-bottom: 8px;
font-family: 'Helvetica Neue', sans-serif;
}
.actLeadClaims label.light {
font-weight: 300;
display: inline;
}
.actLeadClaims .number {
background-color: #5fcf80;
color: #fff;
height: 30px;
width: 30px;
display: inline-block;
font-size: 0.8em;
margin-right: 4px;
line-height: 30px;
text-align: center;
text-shadow: 0 1px 0 rgba(255,255,255,0.2);
border-radius: 100%;
}
input,
textarea {
vertical-align: top;
}
label {
display: inline-block;
width: 130px;
text-align: right;
vertical-align: top;
}
.clear {
clear: both;
}
Take a look at the form in jsFiddle. Please expand the output part to see it widely.
I have a form and i want it positioned directly under the logo that
is positioned in the middle of the page. So far, i cant seem to do
more than this. Any help will be appreciated. Thanx.
Thie is HTML code:
<html>
<body>
<div id="content">
<div id="formwrapper">
<div id="image">
<img src="infiniteflame.jpg" width="200"height="100">
</div>
<div id="form">
<form>
<fieldset class="account-info">
<label>
Email Address
<input type="text" name="username">
</label>
<label>
Password
<input type="password" name="password">
</label>
</fieldset>
<fieldset class="account-action">
<input class="btn" type="submit" name="submit" value="Login">
-----OR----
<input class="btn" type="submit" name="submit" value="Login via facebook">
<div id="lang_pref">
<ul>
<li>English</li>
<li>العربية</li>
<li>čeština</li>
<li>dansk</li>
<li>Deutsch</li>
<li>Ελληνικά</li>
<li>español</li>
<li>español latinoamericano</li>
</ul>
</div>
</fieldset>
</form>
</div>
</div>
<footer>
<div class="copyright"><img src="infiniteflame.jpg" width="15" height="20" align="middle"><br/>Copyright© 2016 PopeeSoft Solutions, Inc.</div>
</footer>
</div>
</body>
</html>
This is CSS Code:
*,
*:before,
*:after {
box-sizing: border-box;
}
#content {
width: auto;
margin: auto;
border:1px solid #00C;
}
#formwrapper{
width: 1200px;
margin: auto;
height: 900px;
border:1px solid #00C;
}
#image {
position: fixed;
top: 50%;
left: 50%;
margin-top: -208px;
margin-left: -155px;
}
footer {
background: #eee;
}
form {
border: 1px solid #c6c7cc;
border-radius: 5px;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
overflow: hidden;
width: 350px;
}
fieldset {
border: 0;
margin: 0;
padding: 0;
}
input {
border-radius: 5px;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0;
width:349px;
}
.account-info {
padding: 20px 20px 0 20px;
}
.account-info label {
color: #395870;
display: block;
font-weight: bold;
margin-bottom: 20px;
}
.account-info input {
background: #fff;
border: 1px solid #c6c7cc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1);
color: #636466;
padding: 6px;
margin-top: 6px;
width: 100%;
}
.account-action {
background: #f0f0f2;
border-top: 1px solid #c6c7cc;
padding: 20px;
}
.account-action .btn {
background: linear-gradient(#49708f, #293f50);
border: 0;
color: #fff;
cursor: pointer;
font-weight: bold;
float: left;
padding: 8px 16px;
}
.account-action label {
color: #7c7c80;
font-size: 12px;
float: left;
margin: 10px 0 0 20px;
}
ul li{
list-style-type:none;
display: inline;
}
A bit of #image id changes solved the issue
<body>
<div id="content">
<div id="formwrapper">
<div id="image" align="center">
<img src="infiniteflame.jpg" width="200" height="100">
</div>
<div id="form" align="center">
<form>
<fieldset class="account-info">
<label>
Email Address
<input type="text" name="username">
</label>
<label>
Password
<input type="password" name="password">
</label>
</fieldset>
<fieldset class="account-action">
<input class="btn" type="submit" name="submit" value="Login"> -----OR----
<input class="btn" type="submit" name="submit" value="Login via facebook">
<div id="lang_pref">
<ul>
<li>English</li>
<li>العربية</li>
<li>čeština</li>
<li>dansk</li>
<li>Deutsch</li>
<li>Ελληνικά</li>
<li>español</li>
<li>español latinoamericano</li>
</ul>
</div>
</fieldset>
</form>
</div>
</div>
<footer>
<div class="copyright"><img src="infiniteflame.jpg" width="15" height="20" align="middle">
<br/>Copyright© 2016 PopeeSoft Solutions, Inc.</div>
</footer>
</div>
</body>
This is CSS:
#charset "utf-8";
/* CSS Document */
*,
*:before,
*:after {
box-sizing: border-box;
}
#content {
width: 100%;
margin: auto;
border: 1px solid #00C;
}
#formwrapper {
width: 100%;
margin: auto;
height: 900px;
border: 1px solid #00C;
}
footer {
background: #eee;
}
form {
border: 1px solid #c6c7cc;
border-radius: 5px;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
overflow: hidden;
width: 350px;
}
fieldset {
border: 0;
margin: 0;
padding: 0;
}
input {
border-radius: 5px;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0;
width: 349px;
}
.account-info {
padding: 20px 20px 0 20px;
}
.account-info label {
color: #395870;
display: block;
font-weight: bold;
margin-bottom: 20px;
}
.account-info input {
background: #fff;
border: 1px solid #c6c7cc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .1);
color: #636466;
padding: 6px;
margin-top: 6px;
width: 100%;
}
.account-action {
background: #f0f0f2;
border-top: 1px solid #c6c7cc;
padding: 20px;
}
.account-action .btn {
background: linear-gradient(#49708f, #293f50);
border: 0;
color: #fff;
cursor: pointer;
font-weight: bold;
float: left;
padding: 8px 16px;
}
.account-action label {
color: #7c7c80;
font-size: 12px;
float: left;
margin: 10px 0 0 20px;
}
ul li {
list-style-type: none;
display: inline;
}
I have a link and a submit button styled with the same .button class. Is there an easy way to make them look exactly the same (to have a same height)?
body .button {
text-align: center;
line-height: 15px;
background: #3333CC;
border-color: #5033CC;
border-radius: 4px;
color: #fff;
font-size: 11px;
border: 1px solid;
padding: 4px 7px 4px 7px;
cursor: pointer;
min-width: 90px;
text-decoration: none;
display: inline-block;
}
<form>
<a class="button" href="http://www.example.org">Link as button</a>
<input class="button" type="submit" value="button as button"/>
</form>
EDIT: I just found out that they look the same in Google Chrome, but not in Firefox.
In this example, they do have the same height (25pixels). You can always set a height in the CSS.
One thing you missed is changing the font-family.
In this example I've added one just to Helvetica, but that will make them more similar.
You can set box-sizing:border-box, set a solid height (25px in this example) and then change display:inline-block; to float:left;
body .button {
text-align: center;
line-height: 15px;
background: #3333CC;
border-color: #5033CC;
border-radius: 4px;
color: #fff;
font-size: 11px;
border: 1px solid;
padding: 4px 7px 4px 7px;
cursor: pointer;
min-width: 90px;
text-decoration: none;
float:left;
font-family:'Helvetica';
box-sizing:border-box;
height:25px;
}
<form>
<a class="button" href="http://www.example.org">Link as button</a>
<input class="button" type="submit" value="button as button"/>
</form>