How to fix IE7 float-clear combination - css

I have a field_wrapper class div which contains the 3 sub divs field_label, field_input and field_error
I need to put the field_label, field_input side by side and field_error below the first two.
Please see below css code to know how i achieved this, My problem is Its is not working in IE7. clear both applied to the field_error is not working.
Even after googling for a long time i can't find a proper method to fix this without adding the HTML mark-up. Please advice css tip or any other method to avoid extra markup code
.field_wrapper
{
clear:both;
}
.field_label
{
float:left;
width:40%;
}
.field_input
{
float:left;
width:40%;
}
.field_error
{
clear: both;
color:#FF0000;
float: right;
text-align:left;
width: 60%;
}
<form method="post" action="http://localhost/locations/add">
<div class="field_wrapper">
<div class="field_label">
<label for="location_add_name">Name</label>
</div>
<div class="field_input">
<input type="text" id="location_add_name" value="" name="name">
</div>
<div class="field_error">
<p>The Name field is required.</p>
</div>
</div>
<div class="field_wrapper">
<div class="field_label">
Address
</div>
<div class="field_input">
<textarea id="location_add_address" rows="12" cols="90" name="address"></textarea>
</div>
<div class="field_error">
</div>
</div>
<div class="form_submit">
<input type="submit" value="Add" name="submit">
</div>
</form>

If you do not want to remove the float left. You can use this wrapper code
.field_wrapper { display: inline-block; }
.field_wrapper:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
* html .field_wrapper { height: 1%; }
.field_wrapper{ display: block; }
It works for me every time (IE6 as well)
Update:
I looked at this again, and changed the markup a bit, also made it valid xhtml.
Just put the class on the P tag, you dont need an extra div.
.field_wrapper
{
clear:both;
}
.field_label
{
float:left;
width:40%;
}
.field_input
{
float:left;
width:40%;
}
.field_error
{
clear: both;
color:#f00;
width: 60%;
}
<form method="post" action="http://localhost/locations/add">
<div class="field_wrapper">
<div class="field_label">
<label for="location_add_name">Name</label>
</div>
<div class="field_input">
<input type="text" id="location_add_name" value="" name="name" />
<p class="field_error">The Name field is required.</p>
</div>
</div>
<div class="field_wrapper">
<div class="field_label">Address</div>
<div class="field_input">
<textarea id="location_add_address" rows="12" cols="90" name="address"></textarea>
</div>
</div>
<div class="form_submit">
<input type="submit" value="Add" name="submit" />
</div>
</form>

Remove float:right from 'field_error'

let me tell you one thing first. if you having floating content in a container the container never contain it untill and unless you set the container overflow property to hidden or also make it float you. like
.field_wrapper
{
clear:both;
overflow:hidden;
}
Now it contain all floating element. Now for your error div as you are floating you elements to left, so make clear:left only and it will work.
Thanks

Related

How to place two DOM elements on the same line

