Pure css close button

前端 未结 11 489
[愿得一人]
[愿得一人] 2020-12-12 19:51

JSFiddle

Is there any way to make something like the X on that link with pure css?

\"enter

相关标签:
11条回答
  • 2020-12-12 20:06

    I become frustrated trying to implement something that looked consistent in all browsers and went with an svg button which can be styled with css.

    html

    <svg>
        <circle cx="12" cy="12" r="11" stroke="black" stroke-width="2" fill="white" />
        <path stroke="black" stroke-width="4" fill="none" d="M6.25,6.25,17.75,17.75" />
        <path stroke="black" stroke-width="4" fill="none" d="M6.25,17.75,17.75,6.25" />
    </svg>
    

    css

    svg {
        cursor: pointer;
        height: 24px;
        width: 24px;
    }
    svg > circle {
        stroke: black;
        fill: white;
    }
    svg > path {
        stroke: black;
    }
    svg:hover > circle {
        fill: red;
    }
    svg:hover > path {
        stroke: white;
    }
    

    http://jsfiddle.net/purves/5exav2m7/

    0 讨论(0)
  • 2020-12-12 20:06

    Basic idea: For the a.boxclose:

    border-radius: 40px;
    width:20px;
    height 10px;
    background-color: #c0c0c0;
    border: 1px solid black;
    color: white;
    padding-left: 10px;
    padding-top: 4px;
    

    Adding a "X" to the content of the close box.

    http://jsfiddle.net/adzFe/1/

    Quick and dirty, but works.

    0 讨论(0)
  • 2020-12-12 20:06

    You can create close (or any) button on http://www.cssbuttongenerator.com/. It gives you pure css value of button.
    HTML

    <span class="classname hightlightTxt">x</span>
    

    CSS

    <style type="text/css">
    .hightlightTxt {
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      -moz-user-select: none;
    }
    .classname {
        -moz-box-shadow:inset 0px 3px 24px -1px #fce2c1;
        -webkit-box-shadow:inset 0px 3px 24px -1px #fce2c1;
        box-shadow:inset 0px 3px 24px -1px #fce2c1;
        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ffc477), color-stop(1, #fb9e25) );
        background:-moz-linear-gradient( center top, #ffc477 5%, #fb9e25 100% );
        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffc477', endColorstr='#fb9e25');
        background-color:#ffc477;
        -webkit-border-top-left-radius:20px;
        -moz-border-radius-topleft:20px;
        border-top-left-radius:20px;
        -webkit-border-top-right-radius:20px;
        -moz-border-radius-topright:20px;
        border-top-right-radius:20px;
        -webkit-border-bottom-right-radius:20px;
        -moz-border-radius-bottomright:20px;
        border-bottom-right-radius:20px;
        -webkit-border-bottom-left-radius:20px;
        -moz-border-radius-bottomleft:20px;
        border-bottom-left-radius:20px;
        text-indent:0px;
        border:1px solid #eeb44f;
        display:inline-block;
        color:#ffffff;
        font-family:Arial;
        font-size:28px;
        font-weight:bold;
        font-style:normal;
        height:32px;
        line-height:32px;
        width:32px;
        text-decoration:none;
        text-align:center;
        text-shadow:1px 1px 0px #cc9f52;
    }
    .classname:hover {
        background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #fb9e25), color-stop(1, #ffc477) );
        background:-moz-linear-gradient( center top, #fb9e25 5%, #ffc477 100% );
        filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fb9e25', endColorstr='#ffc477');
        background-color:#fb9e25;
    }.classname:active {
        position:relative;
        top:1px;
    }</style>
    /* This button was generated using CSSButtonGenerator.com */
    
    0 讨论(0)
  • 2020-12-12 20:20

    Hi you can used this code in pure css

    as like this

    css

    .arrow {
    cursor: pointer;
    color: white;
    border: 1px solid #AEAEAE;
    border-radius: 30px;
    background: #605F61;
    font-size: 31px;
    font-weight: bold;
    display: inline-block;
    line-height: 0px;
    padding: 11px 3px;
    }
    .arrow:before{
     content: "×";
    }
    

    HTML

    <a href="#" class="arrow"> 
    </a>
    

    ​ Live demo http://jsfiddle.net/rohitazad/VzZhU/

    0 讨论(0)
  • 2020-12-12 20:21

    The disappointing thing here is that the "X" isn't transparent (which is how I would likely create a PNG, at least).

    I put together this quick test. http://jsfiddle.net/UM3a2/22/embedded/result/ which allows you to color the positive space while leaving the negative space transparent. Since it is made entirely of borders it is easy to color since border-color defaults to the text color.

    It doesn't fully support I.E. 8 and earlier (border-radius issues), but it degrades to a square fairly nicely (if you're okay with a square close button).

    It also requires two HTML elements since you are only allowed two pseudo elements per selector. I don't know exactly where I learned this, but I think it was in an article by Chris Coyier.

    <div id="close" class="arrow-t-b">
      Close
      <div class="arrow-l-r"> </div>
    </div>
    
    #close {
      border-width: 4px;
      border-style: solid;
      border-radius: 100%;
      color: #333;
      height: 12px;
      margin:auto;
      position: relative;
      text-indent: -9999px;
      width: 12px;
    }
    #close:hover {
      color: #39F;
    }
    .arrow-t-b:after,
    .arrow-t-b:before,
    .arrow-l-r:after, 
    .arrow-l-r:before {
      border-color: transparent;
      border-style: solid;
      border-width: 4px;
      content: "";
      left: 2px;
      top: 0px;
      position: absolute;
    }
    .arrow-t-b:after {
      border-top-color: inherit;
    }
    .arrow-l-r:after {
      border-right-color: inherit;
      left: 4px;
      top: 2px;
    }
    .arrow-t-b:before {
      border-bottom-color: inherit;
      bottom: 0;
    }
    .arrow-l-r:before {
      border-left-color: inherit;
      left: 0;
      top: 2px;
    }
    
    0 讨论(0)
提交回复
热议问题