CSS & Form issue - giving me strife :( [closed] - html

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have created a form and it is supposed to look like this:
Can someone please help me edit my code to look like the above image and explain what I was doing wrong? A JSFiddle would be amazing so I can understand how to fix it.
The zip label and field needs to be brought up and the submit button pushed to the right, yet it's not working for me :(
My attempt is as follows:
http://jsfiddle.net/2w6mK/
CSS:
#form-container {
width: 710px;
height: 450px;
padding: 20px 50px;
margin: 35px 0 0 25px;
}
form {
position: relative;
margin-left: -10px;
}
form label {
display: block;
font: normal 12px/16px arial, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #000;
text-transform: uppercase;
text-align: left;
}
form [type="text"],
form [type="email"] {
display: block;
border: 1px solid #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font: 12px/14px arial, helvetica, verdana, sans-serif;
width: 60%;
padding: 5px 5px;
margin: 5px 0;
-webkit-appearance: none;
}
.zip {
display: block;
border: 1px solid #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font: 12px/14px arial, helvetica, verdana, sans-serif;
width: 20%;
padding: 5px 5px;
margin: 5px 0;
-webkit-appearance: none;
}
.dob-select {
display: block;
border: 1px solid #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font: 12px/14px arial, helvetica, verdana, sans-serif;
width: 80px;
height:25px;
-webkit-appearance: none;
overflow: hidden;
background: url("http://s17.postimage.org/4tmf81arf/down_arrow.png") no-repeat right #fff;
float: left;
margin-right: 5px;
}
.dob-select select {
background: transparent;
width: 125px;
height: 25px;
border: none;
padding: 5px 0 0 5px;
color: #cccccc;
}
.left {
float: left;
}
form [type="submit"] {
display: block;
background-image: url("http://findmuck.files.wordpress.com/2012/06/green_submit_button_by_rukiaxichigo15.jpg") no-repeat;
margin: 25px auto;
width: 154px;
height:57px;
border: none;
color: transparent;
font-size: 0;
float: left;
}
form input[type=submit]:hover {
background-image: url("http://findmuck.files.wordpress.com/2012/06/green_submit_button_by_rukiaxichigo15.jpg") no-repeat;
cursor: hand;
cursor: pointer;
}
#FileUpload {
position:relative;
margin-top: -13px;
padding-bottom: 15px;
}
#BrowserVisible {
position: absolute;
top: 0;
left: 0;
z-index: 1;
background:url(images/btn_browse.gif) 100% 0px no-repeat;
height:27px;
width:390px;
cursor: hand;
cursor: pointer;
}
#FileField {
display: block;
margin-right: 85px;
border: 1px solid #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font: 12px/14px arial, helvetica, verdana, sans-serif;
color: #777;
width: 300px;
padding: 5px 5px;
-webkit-appearance: none;
}
HTML:
<div id="form-container">
<form>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name">
</fieldset>
<fieldset>
<label for="dob">date of birth</label>
<div class="dob-select">
<select name="dob_day">
<option value="01">01</option>
</select>
</div>
<div class="dob-select">
<select name="dob_month">
<option value="01">Jan</option>
</select>
</div>
<div class="dob-select">
<select name="dob_year">
<option value="2012">2012</option>
</select>
</div>
</fieldset>
<fieldset>
<label for="zip">zip</label>
<input type="text" class="short" name="zip">
</fieldset>
<fieldset>
<label for="email">Email</label>
<input type="email" name="email">
</fieldset>
<fieldset>
<label for="subscribe"><input type="checkbox" class="left"> <p class="left">Tick</p></label>
<input type="submit" name="submit">
</fieldset>
</form>
</div>

