Breakout Buttons
Publikováno: 4.10.2019
Andy covers a technique where a semantic <button>
is used within a card component, but really, the whole card is clickable. The trick is to put a pseudo-element that goes beyond the button, covering the entire card. The tradeoff is that the pseudo-element sits on top of the text, so text selection is hampered a bit. I believe this is better than making the whole dang area a <button>
because that would sacrifice semantics and likely cause extreme weirdness for … Read article
The post Breakout Buttons appeared first on CSS-Tricks.
Andy covers a technique where a semantic <button>
is used within a card component, but really, the whole card is clickable. The trick is to put a pseudo-element that goes beyond the button, covering the entire card. The tradeoff is that the pseudo-element sits on top of the text, so text selection is hampered a bit. I believe this is better than making the whole dang area a <button>
because that would sacrifice semantics and likely cause extreme weirdness for assistive technology.
See the Pen
Semantic, progressively enhanced “break-out” button by Andy Bell (@andybelldesign)
on CodePen.
You could do the same thing if your situation requires an <a>
link instead of a <button>
, but if that's the case, you actually can wrap the whole area in the link without much grief then wrap the part that appears to be a button in a span or something to make it look like a button.
This reminds me of the nested link problem: a large linked block that contains other different linked areas in it. Definitely can't nest anchor links. Sara Soueidan had the best answer where the "covering" link is placed within the card and absolutely positioned to cover the area while other links inside could be be layered on top with z-index
.
I've moved her solution to a Pen for reference:
See the Pen
Nested Links Solution by Chris Coyier (@chriscoyier)
on CodePen.
The post Breakout Buttons appeared first on CSS-Tricks.