arrange text below image - html

I want to have option buttons to have image and text below image. Right now i have managed to have image but dont know how to arrange text exactly below image without disturbing alignment.
<div>
<label>
<input type="radio" name="fb" value="small" />
<img src="http://placehold.it/20x20/35d/fff&text=f">
</label>
<label>
<input type="radio" name="fb" value="big" />
<img src="http://placehold.it/40x60/35d/fff&text=f">
</label>
<label>
<input id="fb3" type="radio" name="fb" value="med" />
<img src="http://cache1.asset-cache.net/gc/120523070-dogs-gods-gettyimages.jpg?v=1&c=IWSAsset&k=2&d=de2%2btiBrzaNEk9d4xwzh%2fvq8qyKYRsuWlpI1%2f65dmsaBkiniqNTDJkrq7zrUnaC6">
</label>
</div>
<div>
<label>
<input type="radio" name="fb" value="small1" text="ss" />
<img src="http://placehold.it/20x20/35d/fff&text=f" text="sdsdsd">
</label>
<label>
<input type="radio" name="fb" value="big1" />
<img src="http://placehold.it/40x60/35d/fff&text=f">
</label>
<label>
<input id="fb3" type="radio" name="fb" value="med1" />
<img src="http://cache1.asset-cache.net/gc/120523070-dogs-gods-gettyimages.jpg?v=1&c=IWSAsset&k=2&d=de2%2btiBrzaNEk9d4xwzh%2fvq8qyKYRsuWlpI1%2f65dmsaBkiniqNTDJkrq7zrUnaC6">
</label>
</div>
Here is Fiddle .
I am looking for output something like below
Also wish to generate option button in rows and column dynamically. Any idea related on how to achieve it?

Just set the to display: block;
.figures span, .figures img {
display: block;
}
you can write as
<label>
<input type="radio" name="fb" value="big1" />
<img src="http://placehold.it/40x60/35d/fff&text=f">
<span>your text</span>
</label>

Just add this css to the page:
<Style>
label{
float:left;
height:100px;/*can be modified*/
padding:10px;/*can be modified*/
width:50px;
}
</Style>
and after every image add and then the name as below:
<img src="http://placehold.it/20x20/35d/fff&text=f"><br/>
My name
To control how many images per row there is two ways.
1 - adding div for clear:
<div style='clear:both;'></div>
2- add everything inside a div and adjust the width of this div to until your reach to the proper count of images.
add this to the main div that you have
<div id="maincontainer" style="width:100px">
I updated the css by adding width:50px which means every label will be 50px... the main container is 100 => 2 items / row.
make the width of maincontainer to 150 -> 3 item / row....

According to your need, you can get desired output by using <br/> tag or without tag.
With <br /> Tag
fiddle
Without <br /> Tag
fiddle
In fiddle 1 i have used <br / > tag and in second i have used display:block; on images and display:inline-block on label. So use whatever you are ok with :)

You could wrap your images inside a <figure> tag and use <figcaption> for your text below it. I'm not sure what you mean in regards to "option buttons" though.
http://codepen.io/partypete25/pen/KzJOyY
<figure>
<img src="image-src-url" alt="">
<figcaption>Dog</figcaption>
</figure>

Change your CSS with this:
label > input + img {
/* IMAGE STYLES */
cursor: pointer;
background-position: 50% 50%;
background-repeat: no-repeat;
border-radius: 50%;
width: 50px;
height: 50px;
margin: 5px;
border: 1px solid #ccc;
float: left;
}
Demo

Related

Either using a class or an id will not affect the features of this div

