Align instructions div tag under textbox - html

All,
I have the following code:
http://jsfiddle.net/k2AMG/7/
I am trying to avoid fixed widths in the CSS and align the divs in this fashion, but am not able to do so:
Your name Textbox
Please check the name
Work email Textbox
Email should have a valid format
Job title Textbox
Job title should have only alphabets
Any help is appreciated. Thanks

Try it like this:
http://jsfiddle.net/andresilich/k2AMG/11/
::Edit:: fixed demo
::Edit 2:: added CSS and HTML to post for future reference
CSS
.data_item{
margin-bottom: 20px;
display: block;
}
label
{
width: 100px;
display:inline-block;
}
.left {
display:inline-block;
margin-right:5px;
}
.right {
display:inline-block;
vertical-align:top;
}
.right span span {
display:list-item;
list-style-type:none;
}
Clarification: created two classes to separate the two sides, .left and .right, and added a style to the span of the .instructions div to display as a list-item (so they can displace like a regular html list would, why? Because it is a clean, responsive drop that displaces naturally without the need to add margin or padding that might displace with any other element around and thus less maintenance.).
HTML
<div class="data_item">
<div class="left">
<label> Your name </label>
</div>
<div class="right">
<span>
<input type="text" />
<span class="instructions">Please check the name</span>
</span>
</div>
</div>
<div class="data_item">
<div class="left">
<label> Work email </label>
</div>
<div class="right">
<span class="item">
<input type="text" />
<span class="instructions">Email should have a valid format</span>
</span>
</div>
</div>
<div class="data_item">
<div class="left">
<label> Job title </label>
</div>
<div class="right">
<span class="item">
<input type="text" />
<span class="instructions">Job title should have only alphabets</span>
</span>
</div>
</div>

Try this: http://jsfiddle.net/k2AMG/9/

Related

show no-parent div on click on another div, pure css possible?

I want to split my site in two vertical sections. If you click on a left button (width:50%), the content for this button should appear below with width:100% and if you click on the right button the same but of course with content 2.
Is it even possible with pure css? Because I don't know java :/ and I think it's a quite simple problem, isn't it?
#content_button_left,
content_button_right {
display: none
}
#button_left:active~#content_button_left {
display: inherit
}
#button_right:active~#content_button_right {
display: inherit
}
<div>
<div style="display:flex">
<div id="button_left" style="flex:1">Menu left</div>
<div id="button_right" style="flex:1">Menu right</div>
</div>
<div id="content_button_left" style="width:100%">
blabla 1
</div>
<div id="content_button_right" style="width:100%">
blabla 2
</div>
</div>
You can use :target CSS selector to fake the click event but for that you have to convert your div to anchor tag, below is CSS
#content_button_left, #content_button_right{
display:none
}
#content_button_left:target {
display:block;
}
#content_button_right:target{
display:block;
}
Updated HTML
<div style="display:flex">
<a id="button_left" href="#content_button_left" style="flex:1">Menu left</a>
<a id="button_right" href="#content_button_right" style="flex:1">Menu right</a>
</div>
<div id="content_button_left" style="width:100%">
blabla 1
</div>
<div id="content_button_right" style="width:100%">
blabla 2
</div>
I would use radio buttons next to the content and labels for your button targeting the radios. This way you can use the adjacent sibling selector to only show the content next to a checked radio:
/* hide radio and content */
.radio,
.content {
display: none;
}
/* show content if it directly follows a checked radio */
.radio:checked + .content {
display: block;
}
<div>
<div style="display:flex">
<label id="button_left" style="flex:1" for="left-input">Menu left</label>
<label id="button_right" style="flex:1" for="right-input">Menu right</label>
</div>
<input type="radio" name="show-content-radio" id="left-input" class="radio">
<div id="content_button_left" style="width:100%" class="content">
blabla 1
</div>
<input type="radio" name="show-content-radio" id="right-input" class="radio">
<div id="content_button_right" style="width:100%" class="content">
blabla 2
</div>
</div>

Fill the remaining space with CSS

I have the following html (JSFiddle):
<div id="container">
<div>
<label>Simple label
<input>
</label>
</div>
<div>
<label>Other label
<input>
</label>
</div>
<div>
<label>Variable label
<input>
</label>
</div>
</div>
Is it possible with CSS (I don't want to use JavaScript for this), to fill the remaining space with the inputs? I have variable label length, and I want to align the right side of the input's without float: right (but not to bother also the left alignment).
You can make the label a flex parent and set the input to flex-grow: 1
#container div {
margin: 10px 0;
width: 300px;
}
input {
flex-grow: 1;
}
label {
display: flex;
}
<div id="container">
<div>
<label>Simple label
<input>
</label>
</div>
<div>
<label>Other label
<input>
</label>
</div>
<div>
<label>Variable label
<input>
</label>
</div>
</div>

Make Html Label show on right side of Div element

I have a DIV element:
<div style="background-color:red">This is a test
<label>ID:</label>
<asp:TextBox runat="server"><asp:Textbox>
</div>
I need to show "This is a test" on left side but the Label and Textbox on the right side of the side.
I tried
margin:right 0px;
but this did not help.
Also tried Float:right but this created strange results.
Add a div to wrap the label and input, and use float:
.input-group {
float: right;
}
<div style="background-color:red">This is a test
<div class="input-group">
<label>ID:</label>
<input type="text" />
</div>
</div>
You can try using float:right; in your style:
<div style="background-color:red">This is a test
<div style="float:right">
<label>ID:</label>
<asp:TextBox runat="server"><asp:Textbox>
</div>
</div>

input/button display:table-cell/width:100% do not fill remaining space in table

