I have input fields which are supposed to be shown centered and then the texts to these input fields are supposed to be aligned left and "start" with the input fields.
http://jsfiddle.net/tfbatp5v/2/
.inputdes {
color: #9b9b9a;
font-size:20px;
height: 200px;
}
.blue {
height: 70px;
}
<div align="center" id="parent">
<div class="welcome">Welcome</div>
<div class="inputdes">
<div class="blue">text1<br><input id="inputfield1" /></div>
<div class="blue">text2<br><input id="inputfield2" /></div>
<div class="blue">text3<br><input id="inputfield3" /></div>
</div>
</div>
However, no matter what I do, every time when I use text-align: left; it automatically aligns the inputfields left as well. I tried to group the text areas together with class names but it doesn't work. Does anyone know the answer?
Thanks !
It's recommended to not use align="center", because align attribute is deprecated. You should use the CSS text-align property on the container.
The rule display: table; will make the element to "shrink-to-fit" the content inside, without need to specify the width value.
#parent {
display: table;
margin: 0 auto;
}
.welcome {
text-align: center;
}
.inputdes {
color: #9b9b9a;
font-size: 20px;
height: 200px;
}
.blue {
height: 70px;
}
<div id="parent">
<div class="welcome">Welcome</div>
<div class="inputdes">
<div class="blue">text1<br><input id="inputfield1" /></div>
<div class="blue">text2<br><input id="inputfield2" /></div>
<div class="blue">text3<br><input id="inputfield3" /></div>
</div>
</div>
Try something like the following. The idea is that we limit the width of the .inputdes div, then put the text in a nested div that has text-align: left. That way we can have the inputs centered but the text aligned left within its div.
.inputdes{
color: #9b9b9a;
font-size:20px;
height: 200px;
width: 200px;
}
.inputdes > div > div {
text-align: left;
margin: 0 15px;
}
.blue{
height: 70px;
}
<div align="center" id="parent">
<div class="welcome">Welcome</div>
<br>
<div class="inputdes">
<div class="blue" ><div>text1</div>
<input id="inputfield1"/></div>
<div class="blue" ><div>text2</div>
<input id="inputfield2" /></div>
<div class="blue" ><div>text3</div>
<input id="inputfield3" /></div>
</div>
</div>
You could give the input around the fields a fixed width and give the inputs a width: 100% to use text-align: left.
.inputdes{
color: #9b9b9a;
font-size:20px;
height: 200px;
width: 200px;
text-align: left;
}
input {
width: 100%
}
.blue{
height: 70px;
}
<div align="center" id="parent">
<div class="welcome">Welcome</div>
<div class="inputdes">
<div class="blue" >text1<br>
<input id="inputfield1"/></div>
<div class="blue" >text2<br>
<input id="inputfield2" /></div>
<div class="blue" >text3<br>
<input id="inputfield3" /></div>
</div>
</div>
Here's the updated Fiddle:
https://jsfiddle.net/tfbatp5v/11/
Related
I have found the following solution for aligning an img vertically within a div
https://stackoverflow.com/a/7310398/626442
and this works great for a basic example. However, I have had to extend this and I want a row with two bootstrap col-md-6 columns in it. In the first column I want a 256px image, in the second I want a h1, p and a button. I have to following HTML:
<div class="home-costing container">
<div class="row">
<div class="frame">
<span class="helper"></span>
<div class="col-md-6">
<img src="http://www.nijmegenindialoog.nl/wp-content/uploads/in.ico" height="256" width="256" />
</div>
<div class="col-md-6">
<h2>Header</h2>
<p>
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA<br /><br/>
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
</p>
<a class="btn btn-default"
href='#Url.Action("Index", "Products")'
role="button">
Learn More
</a>
</div>
</div>
</div>
</div>
and the following CSS:
.home-costing {
color: #fff;
text-align: center;
padding: 50px 0;
border-bottom: 1px solid #ff6500;
}
.home-costing h2 {
text-transform: uppercase;
font-size: 60px;
}
.home-costing p {
font-size: 18px;
}
.home-costing .frame {
height: 256px;
width: 256px;
border: 0;
white-space: nowrap;
text-align: center;
margin: 1em 0;
}
.home-costing .helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.home-costing img {
vertical-align: middle;
max-height: 256px;
max-width: 256px;
}
The problem is that now the second column is no longer contained and the text does not wrap and goes off to the right.
How can I center align my image in the first column with the text in the right column and still get the correct wrapping in the second column?
Fiddler: https://jsfiddle.net/Camuvingian/1sc40rm2/2/
Your HTML needed updated, in Bootstrap, the div order should ALWAYS go .container > .row > .col- * - *, your code however went .container > .row > .frame > .col- * - *. I have corrected your HTML and now your code works.
HTML:
<div class="home-costing container">
<div class="row">
<div class="col-md-6">
<img src="http://www.nijmegenindialoog.nl/wp-content/uploads/in.ico" height="256" width="256" class="center-block" />
</div>
<div class="col-md-6">
<h2>UserCost</h2>
<p>Hello, I'm a paragraph</p>
<a class="btn btn-default"
href='#Url.Action("Index", "Products")'
role="button">
Learn More
</a>
</div>
</div>
</div>
</div>
Link to finished code example:
Codepen - Updated & working code
This fixes the word wrap issue also on the p tag.
CSS:
p {
font-size: 18px;
word-wrap: break-word;
}
Does any have an idea how to do so?
I created this fiddle http://jsfiddle.net/matusko/2pctr9ok/3/ and all I want to do is, that the input behave the same way as the upper divs.
CSS:
.left {
float:left;
width:180px;
background-color:#ff0000;
}
.right {
width: 100%;
background-color:#00FF00;
display: block;
}
HTML:
<div>
<div class="left">
left
</div>
<div class="right">
right
</div>
</div>
<br/>
<div>
<div class="left">
left
</div>
<input type="text" placeholder="right" class="right"/>
</div>
I dont understand why input doesnt behave like div, even when propriety inspector says that its display is block.
You can use calc in CSS to dynamically calculate the width for you.
Sample below:
.left {
float: left;
width: 180px;
background-color: #ff0000;
}
.right {
width: calc(100% - 180px);
background-color: #00FF00;
display: inline-block;
}
input[type="text"] {
box-sizing: border-box;
width: 100%;
}
<div>
<div class="left">left</div>
<div class="right">right</div>
</div>
<br/>
<div>
<div class="left">left</div>
<div class="right">
<input type="text" placeholder="right" />
</div>
</div>
For < IE9 I would suggest the following http://jsfiddle.net/2pctr9ok/4/
Putting the left bottom in position:absolute, the whole bottom block in overflow:hidden and apply a padding-left:180px on the input.
I have this CSS:
.div0{padding:5px;height:70px;}
.pos0{float:left;height:50px;padding:5px; background: red;}
.butt{float:middle; position:relative;top:8px;height:40px;}
.pos1 { background: green; position:relative;left:15px;top:4px;min-width:100px; }
.pos2 { position:relative;left:15px;bottom:-8px; } //background: yellow;
and this HTML:
<div class="div0" id="Div0" style="background-color: rgb(255, 255, 221);">
<div class="pos0">
<button name="Pag" class="butt" id="ButtFull0">MY butt here</button>
</div>
<div class="pos1"><span> aLev:</span>
<input size="1" id="S0" type="text"/><span> vMin:</span>
<input size="1" id="n0" type="text"/><span> vMid:</span>
<input size="1" id="inp0" type="text" /><span> vM:</span>
<input size="1" id="inp1" type="text"/><span id="Q0"> text</span>
</div>
<div class="pos2">
<input id="y0" type="checkbox"/><span> 1°:</span>
<input id="y10" type="checkbox"/><span> 2°:</span>
<input id="e0" type="checkbox"/><span> 3°:</span>
<input p id="p0" type="checkbox"/>
</div>
</div>
I want the button vertically centered on the left and two lines with inputs and checkboxes at its right, both vertically even spaced. All maintaining position while shrinking the window.
I tried with this:
http://jsfiddle.net/qacp35fv/33/
Problems:
1) the 2 lines overlap the button (I put a background color green to better see the problem), so you can't easy click on it.
2) when shrinking the result window to the right, the 1° line becomes multiline: I prefer it remains one line without seeing some text and without increasing the total height.
This would be a good base to use. You can add your input elements in the correct divs.
body {
padding: 0px;
margin: 0px;
}
#wrapper {
width: 100%;
font-size: 0px;
display: table;
}
#left-column {
background: red;
display: table-cell;
height: auto;
font-size: 16px;
width: 120px;
vertical-align: top;
}
#right-column {
background: yellow;
display: table-cell;
font-size: 16px;
width: calc(100% - 120px);
vertical-align: top;
}
#row-1, #row-2 {
height: 20px;
overflow-x: hidden;
}
<div id="wrapper">
<div id="left-column">
Left column
</div>
<div id="right-column">
<div id="row-1">
Right column row 1 with extra long text that will be hidden when resized.
</div>
<div id="row-2">
Right column row 1
</div>
</div>
</div>
Help newbie in div for php or html without using css or table.
Trying to do this 4 x column, 2 x row using div with the following behavior
// [.....adjustable....][fixed][fixed][fixed]
// [.....adjustable....][fixed][fixed][fixed]
Below are my codes----------------------------------------
<form action="welcome.php" method="get">
<div style="position: relative; width: 100%; ">
<div id="left" style="position:relative;float:left;width:68%;"> left </div>
<div id="right" style="float:left;width:13%;"> Name: </div>
<div id="right2" style="float:left;width:13%;"> Age: </div>
<div id="right3" style="float:left;width:6%;"></div>
</div>
<div style="position: relative; width: 100%; ">
<div id="left2" style="position:relative;float:left;width:68%;"> left2 </div>
<div id="right4" style="float:left;width:13%;"> <input type="text" name="name"></div>
<div id="right5" style="float:left;width:13%;"> <input type="text" name="age"></div>
<div id="right6" style="float:left;width:6%;"> <input name="submit" type="submit"></div>
</div>
The 68% is equal to 860 pxl on my screen. It should change if it goes to other screen resolution. I tried making the 68% to 100% and the other div with id=right to style="position:fixed..." but it just mess up and puts everything on left side.
The easiest way of accomplishing this, is by using display: table and display: table-cell, to style divs as a table, without using an actual table:
Example on jsbin. See display on mdn.
I'll add both the CSS version and the, discouraged, inline style version to this post:
CSS version
<div class="parent">
<div class="left">ASDF</div>
<div class="right">asdf</div>
<div class="right">asdf</div>
<div class="right">asdf</div>
</div>
With CSS:
.parent {
display: table;
width: 100%;
}
.left {
width: auto;
border: 1px dotted blue;
display: table-cell;
}
.right {
display: table-cell;
width: 50px;
border: 1px dotted green;
}
Inline style version
<div style="display: table; width: 100%;">
<div style="display: table-cell;">ASDF</div>
<div style="display: table-cell; width: 150px;">asdf</div>
<div style="display: table-cell; width: 150px;">asdf</div>
<div style="display: table-cell; width: 150px;">asdf</div>
</div>
I have this set (JsFiddle link) of labels and text inputs.
How do I center the whole thing in the middle of the page?
I tried wrapping them in a div and setting it's alignment to cetner - didn't do what i expected at all.
Any help is appreciated, than you.
Code for reference:
<div>
<div class="left">
label
</div>
<div class="right">
input element
</div>
</div>
<div>
<div class="left">
another label
</div>
<div class="right">
another input element
</div>
</div>
//align the labels and input nicely
.left {
width: 20%;
float: left;
text-align: right;
}
.right {
width: 65%;
margin-left: 10px;
float:left;
}
If you're going to use float, than you need to wrap the whole thing in a DIV and apply margin: 0 auto;
I'd do this in this case:
<style>
.field {
width: 80%;
margin: 0 auto;
}
.left {
width: 20%;
text-align: right;
display: block;
float: left;
margin-right: 5%;
}
</style>
<div class="field">
<label class="left">label</label>
<input type="text">
</div>
<div class="field">
<label class="left">another label</label>
<input type="text">
</div>
wrap the whole thing in a div and set
margin: auto;
also set a width, if you want to use the text-align: center; method , that should be applied to the parent pf the div to be centered.