IE CSS format tableless form with labels, inputs and selects - css

I am having trouble properly formatting CSS to display in IE the way I want it. It shows up in Firefox perfectly. I am trying to have it display the label and then next to it have the input or select box that is aligned and all the same size so it looks even. I know there are hacks for IE but none seem to be making a change. Example CSS and html code that I have and works in firefox is below. Any help would be great Thanks!
*CSS
fieldset {
border: none;
padding: 10px;
width: 600px;
margin-top: 5px;
}
label {
width: 140px;
padding-left: 20px;
margin: 5px;
float: left;
text-align: left;
}
input {
margin: 5px;
padding 0px;
float: left;
vertical-align: middle;
display: inline;
}
select {
margin: 1px 0px;
padding: 2px;
float: left;
display: inline;
width: 149px;
}
br {
clear: left;
}
*HTML
<fieldset>
<label>First Name:</lable>
<input type="text" value="first_name" /><br >
<label>Last Name:</lable>
<input type="text" value="last_name" /><br >
<label>User Role:</lable>
<select>
<option value=""></option>
<option value="admin">Admin</option>
<option value="basic">Basic</option>
</select>
</fieldset>

Fix your label tags and then try this css code:
fieldset {
border: none;
padding: 10px;
width: 600px;
margin-top: 5px;
}
label {
width: 140px;
margin: 5px;
display: block;
float: left;
}
input, select {
width: 150px;
margin: 5px;
float: left;
display: block;
}
br {
clear: both;
}
It works for me in IE, FF, Chrome, and Safari. Also, you might want to try using ordered lists to style your form elements.

Related

Aligning checkbox before text

