float elements of contact form to different sides - css

I have a contact form that I would like all elements to be floated to the left and aligned vertically, with the exception of the "message" box and submit button which should be floated and aligned on the right.
Currently, all fields seem to be flowing horizontally. How can I remedy?
jsfiddle
<div id="contact">
<div id="contact-form" class="clearfix">
<h2><img src="img/chat.png" alt="contact frsh studio"></h2>
<ul id="errors" class="">
<li id="info">There were some problems with your form submission:</li>
</ul>
<p id="success">Thanks for your message! We will get back to you ASAP!</p>
<form method="post" action="process.php">
<input type="text" id="name" name="name" value="" placeholder="NAME" required="required" autofocus="autofocus" />
<input type="email" id="email" name="email" value="" placeholder="EMAIL" required="required" />
<select id="enquiry" name="enquiry">
<option value="refrsh">Brand REFRSH</option>
<option value="consult">Brand Consultation</option>
<option value="support">Just a Hello!</option>
</select>
<textarea id="message" name="message" placeholder="MESSAGE" required="required" data-minlength="20"></textarea>
<span id="loading"></span>
<input type="submit" value="Holla!" id="submit-button" />
<p id="req-field-desc"><span class="required">*</span> kind of necessary</p>
</form>
</div>
</div><!-- end contact -->
#contact-form {
width: 690px;
padding:20px;
margin: 50px auto;
position:relative;
}
#contact-form h2 {
margin-bottom:20px;
margin-top:40px;
text-align: center;
}
#contact-form input,
#contact-form select,
#contact-form textarea,
#contact-form label {
font-size:15px;
margin-bottom:2px;
}
#contact-form input,
#contact-form select,
#contact-form textarea {
float: left !important;
width:320px;
margin-bottom:20px;
padding:4px;
}
#contact-form textarea {
height:150px;
resize: none;
}
#contact-form #message {
clear: both;
float: right !important;
}
#contact-form label {
display:block;
}
#contact-form .required {
font-weight:bold;
color:#F00;
}
#contact-form #submit-button {
width: 100px;
border: 2px solid #515151;
display:block;
float:rightright;
margin-bottom:0px;
margin-right:6px;
}
#contact-form #loading {
width:32px;
height:32px;
background-image:url(../img/loading.gif);
display:block;
position:absolute;
rightright:130px;
bottombottom:16px;
display:none;
}
#errors {
border:solid 1px #E58E8E;
padding:10px;
margin:25px 0px;
display:block;
width:437px;
-webkit-border-radius:8px;
-moz-border-radius:8px;
border-radius:8px;
background:#FFE6E6 url(../img/cancel_48.png) no-repeat 405px center;
display:none;
}
#errors li {
padding:2px;
list-style:none;
}
#errors li:before {
content: ' - ';
}
#errors #info {
font-weight:bold;
}
#errors #info:before {
content: '';
}
#success {
border:solid 1px #83D186;
padding:25px 10px;
margin:25px 0px;
display:block;
width:437px;
-webkit-border-radius:8px;
-moz-border-radius:8px;
border-radius:8px;
background:#D3EDD3 url(../img/accepted_48.png) no-repeat 405px center;
font-weight:bold;
display:none;
}
#errors.visible, #success.visible {
display:block;
}
#req-field-desc {
font-style:italic;
}
/* Remove box shadow firefox, chrome and opera put around required fields. It looks rubbish. */
input:required, textarea:required {
-moz-box-shadow:none;
-webkit-box-shadow:none;
-o-box-shadow:none;
box-shadow:none;
}
/* Normalize placeholder styles */
/* chrome, safari */
::-webkit-input-placeholder {
color:#CCC;
font-style:italic;
}
/* mozilla */
input:-moz-placeholder, textarea:-moz-placeholder {
color:#CCC;
font-style:italic;
}
/* ie (faux placeholder) */
input.placeholder-text, textarea.placeholder-text {
color:#CCC;
font-style:italic;
}

Updated JSFiddle: http://jsfiddle.net/jF49S/1/
As I mentioned in my comment, don't forget to utilize the CSS clear definition when dealing with float.
For instance, all that was needed here was a clear: left;.
#contact-form input,
#contact-form select,
#contact-form textarea {
clear:left;
float: left;
width:320px;
margin-bottom:20px;
padding:4px;
}
I also rearranged some of the HTML. Sometimes this is required to obtain the desired layout. For instance, I moved <textarea> to the beginning of the form in order for it to show up correctly.
Remember that, usually, there are many ways to accomplish a layout with HTML and CSS; my suggestion was just one way.
There are many articles and tutorials on float but here's a good primer: http://css-tricks.com/all-about-floats/

