Dealing with styling of "a" tags (with or without hrefs?)
See original GitHub issueA very common markup in Angular version of bootstrap directives goes like this: <a (click)="prev()">Previous</a>
Pure bootstrap version would have an “empty” href (<a (click)="prev()" href="#">Previous</a>
) to provide appropriate styling (cursor) but this is not needed in ng-version and can interfere with routing.
The question: how do we deal with this situation? Few ideas:
- pass
$event
and callpreventDefault()
on it; this is what we do in the accordion, for example: https://github.com/ng-bootstrap/core/blob/1d912de06578aca1eaea9ad69942978090da43ff/src/accordion/accordion.ts#L42 - remove
href
altogether and add cursor styling through CSS (this would be quite easy with ng2 since we’ve got styles encapsulation) - try to convince bootstrap folks to “fix it” <- not even sure it makes sense
Now, I must admit that I don’t know what is the impact of removing href
on accessibility and keyboard navigation, so the encapsulated CSS path might be a non-option in the end…
Thoughts?
Issue Analytics
- State:
- Created 8 years ago
- Comments:41 (27 by maintainers)
Top Results From Across the Web
Styling <a> without href attribute - html - Stack Overflow
1 Answer 1 ; :not([href]) { /* Styles for anchors without href */ } ; { /* Styles for anchors with and without...
Read more >Styling links - Learn web development | MDN
Link states These can be styled using different pseudo-classes: Link: A link that has a destination (i.e., not just a named anchor), styled...
Read more >How to style an anchor tag with no href attribute? - Misc
In this post, you will learn how to style an HTML anchor tag without href attribute with a demo and HTML-CSS codes.
Read more >When (and when not to) use an anchor tag? - CSS-Tricks
If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed,...
Read more >HTML Button Link Code Examples – How to Make HTML ...
We can add a class to the anchor tag and then use that class selector to style the element. <a class="fcc-btn" href ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, another idea. How about this:
href
(this gives us proper cursor and accessibility)To avoid pain of writing too much for prevent default we could use this trick:
<a href (click)="!!doSth()">
. Taken from https://github.com/angular/angular/issues/2042#issuecomment-105689213This is what we do at Thomson Reuters:
<a (click)="prev()" href>Previous</a>
Thehref
, even when truly empty like this, keeps the anchor focusable and in tabindex. This is essential for A11y.