I'm styling an input group <div> wrapper as display:table; with all contents display:table-cell; When I want to have a fixed width on the table, if the cell I want to widen/shorten to take up the remainder width is a <span> element or a <ul> element, for example, then setting width:100%; works. However, if the element is an <input> or <button> then this does not work in firefox or chrome (but does in IE) and the result is the element takes up the entire space of the input group, pushing the next element down to a new row. I can get around this by putting the <input> or <button> inside a <span> element and setting width:100%; on both, but I'd rather have a css solution.
<div class="input-group wide">
<input type="text" style="width:100%;"></input>
<button>S</button>
</div>
css:
.input-group {
display:inline-table;
padding:0px;
background-color: grey;
}
.input-group > input, .input-group > button, .input-group > span, .input-group > ul {
display: table-cell;
margin:0px;
}
.wide {
width: 260px;
}
http://jsfiddle.net/5v3Lg50d/3/
Floats are good idea, you can follow Epik's solution.
I checked one thing with Firebug for Firefox and I learned that <button> works fine with its parent div having style="display: inline-flex".
You might want to check this against other browsers and use it conditionally, or go with floats instead.
I have a JS fiddle here with the changes made.
http://jsfiddle.net/5v3Lg50d/4/
Basically i changed a few small things and tidied up your fiddle. The elements you wanted full width i added in a class and floated left;
.fullWidth {
width:100%;
display:inline-block;
float:left;
}
The following is the code i amended:
<div class="input-group wide" style="">
<span class="fullWidth">space</span>
<button>S</button>
</div>
<br />
<br />
<div class="input-group wide" style="">
<ul class="fullWidth"><li>o1</li><li>o2</li></ul>
<button>S</button>
</div>
<br />
<br />
<div class="input-group wide" style="">
<input type="text" class="fullWidth"></input>
<button>S</button>
</div>
<br />
<br />
<div class="input-group wide">
<span><input class="fullWidth"></input></span>
<button class="fullWidth">S</button>
</div>
<br />
<br />
<div class="input-group wide">
<button class="fullWidth">A button</button>
<button>S</button>
</div>
<br />
<br />
<div class="input-group wide" style="">
<span><button class="fullWidth">A button</button></span>
<button>S</button>
</div>
Hope this helps.
-Epik

CSS: Why don't these two div (or span) elements float next to each other

In the following code, I need the div elements #ldiv and #rdiv to be placed next to each other.
So I am using the CSS float property. I looked up this answer, and I think I am following it, but still the div's won't position next to each other. The second div displays in the next line.
Then I thought that div is a block level element, so I replaced the div by span elements. But that did not help either.
JSFiddle here.
<div style="padding:25px; width:400px;">
<div style="background-color:#bf5b5b;">
<span>Yes</span>
<span>No</span></div>
<div id="option_one_div">
<div id="ldiv" style="float:left; background-color:#74d4dd; width:150px;">
<label for="rbutton_radio_1_0" style="margin-left:30px; margin-right:30px;">
<input for="rbutton_radio_1_0" type="radio" name="radio" value="0"/></label>
<label for="rbutton_radio_1_1" style="margin-left:30px; margin-right:30px;">
<input for="rbutton_radio_1_1" type="radio" name="radio" value="1"/></label>
</div>
<div id="rdiv" style="float:right; background-color:#74d4dd; margin-left:151px; padding-left: 20px; padding-right: 20px">
<span>Label of first group of Radio Buttons radio buttons.</span>
</div>
</div>
</div>
In your situation you can use display:table in container(#option_one_div) in your example and display:table-cell in children elements(#ldiv, #rdiv) like this:
<div style="padding:25px; width:400px;">
<div style="background-color:#bf5b5b;">
<span>Yes</span>
<span>No</span></div>
<div id="option_one_div" style="display: table;">
<div id="ldiv" style="background-color:#74d4dd; width:150px;display:table-cell;">
<label for="rbutton_radio_1_0" style="margin-left:30px; margin-right:30px;">
<input for="rbutton_radio_1_0" type="radio" name="radio" value="0"/></label>
<label for="rbutton_radio_1_1" style="margin-left:30px; margin-right:30px;">
<input for="rbutton_radio_1_1" type="radio" name="radio" value="1"/></label>
</div>
<div id="rdiv" style="display:table-cell; background-color:#74d4dd; margin-left:151px; padding-left: 20px; padding-right: 20px">
<span>Label of first group of Radio Buttons radio buttons.</span>
</div>
</div>
</div>
fiddle
As you can see you don't need floats.
use width with float in div
<div id="rdiv" style="float:right; background-color: #74d4dd; /* margin-left: 151px; */ padding-left: 20px; width: 210px;padding-right: 20px">
<span>Label of first group of Radio Buttons radio buttons.</span>
</div>
plz check
the total width of the elements (incl. margin/border) can not be greater than the surrounding divs width of 400px else the floating elements will be put into the next line ... see akz's answer for a quick fix
Just remove float:right. It will work.
<div id="rdiv" style="background-color:#74d4dd; margin-left:151px; padding-left: 20px; padding-right: 20px">
DEMO
the main problem is you didn't add width to the id="rdiv" and used margin-left:151px
when you use some element with float, you have to add its width
<div>
<div style="float: left;width: 110px;height: 90px;margin: 5px;">a</div>
<div style="float: left;width: 110px;height: 90px;margin: 5px;">b</div>
<div style="float: left;width: 110px;height: 90px;margin: 5px;">c</div>
</div>
to solve the problem, you can do one of the following things:
1: change your code to:(notice you set margin-left:151px; in th id="rdiv" and I changed it to lower value)
<div id="rdiv" style="float:right; background-color:#74d4dd; margin-left:15px; padding-left: 20px; padding-right: 20px; width:50px;">
2: remove your float=right in the id="rdiv" so the id="ldiv" could be in the float version of this element