Related

How to set label and input in one line?

Hi i have a diferent style because betwin labale and input set icon. Please lock at the https://jsfiddle.net/mL1o0d5m/
css codes :
body{
font-family: tahoma;
font-size:14px;
background-color:#f1f1f1;
color:#999;
direction:rtl;
}
.form{
font-size:14px;
width:100%;
}
.form label{
text-align: right;
clear: both;
float:right;
}
.form input.inputs{
font-size:14px;
color:#999;
display:block;
border:1px solid #ccc;
border-right:none;
background-color:#fff;
width:80%;
margin-bottom:20px;
padding:10px;
padding-right:30px;
box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-shadow:none;
-webkit-appearance: none;
}
.addon{
position:relative;
font-size:0;
}
.addon:before{
display:block;
content:"";
width:3px;
height:100%;
background-color:#3399cc;
position:absolute;
}
.icon:before{
font-size:14px;
color:#bbb;
position:absolute;
top:12px;
right:12px;
}
HTML :
<form class="form">
<label>Name</label>
<div class="addon">
<i class="icon fa fa-user"></i>
<input class="inputs" name="name" type="text" placeholder="Name" />
</div>
</form>
I wanna to set label and input in same line .label should be in right and input and icon must be at left .
Thanks .
like this? https://jsfiddle.net/mL1o0d5m/1/ it is one of the many posibilities to achieve this. Added some css
.form > label{
text-align: right;
float:right;
width:40px;
margin-top:10px;
}and also to .icon:before and .addon:beforeSee in fiddle

Div not aligning properly

I have the following alignment problem: I want the "random" div to have a full width in the window, that's why I added the "width:100%" command. But for some reason, the maximum width it displays the random div on is the width of the "fixedwidth" div, but the two are not connected. Why does the browser keep matching the maximum width of the two divs? If i increase the width of the "fixedwitdth" div, then the width of the "random div" also increases. But that does not make any sense.
<html>
<head>
<title>Gliga's BBC</title>
<style type="text/css">
body {
margin:0px;
font-family: arial,helvetica;
}
#topbar {
background-color:#7A0000;
width:100%;
height:40px;
color:white;
}
.fixedwidth {
width:1200px;
background-color:green;
margin:0 auto;
}
#logodiv {
padding-top:7px;
padding-bottom:3px;
padding-left:50px;
float:left;
border-right: 2px solid #990000;
padding-right:30px;
}
#signindiv {
font-weight:bold;
padding:9px 80px 11px 20px;
font-size:0.9 em;
float:left;
border-right: 2px solid #990000;
}
#topmenudiv {
float:left;
}
#topmenudiv ul {
margin:0;
padding:0;
}
#topmenudiv li {
list-style:none;
font-weight:bold;
font-size:0.9 em;
border-right: 2px solid #990000;
height:100%;
padding:10px 20px 10px 20px;
float:left;
}
#searchdiv {
float:left;
padding:6px 10px 5px; 5px;
border-right: 2px solid #990000;
}
#searchdiv input{
height:20px;
}
.break {
clear: both;
}
.random {
background-color:blue;
margin-top:10px;
height:30px;
width:100%;
}
</style>
</head>
<body>
<div id="container">
<div id="topbar">
<div class="fixedwidth">
<div id="logodiv">
<img src="images/bbclogo.png"/>
</div>
<div id="signindiv">
Sign in
</div>
<div id="topmenudiv">
<ul>
<li>News</li>
<li>Sport</li>
<li>Weather</li>
<li>iPLayer</li>
<li>TV</li>
<li>Radio</li>
<li>More...</li>
</li>
</ul>
</div>
<div id="searchdiv">
<input type="text" placeholder="Search..." />
<div>
</div>
</div>
<div class="break" />
<div class="random">
</div>
</div>
</body>
</html>
.random is a child of .fixedwidth, so it's a totally normal behaviour happening there.
If you sort your code properly then you will get to see it clearly:

Want to make my web page resolution dependent?

