How to style a div like the button-element?

后端 未结 5 1529
南笙
南笙 2021-01-04 13:12

I\'ve noticed that when using the element, the browsers will naturally assume that you want to center the inline content, and that

5条回答
  •  既然无缘
    2021-01-04 14:02

    You don't need multiple divs, check this JSFiddle, it's a single DIV that looks and behaves like a button.

    the HTML:

    this looks like a button

    the CSS:

    .btn{
        display: inline-block;
        padding: 6px 12px;
        margin-bottom: 0;
        font-size: 14px;
        font-weight: 400;
        line-height: 1.42857143;
        text-align: center;
        white-space: nowrap;
        vertical-align: middle;
        -ms-touch-action: manipulation;
        touch-action: manipulation;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        background-image: none;
        border: 1px solid transparent;
        border-radius: 4px;
        text-decoration: none;
    
        color: #333;
        background-color: #fff;
        border-color: #ccc;
    }
    

    If you want the button to actually link to something (behave like a link), simply change your HTML to this:

    
      this looks like a button
    
    

    If you use bootstrap you don't have to define the .btn class, it's included in that.

提交回复
热议问题