Tailwindcss: Adding a 'streched-link' option (make parent block clickable)

Created on 21 Jul 2019  路  3Comments  路  Source: tailwindlabs/tailwindcss

First off, loving the framework so far, great work!

I was wondering if there's an option to add a class similar to stretched-link in Bootstrap 4.

https://getbootstrap.com/docs/4.3/utilities/stretched-link/

What it does is make the entire parent block clickable if you add the class to a link inside.

Most helpful comment

I'd probably do what @AlexVipond suggested but if for some reason the link can't wrap the whole component, you can use @apply to create a new class that mimics Bootstrap's:

.stretched-link::after {
  content: "";
  @apply z-10 absolute inset-0 bg-transparent pointer-events-auto;
}

All 3 comments

I suggest making the parent block a an anchor or a button for accessibility purposes, then adding Tailwind's group class to create a hover group. Then, you can use the group-hover class on its children to customize hover styles when the parent is hovered: https://tailwindcss.com/docs/pseudo-class-variants/#group-hover

I'd probably do what @AlexVipond suggested but if for some reason the link can't wrap the whole component, you can use @apply to create a new class that mimics Bootstrap's:

.stretched-link::after {
  content: "";
  @apply z-10 absolute inset-0 bg-transparent pointer-events-auto;
}

Hey @paulhuisman! I would solve this the way @AlexVipond mentioned 馃憤 I think adding a class like this to core would be a bit too much of a departure from the sorts of classes we currently provide, so if you wanted to create a stretched-link class I would do it in userland or via a plugin.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

AlexVipond picture AlexVipond  路  3Comments

jbardnz picture jbardnz  路  3Comments

Tjoosten picture Tjoosten  路  3Comments

benface picture benface  路  3Comments