I just got back into css again and for some reason I can't get this div to margin-right or show background color, right off the bat..
I started off using a div with an id.
#Full {
background-color: red;
margin-right: 300px;
}
HTML:
< div id="Full" >
and then I tried it with a class, ex.
.Full {
background-color: red;
margin-right: 300px;
}
HTML:
< div class="Full" >
and It should be linked, here's the whole thing:
.Full {
background-color: red;
margin-right: 300px;
}
<body>
<div class="Full" >
<br />
<label> Enter Username </label>
<input type="text" name="Username" />
<brk />
<label> Enter Password </label>
<input type="text" name="Password" />
<brk />
<button class="Button1"> Enter</button>
</div>
</body>
Am I forgetting something?
The example you provided is doing exactly as it should.
If you comment out margin-right:300px you will see the .Full div go full width.
The margin-right is pushing the right edge of the .Full box further left.
By having the body tag border turned on you can see that the .Full box stays within the bounds of the body, which tells you that the margin-right attribute is working.
.Full {
background-color: red;
margin-right: 300px;
}
body {
border: solid 1px;
}
<body>
<div class="Full">
<br />
<label> Enter Username </label>
<input type="text" name="Username" />
<brk />
<label> Enter Password </label>
<input type="text" name="Password" />
<brk />
<button class="Button1"> Enter</button>
</div>
</body>

Center text inside automatically generated label tag

I get the following snippet of html from a CMS:
<label title="">
Land
<input id="Land" name="Land" size="20" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="Land" data-valmsg-replace="true"></span>
</label>
I need to center the text Land, but I can't seem to figure it out. I've tried setting text-align: center on the label, but it doesn't work. I can't modify the markup. Is it something simple I'm missing?
EDIT:
I want to center it over this input:
Don't mind the right edge of the input field. The label span 100% of the width of the input field.
There is two ways to deal with that .
1.The display property specifies if/how an element is displayed so label must be displayed as block or inline-block to center it
label {
display: inline-block;
text-align: center;
}
2.you can use html tag center
<center>
<label title="">
Land
<input id="Land" name="Land" size="20" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="Land" data-valmsg- replace="true"></span>
</label>
</center>
And if you want to center the word Land over the centered Label , you can just add this
<center>Land</center>
the tag is an inline element and therefore exactly the same width of its content.
You would need a div or something to do this
Doing this without being able to alter the markup itself would be messy at best and will probably consist of some javascript/jquery
the label is not expanding on 100% width because it's an inline element. to enable this - set on the label css:
label {
display: block;
text-align: center;
}
or insert the text directly into a block element like: div, etc.
Edit:
Simply add the following CSS to achieve the desired result:
label input, label span {
display: block;
}
See a live demo: http://jsbin.com/sebinuje/1/edit?html,css,output OR http://jsfiddle.net/mayank_agarwal/5yUQr/
Enclose the snippet with a div element and apply the text-align property on the div.
HTML:
<div id="label-enclosure">
<label title="">
Land
<input id="Land" name="Land" size="20" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="Land" data-valmsg-replace="true">
</span>
</label>
</div>
CSS:
#label-enclosure{
text-align:center;
}
Although I'm loath to recommend using a <br/> tag here is one way given your current structure
JSfiddle
HTML
<label title="">
Land
<br/>
<input id="Land" name="Land" size="20" type="text" value=""/>
<span class="field-validation-valid" data-valmsg-for="Land" data-valmsg-replace="true"></span>
</label>
CSS
label {
text-align: center;
display: inline-block;
}

Highlight image when checkbox is checked, and when clicking on the image

Not working
<div>
<input type="checkbox" id="check" class="check-with-label" />
<label for="check" class="label-for-check">My Label
<img class="product-add-image-preview" src="http://ecx.images-amazon.com/images/I/417MwhxcFKL._SY300_.jpg" />
</label>
</div>
This works
<div>
<input type="checkbox" id="check" class="check-with-label" />
<label for="check" class="label-for-check">My Label </label>
<img class="product-add-image-preview" src="http://ecx.images-amazon.com/images/I/417MwhxcFKL._SY300_.jpg" />
</div>
I need the image in the label so that when I select the image, the checkbox is checked. But I can't seem to make the CSS work when I have the image in label.
http://jsfiddle.net/4QV3s/
That's because you're trying to access the image, but you forgot about the label. Also, you don't want to use ~, you want to use + so it will access the following, and only the following label. Replace the + with the ~ again, and you'll see what I mean.
.check-with-label:checked + label > .product-add-image-preview {
border:10px solid yellow;
padding:0; /* To keep things from moving */
}
Here's an updated fiddle. I added a second image so you could see them work independently of each other: http://jsfiddle.net/4QV3s/1/