I am trying to put on the same line $('.prize-item input') and $('.prize-edit')
Here is the DOM structure (1) and the CSS code (2).
I tried to sue the display:inline-block with no success.
The prerequisite is the following:
1) You must not use position absolute.
2) Resizing the screen, the distance between the button and the input box should not change.
3) The DOM structure should be changed only if it is not possible to obtain the result I requested with CSS.
Demo: http://jsfiddle.net/jBme9/8/
(1)
<div class="control-group">
<div class="controls">
<div class="prize-edit">
<button type="button" class="btn" data-toggle="collapse" data-target="">Edit Same line</button>
</div>
<div class="prize-item">
<div class="control-group ">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" class="form-prize-item-name" value="prize same line">
</div>
</div>
</div>
</div>
</div>
​
(2)
.prize-edit {
float: right;
display: inline-block;
}
.prize-item input {
float: left;
display: inline-block;
}
You can use relative positioning. Please adjust these values for your real page.
Demo
Code:
.controls button {
float: right;
position:relative;
top:38px;
right:17px;
}
I used pixels 'cause you're using pixels, but this can be done with ems too.
To push the button outside the input, add another class to the input's wrapper. Let's call it "controlsWrapper".
So that you'll have in html:
<div class="controls controlsWrapper"><input...other stuff...></div>
And in CSS
.controls button {
float: right;
position:relative;
top:38px;
}
.controlsWrapper {
box-sizing: border-box;
width:100%;
padding-right:40px; /* width of the button + some space */
}
Check the demo
I think it´s not possible with this DOM structure. You want to have something like this:
<div class="aWrapper">
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<div class="prize-edit">
<button type="button" class="btn" data-toggle="collapse" data-target="">Edit Same line</button>
</div>
<div class="prize-input"><!-- I renamed the class! -->
<input type="text" class="form-prize-item-name" value="prize same line">
</div>
</div>
</div>
</div>
additional:
.label { diplay: block; }
.prize-edit { float: right; width: 20%; // adjust with paddings etc. }
.prize-input { float: left; width: 80% // adjust ... }

Using column divs with the line-height attribute to align textboxes with their labels

I have aligned textboxes with their labels using the line-height method proposed here. I didn't simply use the width attribute because I wanted it to dynamically adjust if the label text changed. To get Firefox (haven't tried other browsers) to apply the line height to the column with the inputs, I had to use this hack (note the <div class="hack">):
HTML
<div class="textbox-column label">
<div>User Name:</div>
<div>Password:</div>
</div>
<div class="textbox-column input">
<div><div class="hack">#</div><input type="textbox" name="username" /></div>
<div><div class="hack">#</div><input type="password" name="password" /></div>
</div>
<div class="clear"></div>
CSS
div.clear {
clear: both;
}
.textbox-column {
line-height:1.6em;
}
.textbox-column.label {
float: left;
margin-right:1em;
}
.textbox-column.input {
float: right;
}
.textbox-column .hack {
display: inline;
width: 1em;
margin-right: -1em;
}
Can any one suggest a cleaner solution?
Here is a live demo of this code: http://jsfiddle.net/fbe7P/
CSS works best when things are grouped together, so I would group the controls into rows.
Also, the plus side of this method is that it degrades well for small screen sizes.
HTML:
<div class="row">
<label for="username">Username:</label>
<input type="text" id="username" />
</div>
<div class="row">
<label for="password">Password:</label>
<input type="password" id="password" />
</div>​
CSS:
.row {
overflow: auto;
}
.row label {
float: left;
min-width: 100px;
}
.row input {
float: right;
}
Demo: http://jsfiddle.net/ezp9H/2/

OL numbering in chrome not left-aligning, appearing on the right

I'm experiencing some strange behavior with OL numbering in Chrome, here's my markup:
<ol>
<li>
<div class="block left">
<span class="block">Main Title<span class="alert">!</span></span>
<input type='text' name='title-1' />
</div>
<div class="block left">
<span class="block">Subtitle<span class="alert">!</span></span>
<input type='text' name='title-2' />
</div>
<div class="block left">
<span class="block">Add Image<span class="alert">!</span></span>
<input type='file' name='image' size='30' />
</div>
</li>
<ol>
The classes used are:
.block { display:block; }
.left { float:left; }
.alert { color:red; }
The problem I'm having is that I need the number of my OL to appear to the LEFT of the LI's contents, but Chrome seems to attribute some kind of float property to the numbers, making it appear on the right.
Can anyone provide any assistance on this matter? Thanks in advance.
ol li { margin-left: 60px; list-style-type: decimal; }
will make the numbers visible.
Wrapping the tags inside li-elements with <div class="wrap"> and apply this css to it:
.wrap { display: inline-block; position: relative; top: 12px; }
will fix your problem --> http://jsfiddle.net/GpfYk/2/
position: relative; top: 12px; makes the position nicer.
The problem is that you have a span with a class of "block" inside the li, and both are being floated. If you remove the class of block from the span, it should fix the issue.
Or, if you wish to keep the elements inline, try setting them to display: inline-block and remove the "left" class to float them as in this example: http://jsfiddle.net/jglovier/zshPr/

divs not properly aligned side by side

I have 3 divs placed side by side in my application , and after the divs , I have kept a submit button.
This is how the Submit button looks if I select 'today' in date options :
but if I choose specific dates , this is what happens :
This is how the code looks like :
<div class="filters clearfix" style="float:left" id="sel_filters">
<div class="fields">
<div class="10">
<!-- this is for the date option . it contains a label and select element-->
</div>
<div>
<!-- label for start date and an input box -->
</div>
<div>
<!-- label for end date and an input box -->
</div>
<div>
<!-- label for adnetwork options " " and the select element -->
</div>
<input id="startdate_hidden" type="hidden" style="display:none;" value="" name="data[Fam][startdate_hidden]">
<input id="enddate_hidden" type="hidden" style="display:none;" value="" name="data[Fam][enddate_hidden]">
<input id="submit" class="stdButton" type="submit" onclick="return updateAddetailsNetworkWiseReport();" value="Submit" name="submit">
</div>
</div>
Now the styles :
.clearfix:after
{
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
}
div#sel_filters
{
margin-left: 10px;
width: 754px;
}
div.filters div.fields
{
background: url("/img/bg_summary.gif") no-repeat scroll right bottom #FFFFFF;
height: 38px;
padding-right: 10px;
}
div#sel_filters div.fields div.l0
{
margin-left: 0;
}
I added style="float:left" to the outermost div , but this problem persists . What's the exact solution would be?
To me it looks like on the bottom image two images are appearing next to the date boxes and this is causing the elements to be to wide for the containing div.
Try resizing some of the elements to make them smaller by 20-30px or; make the containing divisions width bigger, this should hopefully work.
instead float you can use display:inline-block for this with white-space property. Like this:
CSS:
.parent{
white-space:nowrap;
}
.child{
background:red;
margin:10px;
width:150px;
height:100px;
white-space:normal;
display:inline-block;
*display:inline /*IE7*/
*zoom:1;
}
HTML
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
http://jsfiddle.net/amhWX/

css - have two inline inputs take up remaining space

I have the following html:
<div id="holder">
<span>Search for</span>
<input id="srchfor" />
<span>near</span>
<input id="srchin" />
<span>submit</span>
</div>
The containing div is fixed width. The width of the 3 spans will depend on font size. Is it possible to make the two inputs take a width so that they are both equally sized, and they consume all the remaining space in holder? Or does this require using javascript?
Edit: My aim is to have the 5 elements all on one line, rather than split over several lines.
This is an old post but I came across it and figured I would answer it for the next person. Here is a CSS/HTML snippet that should resolve this issue. It is kind of like a HTML5 flexbox but without HTML5 or a flexbox. You can add width to whatever 2 sections needed and the third will fill the remaining void.
<style type="text/css">
.form-group {
border: 1px solid black;
margin-bottom: 20px;
padding: 10px;
width: 75%;
}
.a {
float: right;
margin-left: 10px;
width: 30%;
}
.a input {
width: 100%;
}
.b {
float: left;
margin-right: 10px;
width: 33%;
}
.b input {
width: 100%;
}
.c {
display: block;
overflow: hidden;
}
.c input {
width: 100%;
}
</style>
<div id="wrapper">
<div class="form-group">
<span class="a">
<label>Thing 1</label><br />
<input type="text" />
</span>
<span class="b">
<label>Thing 2</label><br />
<input type="text" />
</span>
<span class="c">
<label>Thing 3</label><br>
<input type="text" />
</span>
</div>
<div class="form-group">
<div class="a">
<label>Thing 1</label><br />
<input type="text" />
</div>
<div class="b">
<label>Thing 2</label><br />
<input type="text" />
</div>
<div class="c">
<label>Thing 3</label><br>
<input type="text" />
</div>
</div>
</div>
Well, you could change the display type from display: inline to display: block to make them fill space. But I don't know if the inline is an requirement.
You have to choose a fixed width for the span elements, and use the display:inline-block property like in this example.

Resources