How do I make an html link look like a button?

后端 未结 22 1047
执笔经年
执笔经年 2020-11-22 14:03

I\'m using ASP.NET, some of my buttons just do redirects. I\'d rather they were ordinary links, but I don\'t want my users to notice much difference in the appearance. I c

22条回答
  •  孤城傲影
    2020-11-22 14:47

    You may do it with JavaScript:

    1. Get CSS styles of real button with getComputedStyle(realButton).
    2. Apply the styles to all your links.

    /* javascript, after body is loaded */
    'use strict';
    
    { // Namespace starts (to avoid polluting root namespace).
      
      const btnCssText = window.getComputedStyle(
        document.querySelector('.used-for-btn-css-class')
      ).cssText;
      document.querySelectorAll('.btn').forEach(
        (btn) => {
          
          const _d = btn.style.display; // Hidden buttons should stay hidden.
          btn.style.cssText = btnCssText;
          btn.style.display = _d;
          
        }
      );
      
    } // Namespace ends.
    
      

    Button Styled Links

    first second

提交回复
热议问题