Radio Button with images formatting

I am trying to have three images across each line with a radio button underneath each. I am not too familiar with forms and I just cannot figure out why the images are rendering out this way. Anyone have any thoughts or any ideas at how to create this?
/jess/design.html
edit: figured out part of it... problem with the width on forms. still trying to figure out how to get the radio button underneath if anyone cant help with that.
Just put each radio button with its image inside a div with width: 100%, It should do the trick.
EDIT: No wait, that will put the radio on the right side of the image, try also adding 100% width to the image inside the wrapping div and setting the width of the wrapping div to the value you want for the number of column desired (50% for 2 columns)
you can this one, http://jsfiddle.net/ayBeh/
I suggest you that ID should Use on time at same page, so please use .bead instead "#bead",
sorry to say BRO, I Saw your code, not much cleaner , there is lots of cleanup issues,
I think Your not familiar with HTML also, but anyways you tried best, keep it up, if want help contact me any time,
Nest the divs and apply the appropriate rules:
See it here: http://jsfiddle.net/SREMB/4/
html, body {
width: 100%;
}
.row {
text-align: center;
width: 100%;
display: inline-block;
white-space: nowrap;
}
.cell {
padding: 10px;
display: inline-block;
text-align: center;
}
img {
border: 2px solid black;
}
​
HTML
<div class="row">
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/grey.gif"><br>
<input type="radio" name="bead" value="grey" />
</div>
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/ivory.gif"><br>
<input type="radio" name="bead" value="ivory" />
</div>
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/mattsmoke.gif"><br>
<input type="radio" name="bead" value="mattsmoke" />
</div>
</div>
<br><br>
<div class="row">
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/grey.gif"><br>
<input type="radio" name="bead" value="grey" />
</div>
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/ivory.gif"><br>
<input type="radio" name="bead" value="ivory" />
</div>
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/mattsmoke.gif"><br>
<input type="radio" name="bead" value="mattsmoke" />
</div>
</div>
<br><br>
<div class="row">
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/grey.gif"><br>
<input type="radio" name="bead" value="grey" />
</div>
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/ivory.gif"><br>
<input type="radio" name="bead" value="ivory" />
</div>
<div class="cell">
<img src="http://connorreaumond.com/jess/images/beads/mattsmoke.gif"><br>
<input type="radio" name="bead" value="mattsmoke" />
</div>
</div>
<br><br>
​

How to middle vertical align a radio button against an image in html?

I have multiple image of 100x100. I ask the user to choose one of them by putting an radio button before each of them.
This is the code :
<div>
<input type="radio" name="pic" value="1"/><img src="pic01.jpg"/><br/>
<input type="radio" name="pic" value="2"/><img src="pic02.jpg"/><br/>
....
and so on... But the problem is that the radio button renders at the bottom of the line and I want to make it come in the vertical middle of the image. I have tried style="vertical-align:middle" and it does not work.
Any ideas?
When applied to inline elements, vertical-align specifies where to align a certain part of the child element to a corresponding part of the parent's line box. For example, "middle" roughly aligns the middle parts of each. If you want to align two siblings, you'll need to apply the same vertical alignment to both, otherwise the element will align to the parent's baseline.
<style type="text/css">
input[type="radio"], input[type="radio"]+label img {
vertical-align: middle;
}
</style>
<ul>
<li>
<input type="radio" name="pic" id="pic1" value="1" />
<label for="pic1"><img src="pic1.jpg" alt="pic 1" /></label>
</li>
<li>
<input type="radio" name="pic" id="pic2" value="2" />
<label for="pic2"><img src="pic2.jpg" alt="pic 2" /></label>
</li>
</ul>
<div style="width=define_your_image_container_width_here">
<div style="float:left;vertical-align:middle"><input type="radio" name="pic" value="1"/></div>
<div style="float:right;"><img src="pic01.jpg"/></div>
</div>
In addition to the previous answer, the radio button must have the same actual height as the image for it to work. By actual I mean it must match height, padding, margin and border.