I am creating one website in which I have created single page. The page displaying perfect in 1366 X 768 screen resolution.
But when I am opening the same page in 1024 X 768 resolution the Buttons and some text goes down.
I want to write a CSS in a way so it adjust or work properly in both the resolution. Below screen shot shows my problem.
In 1366 X 768 Resolution Page Looks Perfct! -> http://i50.tinypic.com/ac6blc.jpg
In 1024 X 768 Resolution Some elements goes down!!! -> http://i50.tinypic.com/2vxnjva.png
Can some one look my code and suggest me changes to make page display properly on both resolution.
Thanks a lot.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
/*=======Global Styles==========*/
body {
font-family:Geordia, serif;
margin:0;
padding:0;
}
a {
color:#3E97FB;
}
/*==============Container=========*/
div#container {
position:relative;
width:100%;
}
#header {
position:absolute;
top:5px;
width:100%;
background:#FFFFFF;
}
/*========Header 1=========*/
#header1 {
position:absolute;
background:url(images/images/headerbg.png) repeat-x;
width:100%;
height:111px;
left: 0px;
top: 96px;
}
#header1 #form {
float:left;
margin-left:8%;
margin-top:8px;
height:70px;
width:665px;
}
#form .email {
float:left;
margin-right:190px;
font-family:Arial;
font-size:12px;
font-weight:bold;
color:#FFF;
}
#form .password {
float:left;
margin-right:2%;
font-family:Arial;
font-size:12px;
font-weight:bold;
color:#FFF;
}
.clear {
clear:both;
}
#form .input {
float:left;
width:200px;
padding:7px 7px;
margin-right:5px;
width:200px;
border-bottom: 1px double #171717;
border-top: 1px double #171717;
border-left:1px double #333333;
border-right:1px double #333333;
}
#header1 .seprator {
float:left;
margin-left:30px;
background:url(images/images/line.png);
width:2px;
height:72px;
margin-top:15px;
}
#header1 .register {
float:left;
margin-left:6%;
margin-top:8px;
width:280px;
height:70px;
}
.register .noac {
color:#FFF;
font-family:"Trebuchet MS";
font-weight:bold;
text-align:center;
}
.loginbtn {
float:left;
display: inline-block;
width:186px;
height:40px;
}
.advertiserbtn {
display: inline-block;
margin:10px;
}
.publisherbtn {
display: inline-block;
margin:10px;
}
</style>
</head>
<body>
<div id="content">
<div id="header-line"></div>
<div id="header"></div>
<!--End header-->
<div id="header1">
<div id="form">
<div class="email">Email:</div>
<div class="password">Password:</div>
<div class="clear"></div>
<input type="text" class="input" />
<input type="text" class="input" />
<input type="button" class="loginbtn" value="Login" />
<div class="clear"></div>
</div>
<!--From Div End -->
<div class="seprator"></div>
<div class="register">
<div class="noac">Don't have an account yet!</div>
<input type="button" class="advertiserbtn"
value="Free Register" />
<input type="button" class="publisherbtn" value="Premium Registration"
/>
</div>
</div>
<!--End header1-->
<div id="footer"></div>
</div>
<!--End footer-->
</div>
<!--End Content Div-->
</body>
</html>
Use CSS media queries to alter the size of elements as the screen resolution increases. This can be done multiple times to even allow your elements to re size and reorder for mobile/tablet/laptop/desktop screen resolutions. Here is an example:
#media screen and (min-width:1024px) {
.loginbtn {
float: left;
display: inline;
width: 156px;
height: 40px;
}
}
#media screen and (min-width:1366px) {
.loginbtn {
width: 186px;
}
}
Go for a mobile first approach an declare your styles for the smallest width first. Change your widths at your breakpoints.
I think what you want is that the page doesn't get smaller than a specific value.
The easiest way to achieve this is to give you entire page a min-width. A horizontal scroll bar will appear if the window gets to small then.
You should try specifying the dimensions as percentage, instead of all px.

CSS elements won't line up

