1

Tailwind remove default style for link, I try to add underline to all links.

I tried

@layer base {
  a {
    @apply underline;
  }

But I have no idea where to put the code, I tried inside style tag in my layout blade html file, but its not working.

I tried

<style>
ul-link{
 @apply underline;
}
</style>

...
<div class="ul-link">Test</div>

This not working either, no underline.

but like this working

<div class="underline">Test</div>

What am I missing? Why is @apply not working? and How do I create global style?

3
  • The @layer ... code should be in your resources/css/app.css file below the tailwind imports. Run again npm run dev to update the compiled css and it should work. Commented Jan 16, 2021 at 23:42
  • its working, another question if I just want links in certain html page to be affected. Normally I can just use <style>, how to do it with tailwind? Commented Jan 17, 2021 at 0:21
  • Add a class to specific pages that you want this style to apply on, and than only target all links in the created class. Commented Jan 17, 2021 at 0:28

1 Answer 1

3

You need to add such configurations to base layout in app.css or app.scss file in your project.

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  a {
    @apply underline;
  }
}

As mentioned in the comments, if you would like this to not apply globally, then use a class name for this.

  .a-line {
    @apply underline;
  }

This way

<a href="#">Text 1</a>

<a href="#" class="a-link">Text 2</a> // will have underline
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.