Unless you are using HTML5, a link can only encompass text and ‘inline’ elements (that’s things like <b>, <em> and so on), but not ‘block’ elements (which, as it says, are for blocks, like <div>, <p> etc).
If you’ve only got text (and maybe inline elements as well) inside the <div> then you can just put the <a> inside the <div> rather than outside it.
If you’ve got multiple block elements inside the <div> and you want to make them all link to the same place, my preferred method is to put a normal <a> link on whatever is the most obvious bit of text to have as a link (eg a heading), and then use a bit of Javascript to make the whole <div> clickable - something like this:
What stevie said – as a rule I’d only make the relevant text (like the heading) a link with the anchor inside it. Block level containers like DIV really have no place inside an anchor…
Though the classnames in your example make me cringe… we have tags for headers, it’s called a numbered heading… and if an outer container has a class or ID, you probably don’t need a class or ID on the element inside it.
It smells like what I refer to as George Carlin’s “Not every ejaculation needs a name” – not every element needs a DIV around it or a class/ID on it.
Do you have an example page of what you are trying to accomplish – you know with real content and real markup? We could probably point you in a better direction for doing whatever it is you are trying to do if we could actually see it.
If you only have one element in the div then put the anchor inside the div as Stevie said and then set the anchor to display:block and it will expand to fill the horizontal space of the parent.
It looks as though you are creating a navigation anyway and you probably should be using a list to do this , but as Deathshadow said we’d need to see the section of code at hand to give more pertinent advice.
I did have one attempt at using the code but it stopped the CSS code from working on the text. Does using display:block affect any code which is used on the text?
Looking at that link I fail to see anything relevant to what you are asking… or at least nothing that should be a “DIV that’s an anchor”.
Can you be more specific as to WHAT on that page you are trying to replicate? “6 cells with padding” doesn’t really tell us a whole lot – though if they are cells like a table…
Though I’m wondering if we’re having ranguage rarrier issues as your sentence structure is nonsensical… to the point I almost hit “flag” to report as spam…
“affect any code which is used on the text”? Wrong verb, wrong tense, wrong target… No clue what that’s even supposed to mean.
There is no need for all those classes you had as everything can be reached via the parent apart form the 2 items that were different - these are the only ones that need extra classes.
they have cells which are fitted with links and not just the text.
I’ve no idea what you really mean by that I’m afraid. The link you have provided is using lists and anchors just as in the example I have already given you. What makes you think there is something special about it?
We could spend days on this unless you can be more specific and also take the time to try out the things that we suggest and then identify what it is that you need different
Holy hannah – talk about endless classed DIV for nothing. NONE of those lists should be included… take Paul’s advice and make that a list and get rid of EVERY SINGLE DIV. If every single like element inside a parent container is getting the same class, NONE of them need classes.
… and again, it’s invalid to put anchors around div – you should research the difference between “block level” and “inline level” elements, and probably learn a bit about “semantic markup” too.
I would also suggest avoiding the use of classnames that say what the appearance is, and instead use classes to say WHY you are giving it the appearance… so the markup would be:
We’ve already given you examples to do that. Just try the example I gave far above. It will rollover with a change of colour that fills the whole block.
How does the <li> work?
Apologies, but it seems we may have over estimated your knowledge of html and if you don’t understand lists yet then it may be hard for you to follow.
A list is a block level html element that is used for… lists of things - such as a list of links in a menu. You can read about it here. Take some time to research or nothing we say will make much sense.
You will need to add a class to each item and set a different rule for each link in the colour that you choose. Seems a bit overkill to me though but if that’s what you want then you will need the extra classes.