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 ... }
Related
I'm using bootstrap's class
<div class="btn-group btn-group-justified">
Buttons are perfect the way they are (I need them equally spaced and taking full length) but I would like a little space between them. I tried playing around with margins, width percentage and padding with no success.
Please see this codepen http://codepen.io/crhistian/pen/WwyWYM?editors=0100
HTML
<div class="panel-footer">
<div class="row">
<div class="col-xs-2">
<div class="row custom-row">
<div class="col-md-6">
<button class="btn btn-info btn-block">Cart</button>
</div>
<div class="col-md-6">
<button class="btn btn-success btn-block">Checkout</button>
</div>
</div>
</div>
</div>
</div>
CSS
.custom-row {
margin-left: -5px;
margin-right: -5px;
}
.custom-row .col-md-6 {
padding-left: 5px;
padding-right: 5px;
}
For the first button in the div tag
.btn-group {
float: left;
width: 45%;
}
And for your other button (add "2" to the other buttons div tag class):
.btn-group2 {
float: right;
width: 45%;
}
Then you can add margins for the same classes if you want to position them better
This is what I wish to achieve: display a message next to an input box.
However, when the message is too long the whole thing goes under the input box.
css
.data-form{
display: block;
box-sizing: border-box;
line-height: 22.8px;
}
.data {
box-sizing: border-box;
display: inline-block;
}
.form-group {
margin-bottom: 15px;
// box-sizing: border-box;
}
.data-status {
display: inline-block;
color: red;
word-wrap:break-word;
}
.data-label {
display: inline-block;
}
.form-control {
width:200px;
font-size: 16px;
}
html markup
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
<form class='data-form'>
<div class='data form-group row'>
<label class='data-label'>
<span> Add a data code </span>
<input type='text' name='data' class='form-control'>
<div class='data-status'>
<span class='data-status'>TEST </span>
</div>
</label>
</div>
</form>
</div>
I want to keep the whole error message to the right hand side of the input regardless of the length of error text
I have tried
'break-word'
various different structure such as moving the message inside a div which sits at the same level of label.
Unfortunately they do not work.
Here is the code that demonstrated the problem
http://jsfiddle.net/kongakong/o338t791/3/
Any suggestion? It uses bootstrap css
Just change the .data-status rule to this to remove the inline-block:
.data-status {
color: red;
word-wrap:break-word;
}
Here is a fiddle which shows it in action
The inline-block rule is whats forcing the element to remain in a single line. You can also change it to display:inline; but this is the default rule for a span element.
do some changes in your html code as
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
<form class="data-form">
<div class="data form-group row">
<label class="data-label">
<div> Add a data code </div>
<div class="data-status">
<input class="form-control" type="text" name="data">
</div>
<span class="data-status">TEST TEST TEST TEST TEST </span>
</label>
</div>
</form>
</div>
and in your stysheet put
.data-status
{
vertical-align: middle;
}
In the form-control, add a display-inline.
.form-control {
width:200px;
font-size: 16px;
display:inline;
}
Data status as,
.data-status {
display: inline;
color: red;
word-wrap: break-word;
}
Default comes with form-control is display:block.
This will make span and input inline. Wrap the "Add a data code" within a div.
Here is the complete html and css,
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
<form class='data-form'>
<div class='data form-group row'>
<label class='data-label'>
<div>
<span> Add a data code </span>
</div>
<input type='text' name='data' class='form-control'>
<div class='data-status'>
<span class='data-status'>TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST</span>
</div>
</label>
</div>
</form>
</div>
CSS;
.data-form{
display: block;
box-sizing: border-box;
line-height: 22.8px;
}
.data {
box-sizing: border-box;
display: inline-block;
}
.form-group {
margin-bottom: 15px;
box-sizing: border-box;
}
.data-status {
display: inline;
color: red;
word-wrap:break-word;
}
.data-label {
display: inline-block;
}
.form-control {
width:200px;
font-size: 16px;
display:inline;
}
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/
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/
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