div and textboxes are not aligning at same position when text change - css

Few hour ago I have asked question that for to align 2 text boxes in line.
But now problem is text boxes are aligned and I have put select list in side of each text box.
but problem is that when I change the label or text before text box all formation disturbed and it's not aligning in same format.
I want that whatever the text I write before text box, the position of text box should not change. (ONE TEXT BOX SHOULD BE AT SAME POSITION UNDER ANOTHER ONE)
fiddle demo
code :
.divkl {
display: inline;
margin: 20px;
}
.blockl{
width: 100%;
display: block;
padding:3px;
}
.txt_prd_add
{
width:100px;
border-radius:0px !important;
margin-left:10px;
margin-top:4px;
}
.select_prd
{
width:85px;
margin-top:4px;
}

Wrap all of the labels in <label></label> and then apply a fixed width and display: inline-block to the label via CSS. If you want to prevent the elements from wrapping when the browser is resized add white-space: nowrap; to .block1 and .divk1
HTML
<div class="blockl">
<div class="divkl">
<label>Material</label>
<input type="text" class="txt_prd_add">
<select class="select_prd">
<option>GB</option>
<option>MB</option>
<option>GHz</option>
</select>
</div>
<div class="divkl">
<label>Color</label>
<input type="text" class="txt_prd_add">
<select class="select_prd">
<option>GB</option>
<option>MB</option>
<option>GHz</option>
</select>
</div>
</div>
<div class="blockl">
<div class="divkl">
<label>Size</label>
<input type="text" class="txt_prd_add">
<select class="select_prd">
<option>GB</option>
<option>MB</option>
<option>GHz</option>
</select>
</div>
<div class="divkl">
<label>Type</label>
<input type="text" class="txt_prd_add">
<select class="select_prd">
<option>GB</option>
<option>MB</option>
<option>GHz</option>
</select>
</div>
</div>
CSS
label{
width: 50px;
display: inline-block;
}
.divkl {
display: inline;
margin: 20px;
white-space: nowrap; /* Prevents wrapping */
}
.blockl{
width: 100%;
display: block;
padding:3px;
white-space: nowrap; /* Prevents wrapping */
}
JS Fiddle: http://jsfiddle.net/u7aTD/7/

DEMO
<label class="title">Material</label>
.title {
display: inline-block;
width: 80px;
}

