Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML <label> command doesn't work in Iphone browser

Tags:

html

css

iphone

In a html page I am making, I tried to make div's clickable using html and css. This has worked perfectly in some major browsers I have tested it in (Chrome, Firefox, Opera, Safari), as well as an HTC phone, but when I tried to test it on Iphone I noticed it just didn't work. The checkboxes themselves weren't even selectable.

This is my (working apart from on Iphone) code:

HTML:

<div class="" style="height: 30px;">         <div style="display: table; width: 100%;">         <div style="display: table-row; width: 100%;">         <div style="display: table-cell;">         <label for="3171">Text....</label>         </div>          <div style="display: table-cell; text-align: right;">         <input type="checkbox" id="3171" name="3171">         </div>         </div>         </div>         <label for="3171">         <span class="blocklink">Invisible text</span>         </label>         </div> 

CSS:

.blocklink {     display: block;     height: 100%;     left: 0;     overflow: hidden;     position: absolute;     text-indent: -999em;     top: 0;     width: 100%; } 

So as you can see the technique I'm using is basicly just having a <label> spread all over the parent div so anywhere you click, it will tick/untick the linked checkbox.

Unfortunately, this doesn't work on IPhone. Would it be possible to somehow keep using this technique but also provide IPhone support? (Preferrably without javascript, because I'm really going out of my way to only use HTML & CSS)

Thanks in advance,

Arne

like image 720
arnehehe Avatar asked Mar 24 '11 15:03

arnehehe


People also ask

How do you display labels in HTML?

Firstly, use <label> tag by providing the <input> and id attribute. The <label> tag needs a for attribute whose value is the same as input id. Alternatively, <input> tag use directly inside the <label> tag. In this case, the for and id attributes are not needed because the association is implicit.

How does the label tag work in HTML?

HTML <label> tag When writing in HTML, the <label> tag is used to create labels for items in a user interface. Used within <input> tags on a form, the <label> tag is additionally useful because it extends the clickable area of control elements, like buttons.


1 Answers

Adding an empty onclick="" to the label makes the element clickable again on IOS4. It seems that by default the action is blocked or overtaken by the press and hold copy and paste text mechanics.

<label for="elementid" onclick="">Label</label> 
like image 192
Dan Manion Avatar answered Oct 02 '22 21:10

Dan Manion