Have you tried this in IE9? When you hover over the text, the cursor changes to a standard text cursor and it does nothing when you click on the text. As users are prone to click on text elements and when the text elements fill up most of the div , it makes this solution unusable in IE9. Has anyone else experienced this or have a solution? Does anybody know how to have :hover css work with this solution? Perhaps referring the answer put in the fiddle? Show 27 more comments.
Claudio 1 1 gold badge 15 15 silver badges 30 30 bronze badges. Soviut Soviut However, this doesn't make a 'div' into a link.
It makes a link into a block element. It's a bit different. This is solution of your problem. I dislike having lots of content in a link, but this could just as well be part of a navigation menu or something like that. In which way is it wrong to make it into a block? It's semantically correct and it can be used to display it as you want.
This is a perfectly valid solution to a vague question. You actually COULD simply wrap an anchor element around a div, but that would be semantically incorrect. Block element within inline element. I'm not saying replace divs with links, but by the sounds of the question he just wanted a block he could click like a button or something.
Show 4 more comments. This is a bad example, because what the a tag does is takes all the text in a div and underlines it Tried this and it worked, however it broke the element's positioning.
Requires a little javascript. But, your div would be clickable. Results in bad semantics on the page though, so I'd avoid this one even though it is technically possible. I thought about using this solution, but it's kind of ugly. I like the solutions involving display: block better. This looks like a link, but isn't a real link. It has severe usability and accesibility issues, and is a really nasty solution.
Best solution. We just need to run script and send "this" to it. If they don't have js enabled you lost functionality. As well as being bad for SEO. Show 6 more comments. MagTun MagTun 4, 3 3 gold badges 46 46 silver badges 86 86 bronze badges.
Chris Jumonville's solution is working great on both Andriod and iPhone. Example: gastateparks. Shouldn't it be div. This works beautifully, very smooth, works with screen readers nicely too, HTML5 adhering, works even if you do transforms on the parent object, and inherently makes the cursor into a pointer as you expect for a clickable object — Steffen Cole Blake. This is a "valid" solution to achieving what you want. Calvin Calvin 4, 1 1 gold badge 22 22 silver badges 21 21 bronze badges.
Not sure if this is valid but it worked for me. Tim Tim 2 2 silver badges 3 3 bronze badges. I have to say that this approach is as clean as a css class on your stylesheet. This is the best one — Shahram Banazadeh. Noah H 2 2 silver badges 9 9 bronze badges. Erhard Dinhobl Erhard Dinhobl 1, 14 14 silver badges 33 33 bronze badges. To get info about data-attributes see: ejohn. To make thepeer's answer work in IE 7 and forward, it needs a few tweaks. Ben Ben It's not valid to put a block level tag inside an inline tag, so that's the source of the error.
You could use a span instead of a div and use css's display: block; to make it look as desired and semantic. It will become a block element without nesting. I don't think semantics has anything to do with it. It's now valid and technically correct but has nothing to do with semantics. Show 6 more comments. Surreal Dreams Surreal Dreams Thanks — Adil.
I've found use for this over the accepted answer; all text within the "a block" becomes underlined. Yeah, you can get rid of the underlines via text-decoration but that property isn't inherited. Using your method, denu, makes it simple. Yes it is the solution Bootstrap uses with its stretched-link: getbootstrap. Would be nice to get your thoughts! Two things you can do: Change childdivimage to a span element, and change parentdivimage to an anchor tag.
Use Javascript to bind a click event to parentdivimage. You must redirect the browser window by modifying window. Stephen Stephen Kyle Crabtree Kyle Crabtree 1 1 silver badge 9 9 bronze badges.
David Thomas David Thomas k 49 49 gold badges silver badges bronze badges. I want the entire block to a href link.. Alexander Vogt This can be done in many ways.
Using nested inside a tag. Dharman Ayush Anand Ayush Anand 51 2 2 silver badges 8 8 bronze badges. The browser renders it, but it's not html-conform. DaveW DaveW 21 1 1 bronze badge. Save Emails and Attachments. Download email messages and file attachments from Gmail to your Google Drive. Google Forms Email Notifications. Send email notifications to multiple people when a new Google Form is submitted. Document Studio. Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms.
0コメント