EDIT 2:
Add
.short{
width: auto !important;
}
to CSS to draw the ZIP field with full lenght as in picture.
EDIT: remove border: 1px solid silver; when you have understood how positioning is working, it's for debug purpose ;)
Look at: http://jsfiddle.net/pb6mM/3/
form input[type="submit"]{
position: absolute;
right: 0;
bottom: 0;
}
fieldset{
border: 1px solid silver;
}
.fieldsetDate{
padding-right: 30px;
}
.inlineBlock{
display: inline-block;
}
And added
margin-top: 6px;
margin-bottom: 6px;
to .dob-select { to make it the same height of the normal text field.
HTML:
<div id="form-container">
<form>
<fieldset>
<label for="name">Name</label>
<input type="text" name="name">
</fieldset>
<fieldset class="fieldsetDate inlineBlock">
<label for="dob">date of birth</label>
<div class="dob-select">
<select name="dob_day">
<option value="01">01</option>
</select>
</div>
<div class="dob-select" >
<select name="dob_month">
<option value="01">Jan</option>
</select>
</div>
<div class="dob-select">
<select name="dob_year">
<option value="2012">2012</option>
</select>
</div>
</fieldset>
<fieldset class="inlineBlock">
<label for="zip">zip</label>
<input type="text" class="short" name="zip">
</fieldset>
<fieldset>
<label for="email">Email</label>
<input type="email" name="email">
</fieldset>
<fieldset>
<label for="subscribe"><input type="checkbox" class="left"> <p class="left">Tick</p></label>
<input type="submit" name="submit">
</fieldset>
</form>
</div>

Add Position:absolute to input button. and there is slight changes in the html code. Check the demo.
DEMO
SAMPLE CSS FORM

Related

How to centralize content inside a form

Could someone help me? I am with this form trying to centralize all fields in it. I've tried a bunch of different stuff, and I've noticed that the code works differently inside the theme that I am using. Is there another way to do it rather than margin: 0 auto;? Any help will be really appreciated. Here is the url. Thank you
<div id="instant-quote-form">
<form action="http://natesolutions.vonigo.com/external/" accept-charset="UTF-8" method="get" onsubmit="return submitForm(this)">
<div class="instant-quote">
<h3 class="quote-title">Instant Online Quote</h3>
</div>
<div class="house-type">
<input type="radio" onclick="showServices(this)" id="xclientTypeID" name="xclientTypeID" value="1" checked />Residential
<input type="radio" onclick="showServices(this)" id="xclientTypeID" name="xclientTypeID" value="2" />Commercial
</div>
<div class="zip-code">
<input type="text" id="zip" name="zip" value="" placeholder="Enter Postal Code"/>
</div>
<div class="house-size" id="divServices1">
<select id="xserviceTypeID1" onchange="changeService(this)">
<option value="14" selected>Small House (1200-2000sq.ft)</option>
<option value="17">Medium House (2001-2800sq.ft)</option>
<option value="18">Large House (2801-3500sq.ft)</option>
<option value="19">XL House (3500+)</option>
</select>
</div>
<div class="button-go">
<input type="submit" value="Go" />
</div>
<input type="hidden" id="xserviceTypeID2" value="20" />
<input type="hidden" id="xserviceTypeID5" value="20" />
<input type="hidden" id="clientTypeID" name="clientTypeID" value="1" />
<input type="hidden" id="serviceTypeID" name="serviceTypeID" value="14" />
</form>
</div>
<style>
#instant-quote-form {
width: 100%;
margin: 0 auto;
}
.instant-quote {
float: left;
margin: 20px 5px;
padding-top: 4px;
}
.house-type {
float: left;
margin: 20px 5px;
color: #ffffff;
font-size: 16px;
padding-top: 5px;
}
.zip-code {
float: left;
margin: 20px 5px;
border: 1px solid #ffffff;
border-radius: 3px;
color: #000000;
}
.house-size {
float: left;
margin: 20px 5px;
border: 1px solid #ffffff;
border-radius: 3px;
color: #000000;
}
select#xserviceTypeID1 {
border: 1px solid #ffffff;
font-size: 13px;
padding: 10px;
color: #000000;
}
.button-go {
float: left;
margin: 20px 5px;
}
h3.quote-title {
margin-bottom: 0;
color: #ffffff;
}
input#zip {
margin-bottom: 0;
border: 1px solid #ffffff;
font-size: 13px;
padding: 9px;
}
input#zip::placeholder {
color: #000000;
}
input[type=text]::placeholder {
color: #000000;
}
input#xclientTypeID {
margin: 0 5px;
}
input[type="submit"] {
height: 37px;
width: 50px;
background: #55b948;
color: #fff;
border-radius: 3px;
text-transform: uppercase;
border: 1px solid #55b948;
font-weight: bold;
}
</style>
As your #instant-quote-form is as wide as its parent, centering this element will not do anything. What you will need to do is to center the <form> inside of its container. This can be done by applying display:flex to #instant-quote-form and then margin:0 auto to #instant-quote-form > form:
#instant-quote-form {
display: flex;
}
#instant-quote-form > form {
margin: 0 auto;
}
Try enclosing your <form> within <center> tag
Additionally, If you want the form with elements in a vertically aligned fashion then set float to none for each direct child of your <form>
If this isn't what you were looking for, please elaborate your issue and expected outcome.

CSS - Styling a form

