Hacker News new | ask | show | jobs
by whbrown 671 days ago
Why make it a link if you aren't linking to anything?
2 comments

so you don't have to set "cursor: pointer" in css
You should really use a button for this. Using anything else is semantically incorrect, and the "it comes with bad styles" argument doesn't make sense given a CSS reset is under 10 lines of code, or even less if you use the `all` style.
And it gives some baseline accessibility functionality. Sucks that there isn't any gerneral "I am clickable" element that neither has bad default click behavior, nor has its own likely-unfitting styling.
What's wrong with a button? You can make it look like an <a> can't you?
https://stackoverflow.com/questions/1367409 has varying amounts of CSS for that, ranging from bad (i.e. more than one line, i.e. the bar to beat for people to automatically use it over <a>) to horrific.

Looks like the rough minimum is this:

    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font: inherit;
And, given that some answers there have browser-specific additions, it looks like the spec doesn't have sane effective restrictions on what funky things browsers can do, thus essentially making the answer a "no, you cannot portably make a button look exactly like a link".

And no CSS I could find made the button content flow inline with surrounding text (I even went through all of the computed CSS in FF devtools and added the differing ones to the button), so it looks like the answer is "no" in practice too. (though, granted, for a good amount of link-buttons out there you'd probably want no mid-button breaking)

Certainly looks like it'd be simpler to make a <span> act like a link, than a <button>, at least. At which point you lose the implicit accessibility functionality.

why avoid so hard to make it a `submit` for a `<form method="POST" action="/logout">`, which is semantically correct and removes all the need for any javascript (logouts have never needed JS after all)?
because you often need to send a DELETE verb not POST
"If not link, why link shaped?"