I have a problem with the text after a checkbox. It is not aligned properly (the checkbox is too high) and since I am just starting to learn css and coding, I don't understand the solutions that were given to this problem on other sites. Here is an image of what it looks like right now and would appreciate any help on what to put in custom css in order to have the box properly aligned. Thank you!
https://www.dropbox.com/s/s46g9bb1u0ymrlf/checkbox.JPG?dl=0
.legal label input[type=checkbox] {
vertical-align: middle;
}
form .form-row .input-checkbox {
display: inline;
margin: -2px 8px 0 0;
text-align: center;
vertical-align: middle;
}
.checkbox input[type=checkbox], .checkbox-inline input[type=checkbox],
.radio input[type=radio], .radio-inline input[type=radio] {
float: left;
margin-left: -20px;
}
input[type=checkbox], input[type=radio] {
margin: 4px 0 0;
margin-top: 1px\9;
line-height: normal;
input[type=checkbox], input[type=radio] {
box-sizing: border-box;
padding: 0;
}
`
There can't be able to help without code
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
I have a car
Please check the below example

How to center a set of html radio buttons in a fieldset with div

I have a set of radio buttons and labels. The radio buttons precede the labels. I would like to center the set of them within a field set. I tried putting them in a div with display set to inline-block. Almost works, but one label gets bumped down to the next line.
My understanding was that giving a div display: inline-block would make it shrink-to-fit, but I'm getting the unexpected behavior you can see here (code below):
http://jsfiddle.net/abalter/TedVe/13/
Is my only hope to manually set margins and stuff? Is there a way to understand why the div is shrinking just a bit too much??
Update...
If I remove the right margin from the label (which is there to add space before the next radio button) then it fits. If, instead, I add margin-left to the button, I still have the problem.
<form>
<fieldset>
<legend>Test</legend>
<div>
<input class="radio-input" type="radio" name="test" value="yes" />
<label class="radio-label">Yes</label>
<input class="radio-input" type="radio" name="test" value="yes" />
<label class="radio-label">No</label>
<input class="radio-input" type="radio" name="test" value="yes" />
<label class="radio-label">Maybe</label>
</div>
</fieldset>
.radio-label {
float: left;
margin-right: 3%;
}
.radio-input {
float: left;
}
fieldset {
text-align: center;
}
div {
display: inline-block;
margin: auto;
border: 1px solid black;
}
Try this remove float left on your .radio-label and .radio-input and now define
display inline-block
As like this
.radio-label {
display: inline-block;
vertical-align: top;
margin-right: 3%;
}
.radio-input {
display: inline-block;
vertical-align: top;
}
Demo
Just remove all styles but text-align:center and you got it. No need to display: inline-block.
here's an updated fiddle:
http://jsfiddle.net/TedVe/8/
.radio-label {}
.radio-input {}
fieldset {
text-align: center;
}
div {}
use this following css.
.radio-label {
margin-right: 3%;
}
fieldset {
text-align: center;
}
div {
display:inline;
border: 1px solid black;
}
add width for div then your problem may fixed
.radio-label {
float: left;
margin-right: 3%;
}
.radio-input {
float: left;
}
fieldset {
text-align: center;
}
div {
display: inline-block;
margin: auto;
border: 1px solid black;
width:50%
}

alignment of inline-block div does not work

I'm trying to align a div containing only one select as shown below, but it does not work.
No matter what option I choose for vertical-align, nothing happens.
Below is the css for the div of class styled-select and the select inside.
div.styled-select {
width: 100px;
height: 17px;
overflow: hidden;
background: url(../../../../images/downarrow_blue.png) no-repeat right white;
display: inline-block;
position:relative;
float: left;
vertical-align: sub
}
.styled-select select {
background: transparent;
-webkit-appearance: none;
width: 117px;
height: 17px;
border: 0;
position: absolute;
left: 0;
top: 0;
}
// HTML code
<p/>
<form action="/prepareUpdateCategoryList.do?forwardto=search">
<fieldset class="block">
<label style="width:80px">Class</label>
<div class="styled-select">
<select>
<option value="0">Select </option>
<option value="7382">steam </option>
</select>
</div>
<input type="text" name="fname">
<input type="submit" value="Submit">
</fieldset>
</form>
if u just want it to align no matter how, then just use margin-top.
div.styled-select {
width: 100px;
height: 17px;
overflow: hidden;
background: url(../../../../images/downarrow_blue.png) no-repeat right white;
display: inline-block;
position:relative;
float: left;
vertical-align: sub;
margin-top:5px;
}
Fiddle here

how to position these CSS elements without defining height and width

I am trying to create a little graphical box for a time element on a website. What I would like to have is something like this:
I have this HTML:
<div class="entry-meta">
<time class="entry-date" datetime="2011-09-16T09:59:48+00:00" pubdate="">
<span class="date-day">16</span>
<span class="date-month">Sep</span>
<span class="date-year">2011</span>
</time>
</div>
And this CSS so far:
.entry-meta {
display: block;
color: white;
float: left;
background: #aaa;
}
.date-day {
display: block;
font-size: 30px;
background: #444;
float: left;
}
.date-month {
display: block;
font-size: 12px;
background: #666;
float: left;
}
.date-year {
display: block;
font-size: 12px;
background: #888;
float:left;
}
My problem is that I cannot achieve two things:
To align the text to the corners of the box and forget about the baseline. I would like to align 16 to the top left corner and cut it's box at the bottom right corner. I am looking for eliminating all the spacing pixels.
To move the year under the month, without specifying exact width and height properties. If I delete float: left then it goes under the day. What I would like to have is to move it right of the day and under the month. Do I need to create an other div or spand for the month + year?
Also, it seems that it doesn't matter if I remove display: block from the span CSS-es why is it?
Here is a jsFiddle I created:
http://jsfiddle.net/ESbqY/3/
An update one based on Kolink's suggestion:
http://jsfiddle.net/ESbqY/5/
Fully customizable:
http://jsfiddle.net/5MMc9/8/
html:
<div class="entry-meta">
<time class="entry-date" datetime="2011-09-16T09:59:48+00:00" pubdate="">
<div class="date-day">16</div>
<div class="container">
<div class="date-month">Sep</div>
<div class="date-year">2011</div>
</div>
</time>
</div>
css:
.entry-meta {position: relative; font-family: Trebuchet MS;}
.container {float: left;}
.date-day {font-size: 70px; line-height: 55px; float: left; background: #fa7d7d;}
.date-month {font-size: 25px; line-height: 25px; background: #627cc6; padding: 0 0 5px 0;}
.date-year {font-size: 25px; line-height: 25px; background: #3ce320;}
Furthermore, you can add display: inline-block; to the month css if you want the div to be same width as text inside.
The following:
<span style="font-size: 2em;">16</span><span style="display: inline-block;">Sep<br />2011</span>
Will produce, more or less exactly, the result shown in the image.
This seems to work as required:
time span {
display: block;
font-size: 1em;
margin-left: 2.5em;
}
time span.date-day {
float: left;
position: absolute;
font-size: 2em;
margin: 0;
}
.entry-meta {
border: 2px solid #ccc;
display: block;
float: left;
position: relative;
}
JS Fiddle demo.
Edited to amend/use the colours from the question, and to remove the (possibly unwanted) margin between the date-day and the other span elements:
time span {
display: block;
font-size: 1em;
margin-left: 2em;
}
time span.date-day {
float: left;
position: absolute;
font-size: 2em;
margin: 0;
background-color: #444;
}
time span.date-month {
background-color: #666;
}
time span.date-year {
background-color: #888;
}
.entry-meta {
border: 2px solid #ccc;
display: block;
float: left;
position: relative;
background-color: #ccc;
}
JS Fiddle demo.

Align child element to bottom with CSS

I have a form input, and the label spans multiple lines, and I want the corresponding checkbox to appear at the bottom (last line of the label element).
Here is what I was playing with
CSS
.standard-form {
width: 500px;
border: 1px solid red;
}
.standard-form .input-row {
overflow: hidden;
margin-bottom: 0.8em;
}
.standard-form label {
width: 25%;
float: left;
}
.standard-form .input-container {
width: 70%;
float: right;
}
.standard-form .checkbox .input-container {
display: table-cell;
height: 100%;
vertical-align: text-bottom;
}
HTML
<form class="standard-form">
<div class="input-row checkbox" id="permission">
<label for="input-permission">
Do I hereby grant you permission to do whatever tasks are neccessary to achieve an ideal outcome? </label>
<div class="input-container">
<input type="checkbox" id="input-permission" name="permission" value="true" /> </div>
</div>
</form>
It is also online at JSbin.
Is there any way to do this? I notice that div.input-container isn't expanding, which is the old multi column problem with CSS.
I thought I could get this going with display: table-cell and vertical-align: bottom but I haven't been able to do it yet. I don't mind that IE6/7 won't render it correctly.
I have also tried using a combination of position: relative; with the child position: absolute; bottom: 0; except then I need to specify a height which I can not guarantee will be the height of the label on the left.
See my changes in action: http://jsbin.com/ocovu/2/edit
Here are the relevant declarations:
.standard-form .input-row {
overflow: hidden;
margin-bottom: 0.8em;
position: relative;
}
.standard-form .checkbox .input-container {
position: absolute;
bottom:-2px;
left:25%;
}
Tried display: block?

Resources