Placing checkbox over an image without using 'top' and 'position:absolute'? - html

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.

Related

CSS HTML image next to the paragraph - background lost [duplicate]

This question already has answers here:
Why doesn't the height of a container element increase if it contains floated elements?
(7 answers)
Parent div ingnores height of child because of its float
(5 answers)
Closed 1 year ago.
I would like to place the image next to the paragraph. Unfortunately the background disappears.
My code looks like this:
<figure class="fig">
<label>
<div class="order">23</div>
<p>Suggested Location for RTD & Basement Box<span class="asterisk">*</span></p>
<img src="../images/basement_box.png" width="30%"></img>
<div style="clear:both;"></div>
</label>
<br>
<input type="text" placeholder="Enter your answer">
<br>
</figure>
label {
background-color: #E6EDF2;
padding: 5px;
}
label img {
display: inline;
float:left;
}
The image shows my problem.
I want the image next to the paragraph without losing the background.
If I put float:left or float:right image is placed quite well, but the background is rolled up to the paragraph only.
The clear:both; option doesn't work either, bringing back everything to the beginning.
How can I place my image, as shown in "good" example?
it's happen because u give your img element display:inline,that makes your image acted like a text,so it's move down,try:
img { display: block; position: absolute; right: 0; }
that's make your image one layer above your text
Basing on the hints provided in the comments I've solved finally this issue.
I used the overflow:hidden feature and placed clear:both; at the bottom of my label
<figure class="fig">
<label>
<img src="../images/basement_box.png" width="30%"></img>
<div class="order">23</div>
<p>Suggested Location for RTD & Basement Box<span class="asterisk">*
</span></p>
<div style="clear:both;"></div>
</label>
<br>
<input type="text" placeholder="Enter your answer">
<br>
</figure>
And CSS
label img {
float:right;
overflow: hidden;
}

How do I put input type="text" on the Image using css and html

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.

height of input tag in HTML

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;
}

Positioning of text relative to inline-block div

I'm having a problem with the positioning of text relative to an inline-block div to the right of it. Here's a jsfiddle which demonstrates this problem.
And here's the demo HTML/CSS:
HTML
Select Date:
<div class="inputblock">
<input type="radio" name="dateselect" value="0" />Todays Date<br />
<input type="radio" name="dateselect" value="1" />Another Date
</div>
CSS
.inputblock {
display:inline-block;
background-color:#DDD;
}
What I want is for the text to the left of the block of radio buttons which says 'Select Date', to be positioned next to the top of the div to the right of it, not at the bottom. How can I achieve this? Will I have to wrap the label in a div?
I would appreciate any advice with this issue.
All childs of inline elements can be vertically positioned at the top using the vertical-align:top CSS property.
So, your CSS needs one extra line:
.inputblock {
display:inline-block;
background-color:#DDD;
vertical-align: top;
}
Fiddle: http://jsfiddle.net/6CtT8/1/
If you wrap both the label and the inputblock in a div and set vertical-align: top on that div you get what you want like this:
<div style="vertical-align:top;">
Select Date:
<div class="inputblock">
<input type="radio" name="dateselect" value="0" />Todays Date<br />
<input type="radio" name="dateselect" value="1" />Another Date
</div>
</div>
Not sure if there's a better way using negative margins and relative positioning.
EDIT This works for me in Chrome as well:
.inputblock {
display:inline-block;
background-color:#DDD;
vertical-align: top;
}

Making a Input Text Field Be On The Right Side Of a Image

I have a 50x50 image and an <input type="text" /> field that I want to be on the right side of the image. I've tried this:
<img src="missing-image.png" />
<div name="image_input">
<input type="text" />
</div>
And with this CSS:
#image_input {
position: absolute;
top: 10px;
}
But the text input won't go to the right side of the image. Also as you can see I want it to be centralized with the height of the image and as I can see it won't work too. How I can correct this?
PS: All that is inside a <form>
Position absolute gives you more control:
HTML
<div name="image_input">
<img src="missing-image.png" />
<input type="text" />
</div>
CSS
div {
position:relative;
}
input{
position:absolute;
right:10px;
bottom:20px;
}
Try this:
<div id="image_input">
<img src="missing-image.png" />
<input type="text" />
</div>
and the CSS:
#image_input img {
float: left;
clear: none;
}
Note that I changed the div's "name" attribute to an "id" attribute.
there are a couple of ways to center align text next to an image. you can put it in a list and make the image the list style type. The other thing you can do it properly pad the element to center align it.
Try changing to this:
<div name="image_input">
<img src="missing-image.png" />
<input type="text" />
</div>
And the CSS:
.img {
display: inline-block;
}
To center the height, you might want to use one of the vertical-align options on the input tag.
such as:
input {
vertical-align: middle;
}
I don't use vertical-align very much, so you might have to tweak it a little to get it to work, but see here: http://www.w3schools.com/css/pr_pos_vertical-align.asp