2017-06-09 3 views
1

私は私のサイトに持っていきたいこのトグルスイッチを持っています。トグルスイッチにCSSの枠線を適用すると、このギザギザの境界がどのように修正されますか?

https://jsfiddle.net/njxfnfoa/

<div class="switch-container"> 
    <label class="switch"> 
     <input type="checkbox"> 
     <div class="slider round"></div> 
    </label> 
</div> 

とCSSの長さであるので、私はちょうどJSFiddleでそれをしておこう。

しかし、あなたはそれがかなりギザギザに見えることがわかります。私が作業しているPDFデザインはこのように見えます。

toggle switch

どのように私はより良いこのなめらかな境界線を複製することができますか?

+0

あなたのスクリーン/コンピュータに依存して、MacBook ProのImは非常に滑らかに見えます。 – Zac

+0

灰色の境界線で表示されない - https://jsfiddle.net/njxfnfoa/3/ – Pete

答えて

1

使用border: 1px solid rgba(211,211,211, .8);はそうあなたがボーダー不透明度(ここでは0.8)を制御

.switch-container{ 
 
    position:relative; 
 
} 
 

 
.switch { 
 
    position: relative; 
 
    display: inline-block; 
 
    width: 65px; 
 
    height: 34px; 
 
} 
 

 
/* Hide default HTML checkbox */ 
 
.switch input { 
 
    display: none; 
 
} 
 

 
/* The slider */ 
 
.slider { 
 
    position: absolute; 
 
    cursor: pointer; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    background-color: white; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
    border: 1px solid rgba(211,211,211, .8); 
 
} 
 

 
.slider:before { 
 
    position: absolute; 
 
    content: ""; 
 
    height: 32px; 
 
    width: 32px; 
 
    left: 0px; 
 
    background-color: #73c82b; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
input:checked + .slider { 
 
    background-color: white; 
 
} 
 

 
input:focus + .slider { 
 
    box-shadow: 0 0 1px white; 
 
} 
 

 
input:checked + .slider:before { 
 
    -webkit-transform: translateX(31px); 
 
    -ms-transform: translateX(31px); 
 
    transform: translateX(31px); 
 
} 
 

 
/* Rounded sliders */ 
 
.slider.round { 
 
    border-radius: 34px; 
 
} 
 

 
.slider.round:before { 
 
    border-radius: 50%; 
 
}
<div class="switch-container"> 
 
          <label class="switch"> 
 
           <input type="checkbox"> 
 
           <div class="slider round"></div> 
 
          </label> 
 
         </div>
を持っています

+1

素敵な、ありがとう。それが許せば答えを受け入れる。 –

+0

@Geesh_SO cool、少し更新しました。= D –

0
あなたは少し微調整する

.slider:before 

でCSSを必要とする

js fiddle

関連する問題