I have just embedded a newsletter field and button into my website, the field sits nicely but the button is too low. I tried different styles but nothing seems to work.
http://www.pazzle.co.uk/
Just underneath the banner.
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="http://pazzle.us6.list-manage.com/subscribe/post?u=7167bf73b26b7bd1298d4f925&id=a48b73e435" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
<div class="clear">
<input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button">
</div>
</form>
</div>
<!--End mc_embed_signup-->
#mce-EMAIL {float:left;}
#mc-embedded-subscribe {}
/* MailChimp Form Embed Code - Slim - 08/17/2011 */
#mc_embed_signup form {display:block; }
#mc_embed_signup h2 {font-weight:bold; padding:0; margin:15px 0; font-size:1.4em;}
#mc_embed_signup input {border:1px solid #999; -webkit-appearance:none;}
#mc_embed_signup input[type=checkbox]{-webkit-appearance:checkbox;}
#mc_embed_signup input[type=radio]{-webkit-appearance:radio;}
#mc_embed_signup input:focus {border-color:#333;}
#mc_embed_signup .button {clear:both; background-color: #aaa; border-radius:4px; color: #FFFFFF; cursor: pointer; font-size:15px; font-weight: bold; line-height: 28px; padding:0; text-align: center; text-decoration: none; vertical-align: top; white-space: nowrap; width: auto;}
#mc_embed_signup .button:hover {background-color:#777;}
#mc_embed_signup .small-meta {font-size: 11px;}
#mc_embed_signup .nowrap {white-space:nowrap;}
#mc_embed_signup .clear {clear:none; display:inline; float:left;}
#mc_embed_signup input.email {display:block; padding: 5px 0; text-indent: 8px; width: 120px !important; margin-left: 13px;margin-top: 5px; float:left;}
#mc_embed_signup input.button {display:block; min-width: 50px; height: 28px; margin-top: 5px;}
#mc_embed_signup div#mce-responses {float:left; top:-1.4em; padding:0em .5em 0em .5em; overflow:hidden; width:90%;margin: 0 5%; clear: both;}
#mc_embed_signup div.response {margin:1em 0; padding:1em .5em .5em 0; font-weight:bold; float:left; top:-1.5em; z-index:1; width:80%;}
#mc_embed_signup #mce-error-response {display:none;}
#mc_embed_signup #mce-success-response {color:#529214; display:none;}
#mc_embed_signup label.error {display:block; float:none; width:auto; margin-left:1.05em; text-align:left; padding:.5em 0;}
#mc_embed_signup {float:left; height: 30px;}
Try adding float: left to the #mc_embed_signup .clear div and the #mc_embed_signup input.email textbox
The issue is here in the CSS:
#mc_embed_signup .button on line 1176 of stylesheets.css
Get rid of the clear:both from that class and it will get the submit button in line with the form field. From there you should be able to fix up the margin/positioning.
clear:both essentially prevents the element from ever being inline with any other element. It clears floats such that it can't be floated next to another element.
not sure if this is exactly what you were talking about but I added #mc_embed_signup .clear { float: right;}. this will put the submit button into the form box and then you can get specific with alignment using postion:relative

Box issue in Chrome versus Firefox

In Chrome, notice that that input area under "Your contact info" lines up with the border for div#contact. Also notice that the textarea under "Message" does not line up with that border; it's moved in a couple pixels. This is not the behavior I prefer.
In Firefox, everything lines up on the left. It's a little difficult, but you can see that in this screencap. This is the behavior I prefer.
My problem is obvious: how do I get those input areas to line up on the left (as in the Firefox image)?
Here is the HTML (non-working skeleton form code) that's rendered for that portion of the page (which resides in the footer of the page).
<div id="footer">
<div id="contact">
<h1>Talk to me</h1>
<div id="email-me">You can email me at address#server.com<br/>
or fill out the form below!
</div>
<form>
<div id="email">
<h2>Your contact info</h2>
<input type="text"/><br/>
</div>
<div id="message">
<h2>Message</h2>
<textarea rows="10" cols="75"></textarea><br/>
</div>
<input class="buttons" type="submit" value="Send"/>
</form>
</div>
</div>
Here's the CSS. It's quite long, so I was going to edit out some parts, but I decided against it in case some small piece makes the difference.
#footer {
clear:both;
background-color:#8BA5B5;
min-height:400px;
font-size:13px;
font-family:Helvetica,Verdana,Arial,sans-serif;
color:#fff;
padding-left:105px;
padding-top:30px;
padding-bottom:45px;
position:relative;
top:5px;
overflow:hidden;
}
#footer h1 {
font-size:15px;
margin:0px;
margin-bottom:5px;
}
#footer a {
color:#DAEBF5;
text-decoration:none;
margin-bottom:5px;
}
#footer a:visited {
color:#333;
text-decoration:none;
}
#footer a:hover {
text-decoration:underline;
}
#email-me {
font-size:16px;
padding-left:2px;
margin-bottom:10px;
text-align:center;
}
#email-me a {
font-size:18px;
font-style:normal;
}
#contact {
float:left;
overflow:hidden;
font-style:oblique;
font-family:georgia,times,serif;
}
#contact h1 {
font-size:44px;
font-style:normal;
text-align:center;
font-family:helvetica,verdana,arial,sans-serif;
}
#contact h2 {
margin:0px;
font:inherit;
}
#contact input {
background-color:transparent;
border:1px solid #fff;
color:#fff;
width:50%;
}
#contact textarea {
background-color:transparent;
border:1px solid #fff;
color:#fff;
}
#contact #message {
margin-top:5px;
margin-bottom:5px;
}
#contact .buttons {
font-family:inherit;
font-weight:800;
font-size:12px;
padding:5px;
width:100%;
background-color:#fff;
color:#8BA5B5;
}
It seams that your margins are off... Are you using a CSS reset to level the style across all browsers?
try setting margin:0; to your inputs
For a css reset, I recommend:
http://meyerweb.com/eric/tools/css/reset/
#contact input, #contact textarea {
margin:0px;
}

Resources