I'm styling a form for a site and I need it to look like this -
My coded version, so far, looks like this -
The name & email sections for some reason won't size properly and there seems to be padding or margin properties somewhere which I can't seem to override. Here's my code as it stands -
form {
height: 200px;
width: 400px;
margin-right: 50px;
}
.name {
float: left;
}
input[type=text],
input[type=email] {
background: #F0F0F0;
font-size: 10px;
width: 100%;
height: 20px;
}
input[type=subject] {
background: #F0F0F0;
font-size: 10px;
width: 100%;
height: 20px;
}
textarea {
resize: vertical;
font-size: 10px;
width: 100%;
background: #F0F0F0;
height: 100px;
}
input[type=submit] {
background: #00bfff;
border: none;
color: #ffffff;
cursor: pointer;
font-size: 10px;
font-weight: 700;
width: 100%;
}
<div class="six columns">
<form>
<fieldset>
<div class="name">
<input type="text" required placeholder="NAME">
</div>
<div class="name">
<input type="email" required placeholder="EMAIL">
</div>
<div>
<input type="subject" placeholder="SUBJECT">
</div>
<div>
<textarea placeholder="MESSAGE..."></textarea>
</div>
</fieldset>
<input type="submit" value="SUBMIT">
</form>
</div>
UPDATE - Latest version.
I made a bunch of tweaks and kind of last track as I went, so I hope you're able to read through this and figure it out. If not, please feel free to ask questions!
form {
height: 200px;
width: 400px;
margin-right: 50px;
}
fieldset {
border: none;
padding: 0;
margin: 0;
display: flex;
}
div.row {
display: flex;
width: 100%;
}
div.row input {
margin-left: 5px;
}
div.row input:first-child {
margin-left: 0;
}
input[type=text],
input[type=email] {
background: #E8E8E8;
font-size: 10px;
width: 100%;
box-sizing: border-box;
border: 0;
padding: 0;
margin-bottom: 5px;
padding: 6px 12px;
}
textarea {
resize: none;
font-size: 10px;
background: #E8E8E8;
width: 100%;
box-sizing: border-box;
border: 0;
padding: 6px 12px;
margin-bottom: 5px;
}
input[type=submit] {
background: #1ba4dd;
border: none;
color: #ffffff;
cursor: pointer;
font-size: 10px;
font-weight: 700;
width: 100%;
padding: 8px 0;
}
input[type=submit]:hover {
background: #00bfff;
}
<div class="six columns">
<form>
<fieldset>
<div class="row">
<input name="name" type="text" required placeholder="NAME">
<input name="email" type="email" required placeholder="EMAIL">
</div>
<input name="subject" type="text" placeholder="SUBJECT">
<textarea rows="8" placeholder="MESSAGE..."></textarea>
</fieldset>
<input type="submit" value="SUBMIT">
</form>
</div>

Aligning search box to center

I picked a good css/html code for implementation of search box on the web. But I can't move the search box to center. The below css code is about search box.
#search {
width: 357px;
margin: 4px;
}
#search_text{
width: 297px;
padding: 15px 0 15px 20px;
font-size: 16px;
font-family: Montserrat, sans-serif;
border: 0 none;
height: 52px;
margin-right: 0;
color: white;
outline: none;
background: #1f7f5c;
float: left;
box-sizing: border-box;
transition: all 0.15s;
}
<li id="search">
<form action="" method="get">
<input type="text" name="search_text" id="search_text" placeholder="Search"/>
<input type="button" name="search_button" id="search_button"/>
</form>
</li>
What should I fix the code for aligning the search box?
Thanks.
Try providing text-align: center to your body.
Refer code:
body {
text-align: center;
}
#search {
width: 357px;
margin: 4px auto;
text-align: center;
display: inline-block;
}
#search_text {
width: 297px;
padding: 15px 0 15px 20px;
font-size: 16px;
font-family: Montserrat, sans-serif;
border: 0 none;
height: 52px;
margin-right: 0;
color: white;
outline: none;
background: #1f7f5c;
float: left;
box-sizing: border-box;
transition: all 0.15s;
}
<li id="search">
<form action="" method="get">
<input type="text" name="search_text" id="search_text" placeholder="Search" />
<input type="button" name="search_button" id="search_button" />
</form>
</li>
If you want to align the text in the center of the textbox than use #nashcheez answer.
If you want to align the searchbox itself to the center of the parent than:
Set the textbox to display block
Give a with to the textbox
Set margin-left to auto
Set margin-right to auto
You may have to set position to relative.
you can try to use:
#search {
width: 357px;
margin-right: auto;
margin-left: auto;
}
if its being overridden, try using:
#search {
width: 357px;
margin-right: auto !important;
margin-left: auto !important;
}
If li#search is all you've got, try this:
#search {
width: 357px;
margin: 4px auto;
}
#search_text{
width: 297px;
padding: 15px 0 15px 20px;
font-size: 16px;
font-family: Montserrat, sans-serif;
border: 0 none;
height: 52px;
margin-right: 0;
color: white;
outline: none;
background: #1f7f5c;
float: left;
box-sizing: border-box;
transition: all 0.15s;
}
<li id="search">
<form action="" method="get">
<input type="text" name="search_text" id="search_text" placeholder="Search"/>
<input type="button" name="search_button" id="search_button"/>
</form>
</li>