Demo: http://jsfiddle.net/abhitalks/u7aTD/6/
You would better wrap your text in labels, e.g.:
<div class="divkl">
<label>Material</label>
<input type="text" class="txt_prd_add">
...
And, then apply css to the labels, e.g.:
label { display: inline-block; width: 10%; }
.txt_prd_add { width:10%; ...
.select_prd { width:10%; ...
The problem you are having is with the widths. It would be better if you first apply widths in percentages to check it out, and then tweak it according to your design.

You can use tables insted of divs , as to get proper aling.`
Material
GB
MB
GHz
Color
GB
MB
GHz
<tr class="divkl"><td>Size</td>
<td>
<input type="text" class="txt_prd_add">
<select class="select_prd">
<option>GB</option>
<option>MB</option>
<option>GHz</option>
</select>
</td>
</tr>
<tr class="divkl">
<td>Type</td>
<td>
<input type="text" class="txt_prd_add">
<select class="select_prd">
<option>GB</option>
<option>MB</option>
<option>GHz</option>
</select>
</td>
</tr>
</table>
</div>`

Related

Align a label and two DIVs horizontally with CSS

I have this form, that I can't edit:
<body>
<form action="" method="post" class="adverts-form adverts-form-aligned">
<fieldset>
<div class="adverts-control-group adverts-field-text adverts-field-name-adverts_eventLength ">
<label for="adverts_eventLength">Durata evenimentului</label>
<span class="ui-spinner ui-corner-all ui-widget ui-widget-content">
<input name="adverts_eventLength" id="adverts_eventLength" aria-valuemin="1" aria-valuemax="999" autocomplete="off" class="ui-spinner-input" role="spinbutton" type="text">
</span>
</div>
<div class="adverts-control-group adverts-field-select adverts-field-name-adverts_eventUnits ">
<label for="adverts_eventUnits"> </label>
<select id="adverts_eventUnits" name="adverts_eventUnits" style="">
<option value="zile">zile</option>
<option value="săptămâni">săptămâni</option>
<option value="luni">luni</option>
<option value="ani">ani</option>
</select>
</div>
</fieldset>
</form>
</body>
I want to align inline horizontally the two form DIVs, but keeping the position and the width of the first DIV label unchanged. Is there a way to do this with CSS?
This is the working (solved) solution: https://jsfiddle.net/iuriemalai/cp7kvLrw/32/
You can just float it.
.adverts-form-aligned .adverts-control-group > label {
float:left;
width: 30%;
}
.adverts-form input[type="text"] {
width: 60%;
float:left;
}
Make it like
.adverts-form-aligned .adverts-control-group > label {
display: inline-block;
width: 30%;
}
.adverts-control-group {
float: left;
}
.adverts-form input[type="text"] {
width: 60%;
}
This is the CSS code that helped to solve my problem:
body .adverts-form.adverts-form-aligned .adverts-field-name-adverts_eventLength {
overflow: initial;
}
.adverts-form.adverts-form-aligned .adverts-control-group.adverts-field-text.adverts-field-name-adverts_eventLength label,
.adverts-form.adverts-form-aligned .adverts-field-name-adverts_eventLength .ui-widget.ui-widget-content {
float: left;
}
body .adverts-form.adverts-form-aligned .adverts-field-name-adverts_eventUnits {
clear: initial;
}
body .adverts-form .adverts-field-name-adverts_eventUnits > label {
display: none;
}
body .adverts-form .adverts-field-name-adverts_eventUnits > #adverts_eventUnits {
width: 112px;
}

Vertical center label with text area and with select and with textbox

I have horizontally side by side: labels and text areas; labels and select. I would like to have it such that:
The select input is vertically centered with the label for that select. Say for example the select label takes up 5 lines then the select should be lined up so it appears to be on the same vertical level as teh 3rd line in the label side by side. If the label text is one line high then the label and the select are vertically on the same level. If the label text is 2 lines high then the select should appear to be on a level between the two lines.
For text areas the label text is vertically centred with the text area and the text area is vertically centered with the label. Say the text area is 5 lines high and the label is one line hight then the label should appear to be level with the 3rd line in the text area. Say the text area is 2 lines high and the label is 4 lines high then the text area should line level with the middle 2 lines in the label.
For text box similar to item 1, with the text box lining up with middle line in the label.
HTML
<div class="fieldSet"><fieldset>
<p>
<label class="field" for="name">Name:</label>
<input id="name" type="text" name="name" class="textbox" >
</p>
<p>
<label class="field" for="life">Life Number:</label>
<input id="life" type="text" name="life" class="textbox" style="width:85px;">
<label class="field" for="annual">Annual Blah Blah Blah Blah Blah Blah Blah Blah Blah Number:</label>
<input id="annual" type="text" name="annual" class="textbox" style="width:85px;">
<label class="field" for="maleFemale" style="width:125px;">M/F:</label>
<input id="maleFemale" type="text" name="maleFemale" class="textbox" style="width:40px;">
</p>
<p>
<label class="field" for="runYesNo">Running, Yes/No?:</label>
<select name="runYesNo" id="runYesNo">
<option value="?" selected>Yes/No?</option>
<option value= "Yes">Yes</option>
<option value= "No">No</option>
</select>
</p>
<p>
<label class="field" for="predMins">Predicted 5km blah blah blah blah blah blah:</label>
<input id="predMins" type="text" name="predMins" class="textbox" style="width:85px;">
<label class="field" for="predSecs">Seconds:</label>
<input id="predSecs" type="text" name="predSecs" class="textbox" style="width:85px;">
</p>
<p>
<label class="field" for="helpOut">Blah Blah Blah Blah are you Available to Assist / Help Out / Officiate / Steward on the Night?, Yes/No:</label>
<select name="helpOut" id="helpOut">
<option value="?" selected>Yes/No</option>
<option value= "Yes">Yes</option>
<option value= "No">No</option>
</select>
</p>
<p>
<label class="field" for="comments">Comments:</label>
<textarea id="comments" name="comments" ROWS=10 WRAP="SOFT" >Comments go here.......</textarea>
</p>
</fieldset></div>
CSS
form{
display: block;
width:800px;
margin-left: auto;
margin-right: auto;
text-align: center;
padding:0;
}
div.fieldSet {
width:798px;
margin-left: auto;
margin-right: auto;
}
fieldset{
border: none;
margin: 0px 0px 0px 0px;
padding: 0px 0px 15px 0px;
}
legend{
width: 100%;
padding: 0px;
text-align: center;
}
label.field{
text-align: right;
width: 190px;
float:left;
vertical-align: middle;
}
input.textbox{
width: 560px;
float: left;
height: 25px;
vertical-align: middle;
}
fieldset p{
clear: both;
vertical-align: middle;
text-align : left;
}
textarea {
width:560px;
}
select {
width:270px;
display:block;
float: left;
}
I would appreciate advise on how to achieve the layout that I am looking for.
Thank you for reading this.
Try this >>>>>>>Better-vertical-Alignment
css
label.field{
text-align: right;
width: 190px;
float:left;
vertical-align: middle;
line-height:25px;
}
so for the vertical alignment play with line-height:25px with vertical-align:middle!

How to align label to top?

jsfiddle
Without modifying the html, how can I align it's label to top like in the picture:
<div class="col">
<label for="foo">Select:</label>
<select id="foo" name="select">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<div class="col">
<label for="bar">Select any of the following:</label>
<select id="bar" name="select">
<option value="11">11</option>
<option value="22">22</option>
</select>
</div>
I can align label to the top and select to the bottom if it was in two div blocks using vertical-align, but I wanted to know without modifying the html code how can I align the label to the top and select to the bottom?
Use Display: Table-cell to make both columns have the same height:
div.col {
display: table-cell;
border: 1px solid blue;
font-size: 300%;
width: 300px;
position: relative;
padding-bottom: 40px; /* Space for the 'select'*/
}
select {
position: absolute;
bottom: 0;
left: 0;
}
Demo: (Tested in Chrome) http://jsfiddle.net/cM6Yp/

Aligning submit button and textfields with css

I have a form where I gave the textfields a padding so it will be a bit bigger and nicer. Underneath the form I have a submit button.
The button and the textfields have a width of 100%, but the problem is, is that the button isn't fully 100% by that it isn't equally even in the width with the textfields. What am I doing wrong? Can't seem to "find" the issue
I have put it here http://jsfiddle.net/zrhB6/3/
The Css
input[type=text],input[type=password]{
display: block;
height: 3em;
width: 100%;
}
.btn {
background-color:#c1d82f;
border:3px solid #97a34b;
display:inline-block;
color:#26328c;
font-family:Verdana;
font-size:20px;
font-weight:bold;
padding:6px 24px;
text-decoration:none;
cursor: pointer;
width: 100%;
}
HTML
<div class="grid-container">
<div class="grid-50 login">
<h3>Login</h3>
<form class="grid-100">
<input type="text" name="loginEmail" placeholder="Email"/>
<input type="password" name="loginPassword" placeholder="pass"/>
<input type="submit" name="loginSubmit" class="btn"/>
</div>
<div class="grid-50 login">
<h3>Register</h3>
<form">
<input type="text" name="registerName" placeholder="Name"/>
<input type="text" name="registerEmail" placeholder="Email"/>
<input type="password" name="registerPassword" placeholder="pass"/>
<input type="submit" name="registerSubmit" class="btn"/>
</div>
</div>
I'm using unSemantic grid, but that shouldn't be a issue I think
To both CSS selectors, add:
box-sizing:border-box;
The reason is the default box sizing doesn't include padding and margins in the width, so you're getting 100% + padding + border + margin for the total width.

CSS Positioning: A row of floating left, followed by a block underneath

I want a row of blocks from left to right, followed by a block underneath.
Here is a picture of what I would like to see rendered in the browser.
I need to do all positioning by CSS, not by tables. Here is my HTML and my CSS...
<!DOCTYPE html>
<html>
<head><link rel="stylesheet" href="demo.css" /><head>
<body>
<form action="">
<fieldset>
<legend>Field set A</legend>
<label for="password">Password
<input id="password" name="password" type="text" value="my password" />
</label>
</fieldset>
<fieldset class="radio">
<legend>Chaining mode</legend>
<label for="chain-cfb">
<input id="chain-cfb" name="chain" type="radio" />CFB
</label>
<label for="chain-cbc">
<input id="chain-cbc" name="chain" type="radio" />CBC
</label>
</fieldset>
</form>
<hr />
<p style="padding-top: 1em;">Some text underneath</p>
</body>
</html>
... and here is the content of demo.css...
fieldset
{
float: left;
display: block;
width: 17em;
margin: 0 1em 1em 0;
padding: 0 1em 1em 1em;
}
fieldset.radio input
{
clear: both;
float: left;
width: auto;
}
input
{
display: block;
width: 15em;
}
label
{
display: block;
margin-bottom: 1em;
font-weight: bold;
}
label.first
{
padding-top: 1em;
}
The way I read it, should be getting the desired result with this code. But I am not. Here is what renders instead ....
What changes do I need to make to my html/css in order to get the stated desired result?
A way without clearing is:
form { overflow: hidden; }
I usually create a class called floatbox and use this on every container which contains floating elements
.floatbox { overflow: hidden; }
the matching html then is
<form class="floatbox" action="">
<fieldset><p>I'm floating</p></fieldset>
<fieldset><p>me too</p></fieldset>
</form>
you need to make the <hr /> element clear the floats. hr { clear: left; }
Add:
hr {
clear: left;
}
to your style sheet to clear your floats.
You could use the ole' dummy clearing element trick:
<form action="">
<fieldset>
<legend>Field set A</legend>
<label for="password">Password
<input id="password" name="password" type="text" value="my password" />
</label>
</fieldset>
<fieldset class="radio">
<legend>Chaining mode</legend>
<label for="chain-cfb">
<input id="chain-cfb" name="chain" type="radio" />CFB
</label>
<label for="chain-cbc">
<input id="chain-cbc" name="chain" type="radio" />CBC
</label>
</fieldset>
<div style="clear:both"> </div>
</form>
This ensures your form actually occupies as much space as the elements inside it.
The problem with simply clearing the hr is that the form has zero width and height, which could be problematic if you're applying styling to the form as well.

Resources