So I have a div, which has an input and button tag. How can I make the height same as the height of the div?
I have tried the following code:
<div class="input-area" style="border:1px solid;display:table;background:green;">
<input type="text" style="border:none;display:table;float:left;background-color:red;" />
<button>Search</button>
</div>
Since I can't upload images till now, here is a link to it:
https://drive.google.com/file/d/0BxCMhBQ7C3kLemVEemJYUldaZWM/edit?usp=sharing
There are numerous ways to accomplish this. Here are two:
Give the div container a specific height, then give the input
element a height of 100%:
<div class="input-area" style="height:50px;">
<input type="text" style="height:100%;" />
</div>
Position the input element absolutely, and the div container relatively, then use some more CSS to style it properly:
<div class="input-area" style="position:relative;width:200px">
<input type="text" style="position:absolute;left:0;top:0;bottom:0;right:50px;" />
</div>
Also, move your CSS to an external file. Inline styles are annoying.
<input height="pixels">
in pixels set your height as you want . Try it
Text input is tricky because of the differences in browsers. I use the following in my CSS to ensure that all inputs have the same height:
input[type="text"] {
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 24px;
}
Related
Is it possible to put a checkbox over an image without using 'top' and 'position:absolute' ?
<div class="main">
<img src="http://www.standard.co.uk/incoming/article9760552.ece/binary/original/Rooney.jpg" class="image"/>
<input class="checkbox" type="checkbox" value="1" />
</div>
JSFIDDLE
There's a few possible ways. If you want to avoid top and absolute you could position it using negative margins. Or if you simply want checkbox to be checked when the image is clicked you could wrap the image in a label and tie the label to the checkbox. I've done both here.
HTML:
<div class="main">
<label for="checkbox">
<img src="http://www.standard.co.uk/incoming/article9760552.ece/binary/original/Rooney.jpg" class="image" />
</label>
<input id="checkbox" type="checkbox" value="1" />
</div>
CSS:
.image {
height: 200px;
width: 250px;
}
input {
display: block;
margin-top: -200px;
position: relative;
}
A quick explanation: position: relative allows the checkbox to sit on top of the image (z-index won't cut it here), the negative margin-top pulls it up onto the image, and display: block makes it so that the top margin can be applied (I'm not sure why it doesn't work on inline elements.) I expected to have to use negative margins on margin-left as well, but it seems to naturally move to the left on it's own. I'm not sure why for that either. But it does work and it does not need position: absolute or top.
I do not want to know How to use image as an input text.
I want to know How do I put the text input on the Image
login.html
<div id = "background">
<img class="stretch" alt="" src="C:\Users\joseph\Documents\GitHub\Spring2014\CMP342\MainProject\WebContent\WEB-INF\img\login.png">
<div class = "text">
<input type="text" >
<input type="text" >
</div>
</div>
login.css
#background{
margin-left:30%;
width:400px;
height:400px;
}
.stretch{
width:100%;
height:100%;
}
.text{
}
What am I trying to do now is imitating the Google "Sign in" page
You have 2 options
Set background image for the #backkground. Use margin, padding, or other background css for positioning. This option won't need any img tag.
Use position: relative on the #background, and position: absolute on the .text. Use left, top, right, bottom css on #text for any kind of positioning you want.
I would recommend going with the 1st option. But if you feel the need to keep the img tag for some reasons, then the second option is good enough for you.
Be sure to close your text input tags. Also try this.
CSS:
#background {
margin-left: 30%;
width: 400px;
height: 400px;
background-image: url(C:\Users\joseph\Documents\GitHub\Spring2014\CMP342\MainProject\WebContent\WEB-INF\img\login.png);
background-size: contain;
}
HTML:
<div id = "background">
<div class = "text">
<input type="text" />
<input type="text" />
</div>
</div>
Use CSS to position your text inputs where you'd like inside the div.
I have the following code:
<div class="w25">
<span>True</span>
<input data-ng-model="answer.correct"
type="checkbox">
</div>
The div is approximately 150px wide. What happens is that the input appears in the center with about 70px on each side.
How can I get the <input> to go to the left ?
span and input elements are both inline by default, and the checbox will be placed next to the span element. I assume no further styling is applied on any of the elements. If it is, please post your css.
If you want to place the checkbox on the left, you can either:
Turn around the span and input (input first, then the span)
Float the input to the left (style="float: left;")
Use explicit positioning (eg. postition: absolute; left: 0;)
As illustrated here
<input data-ng-model="answer.correct" style="float:left" type="checkbox">
Probably you have inherit styles from your div class="w25". But you can try with this:
One change the order:
<div class="w25">
<input data-ng-model="answer.correct" type="checkbox">
<span>True</span>
</div>
Two add this properties on your CSS to be sure each element has the correct properties:
.w25 input, .w25 span {
margin:0;
padding:0;
vertical-align:middle;
}
View this demo http://jsfiddle.net/W7YE7/1/
First, change the positions of input and span (if you can do it) and see if it works:
<div class="w25">
<input data-ng-model="answer.correct" type="checkbox">
<span>True</span>
</div>
If it doesn't work, try to change the input for:
<input data-ng-model="answer.correct" style="float: left" type="checkbox">
If it doesn't work too, try it:
<div class="w25">
<div style="width:70px; display: inline;"><span>True</span></div>
<div style="float:left; width:70px; display: inline;"><input data-ng-model="answer.correct" type="checkbox"></div>
</div>
You can add the CSS style float: left;
Usually it's a better practice to put the styling in a separate CSS file, not inline, so if you can do that, assign a class to the input, like this:
<div class="w25">
<span>True</span>
<input class="yourclass" data-ng-model="answer.correct" type="checkbox">
</div>
And in the css file:
.yourclass {float: left;}
Here you have the JsFiddle: http://jsfiddle.net/A52nS/
try this css
.w25{
float:left;
}
I have:
<div>
<input id="input" type="text" />
<button id="submit">submit</button>
</div>
which gives me this
If I expand the main panel by dragging it with the mouse cursor the width the new space is empty:
I want that the <input type="text" /> fills the whole horizontal new space but that the submit button remains in the same row.
I tired to use <input style="width:100%" type="text"/> but then it fills the whole row and the submit button appears in the next row:
I also tried a table as mentioned in that thread:
Liquid textfield width
The result was that it works "a little bit" the submit button overlaps the input text and a certain space on the right always remains empty:
Can somebody help me with an code idea for fill the whole space except the (static) size of the submit button.
Thanks!
The "table" method you linked to will work, but you're missing one crucial property on your input elements: box-sizing.
http://cssdeck.com/labs/sbffl3l2
<div class="foo">
<div class="bar"><input type="text"></div>
<div class="bar"><input type="submit"></div>
</div>
.foo {
display: table;
width: 100%;
}
.bar {
display: table-cell;
}
.bar:first-child, input[type="text"] {
width: 100%;
}
input {
box-sizing: border-box; /* this is the key */
}
Prefixes may be required: http://caniuse.com/#feat=css3-boxsizing
I believe you can do this:
<input type="text" style="width:calc(100%- widthofbuttoninpixels);" />
It's not advisable to do inline styles though.
Edit: Make sure you also define a fixed width for the button
Why not give width of 70% to input and 20% to button?
Currently I have the following HTML code.
<div class="field">
<label>E-mail address: </label>
<input type="text" id="email" name='email' style="width:200px;"></input>
<span class='warning' id="emailWarning" > </span>
<div class="tip" id="emailTip"></div>
</div>
However, I want the text in the div element (class = 'tip') to be aligned with the start of the form's text field.
How should I do this using HTML and CSS?
Here's what is looks like now:
http://jsfiddle.net/pEJMD/embedded/result/
This would be a quick workaround. You should put both the .tip div and the input into a wrapping div.
You can set a fixed size to the label. Than push the div to the right with the size of the label:
<div class="field">
<label style="width:100px;">E-mail address: </label>
<input type="text" id="email" name='email' style="width:200px;"></input>
<span class='warning' id="emailWarning" > </span>
<div class="tip" id="emailTip" style="margin-left:100px;">
The quick brown fox jumps over the lazy dog
</div>
</div>
And the result.
Well, either you use a <table>, putting in one cell the <label> and in the other the <input>, or you use fixed widths/margins or paddings.
Solution 1: Table
Table solution
In this solution you use a table to hold the form. On column is for labels, the other column is for inputs. In this case you will have the tip in the input column, and it will align automatically with the input.
This has the pro to be working for flexible dimensions of your label/inputs. And tables are not always evil. Just remember that, if you want to keep your label aligned with the input, add a vertical-align:top to your CSS.
Solution 2: Fixed width
Fixed-width solution
In this solution you give a fixed width to your label, and move the .tip div using either margin, padding or left.
This will hold your layout in place, so be careful of extremely long labels!
You don't need an explicit width at all, nor tables; just use CSS tables (see my answer to this related question):
CSS
form { display: table; }
p { display: table-row; }
label { display: table-cell; }
input { display: table-cell; }
HTML
<form>
<p>
<label for="a">Short label:</label>
<input id="a" type="text">
</p>
<p>
<label for="b">Very very very long label:</label>
<input id="b" type="text">
</p>
</form>
Here's a JSFiddle: http://jsfiddle.net/DaS39/1/
And if you need the labels right-aligned, just add text-align: right to the labels: http://jsfiddle.net/DaS39/
Use margin-left:
Change:
<div class="tip" id="emailTip">
To:
<div class="tip" id="emailTip" style="margin-left:95px;">
DEMO
Learn more about the CSS margin property here.
You can give a height to the label, give a width to the parent div and float your tip. See the demo: http://jsfiddle.net/pEJMD/4/
Here you go: http://jsfiddle.net/4sJ2t/
You just need to give your label a fixed width, and then your tip a left margin
label {width:100px; text-align:right; margin-right:5px;}
.tip {margin-left:105px; padding: 5px 0;}