Could you tell me how I could change it and get to work exactly as it does now, please?
Sorry to acknowledge that after 3 years I still don’t understand css/html speak. I take it that the anchor is th a tag, and that the block element is the mgn div Is that so?
But as the a tag is at the extremes of the line and the mgn div inside them, I don’t understand what you are saying. Could you explain, please?
It works and HTML5 should allow block elements wrapped by anchor tags (an inline element). @felgall, can you give an example of when this could fail? I avoid using that way, but I’ve never seen it broken on HTML5 - only on HTML4.01.
@qim, to make things clear. This is how I would do:
In your case, wrapping divs in your anchor tags shouldn’t be needed, although I don’t see it as a huge problem. In addition to that, you don’t even need p tags wrapping an anchor tag since HTML5 doesn’t require that.
Another thing I have changed was to add the anchor tags inside each box div, instead of creating a new row (separated by the break tag) and lining them up almost blindly.
I think felgal was referring to the case in the OP where the css selectors were set up wrong, different to the html structure, then it will fail or course. Set up properly, it should always work.
[quote=“qim, post:3, topic:207993”][quote=“SamA74, post:13, topic:207993”]
I think felgal was referring to the case in the OP where the css selectors were set up wrong,
[/quote]
Precicely.
.mgn1 a { }
in the CSS will “fail” when the HTML is
<a><div class="mgn1"></div></a>
because there is no <a> nested inside the element with the class for it to target.
Both need to either have the <a> inside the <div> or both need to have the <a> outside the <div> - it will fail if you have one inside and one outside.as was in the original code.
HTML5 does allow block elements in nested in <a> tags, so it’s not that unorthodox if you are using html5. The reason people are reluctant to accept this is because <a> is an inline element, and it is wrong to put block elements (Eg, <div>) inside an inline one.
While I understand why it’s wrong, I see the benefits of allowing it from a design point of view. You can have chunky “card style” links. Though if I do this I would set the <a>s to display:block just to be more correct about it.
The problem was just that the html did not match the css, so one or the other had to change.
It’s not unorthodox, really it’s all about preference in this case (and perhaps some tradition). Unless you need to support legacy browsers that strictly support HTML 4.01 or XHTML, your way is absolutely fine. I have this thing of trying to support as many browsers as I can purely on a whim.