HTML: Textbox and Select Dropdown are not level

I've been messing with this for a while now and I can simply not get the dropdown to be level with the textboxes! I've been changing the padding, margin, borders, height and all I can think of to make it be level both at the top and at the bottom.
What could be wrong?
.metricDateTextbox {
width: 130px;
padding: 11px;
border: 1px solid white;
color: transparent;
text-shadow: 0 0 0 black;
font-family: Verdana;
font-weight: 500;
background: #fff center right 10px no-repeat url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAQCAYAAAAMJL+VAAAAjUlEQVR42rTTQQ6DIBBG4XcuOZlIMHri2gtMN2OKBAt05E/YsPheDBG+84DDPqfWZRsgwNsYcWqImgDseiHGiAOOzNoB5uzyn0gJF7W5ixyNkSqePnJvZGrFa5GpA/e1T14aInf40vpovyJmvBZ5PYGfCwUsP8H664eR+LlYwFceXhqJDFrsxkVk6PkMALMhvwVPjvl/AAAAAElFTkSuQmCC);
background-size: 12px 8px;
cursor: pointer;
user-select: none;
margin: 0;
}
::-webkit-input-placeholder {
color: grey;
font-weight: 500;
font-family: Verdana;
}
.dwmViewSelect {
width: 80px;
height: 40px;
top: -10px;
font-weight: bold;
border: 1px solid white;
margin: auto;
padding-top: unset 50px;
}
.showDateBtn {
width: auto;
padding: 10px;
text-align: center;
}
<form method="post" action="" name="form">
<div class="reportDateDiv">
<a class="blackColor fSize18">Reporting Period</a>
<input type="text" name="inputDate" spellcheck="false" class="datepicker metricDateTextbox capitalFirst" value="#inputDate" autocomplete="off" placeholder="#placeholderStartDate.ToString(" MMM d, yyyy ")" readonly="readonly" />
<a class="blackColor fSize16">to</a>
<input type="text" name="endDate" spellcheck="false" class="datepicker metricDateTextbox capitalFirst" value="#endDate" autocomplete="off" placeholder="#noEndDate.ToString(" MMM d, yyyy ")" readonly="readonly" />
<select name="hAxisType" class="dwmViewSelect">
<option selected=#(Request.Form[ "hAxisType"]=="1" ) value="1">Daily</option>
<option selected=#(Request.Form[ "hAxisType"]=="2" ) value="2">Weekly</option>
<option selected=#(Request.Form[ "hAxisType"]=="3" ) value="3">Monthly</option>
</select>
<input type="submit" value="Show" class="showDateBtn" />
</div>
</form>
See this fiddle as well!
https://jsfiddle.net/g6Ledf00/1/
Select element is a inline-block element, setting vertical-aling:top will align the element to the top,
here is some documentation
fiddle
.dwmViewSelect {
width: 80px;
height: 40px;
top: -10px;
font-weight: bold;
border: 1px solid white ;
margin: auto;
padding-top:unset 50px;
vertical-align: top;
}

Position a submit button inside div

Hi I am having some problems with the positioning of a submit button. I have posted the code below.
HTML
<div class="search">
<form action="post">
<input type="text" name="fname" placeholder="First name">
<input type="text" name="lname" placeholder="Last name">
<input type="submit" name="submit" value="Search">
</form>
</div>
CSS
.search {
position: absolute;
background-color: red;
width: 100%;
height: 30px;
}
input[type="text"] {
background-color: #f7f7f7;
height: 30px;
width: 280px;
color: #4D4C4C;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
padding: 0px 5px 0px 5px;
-webkit-box-sizing: border-box;
moz-box-sizing: border-box;
box-sizing: border-box;
border: 1px solid rgba(147, 184, 189,0.8);
}
input[type="submit"] {
font-family: 'Open Sans', sans-serif;
font-size: 13px;
height: 30px;
width: 100px;
}
Here is an image showing the output. My problem is that there is a small space above the submit button and I cant find out why since they both have height set to 30px . I want the button to have the same height as the .search div. Height: 100% does not seem to work.
http://i57.tinypic.com/atswm0.png
Try adding:
input[type="submit"] {
position: absolute;
}