2017-07-03 6 views
1

ラジオボタンのラベルにカーソルを合わせると、太字になります。しかし、これにより、コンテナの幅が変更されます。最新の主要なブラウザのすべてのバージョンで動作するラベルが太字である場合、同じコンテナ幅を維持する必要がありますか?ここでホバー上でラベルを太字にすると、コンテナが移動します

jfiddle link

私のhtmlコードです:テキストを太字に見えるようにする

.input-wrapper { 
    margin-right: 30px; 
} 

.input-wrapper label { 
    position: relative; 
    cursor: pointer; 
} 

.input-wrapper label:hover { 
    font-weight: bold; 
    transition: 0.3s font-weight; 
} 

.input-wrapper span::before, 
.input-wrapper span::after { 
    content: ''; 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    margin: auto; 
} 

.input-wrapper span::hover { 
    cursor: pointer; 
} 
.input-wrapper span::before { 
    left: -20px; 
    width: 17px; 
    height: 17px; 
    background-color: white; 
    border-radius: 50px; 
} 

input[type="radio"] { 
    display: none; 
} 

input[type="radio"]:checked + label span::after { 
    left: -17px; 
    width: 11px; 
    height: 11px; 
    border-radius: 10px; 
    background-color: #98fbc9; 
    transition: left .25s, background-color .25s; 
} 

.group-label { 
    margin-right: 30px; 
    text-transform:uppercase; 
} 
+0

あなたは私の答えを受け入れて、今、あなたはそれを同じ – LKG

+0

のに関するすべての問題を取り除くはい、すべての入力ラッパーの間の間隔は、常にこのソリューションによって変化するであろうと思われます。 https://jsfiddle.net/7gL038jd/9/ – feychou

+0

スペースを必要としない場合は、 'max-width'を再利用することができます。 – LKG

答えて

1

使用テキストの影:

<form> 
    <div> 
    <b class="group-label">from</b> 
    <span class="input-wrapper"> 
     <input type="radio" id="from-hiragana" name="from" value="true"> 
     <label for="from-hiragana"> 
     <span>Hiragana</span> 
     </label> 
    </span> 
    <span class="input-wrapper"> 
     <input type="radio" id="from-katakana" name="from" value="true"> 
     <label for="from-katakana"> 
     <span>Katakana</span> 
     </label> 
    </span> 
    <span class="input-wrapper"> 
     <input type="radio" id="from-romaji" name="from" value="true"> 
     <label for="from-romaji"> 
     <span>Romaji</span> 
     </label> 
    </span> 
    </div> 
</form> 

そして、ここでは私のCSSコードです。あなただけの固定にラベルの位置を変更し、ラッパーのあなたの余白を右に拡張することができjsfiddle

.input-wrapper label:hover { 
    /* font-weight: bold; */ 
    text-shadow:1px 0px 0px black; 
    transition: 0.3s text-shadow; 
} 
+0

クロスブラウザは非常に広範なステートメントなので、IE 9以降ではこれが失敗することに注意してください。 http://caniuse.com/#feat=css-textshadow –

+0

私の質問が更新されました。重要なことは、それが最近の主要なすべてのブラウザで動作することです。 – feychou

1

を参照してください。

.input-wrapper { 
    margin-right: 100px; 
} 

.input-wrapper label { 
    position: fixed; 
    cursor: pointer; 
} 
1

あなたはあなたが

CSSを以下のようにmax-widthflexにより取得することができます

fiddle link

を次のようにtext-shadowを使用して、それを得る

.input-wrapper label:hover { 
    /* font-weight: bold; */ 
    text-shadow:1px 0px 0px #000; 
    transition: all 0.3s linear; 
} 
を変更します

.input-wrapper { 
 
    margin-right: 30px; 
 
} 
 

 
.input-wrapper label { 
 
    position: relative; 
 
    cursor: pointer; 
 
} 
 

 
.input-wrapper label:hover { 
 
    /* font-weight: bold; */ 
 
    text-shadow:1px 0px 0px #000; 
 
    transition: all 0.3s linear; 
 
} 
 

 
.input-wrapper span::before, 
 
.input-wrapper span::after { 
 
    content: ''; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    margin: auto; 
 
} 
 

 
.input-wrapper span::hover { 
 
    cursor: pointer; 
 
} 
 
.input-wrapper span::before { 
 
    left: -20px; 
 
    width: 17px; 
 
    height: 17px; 
 
    background-color: white; 
 
    border-radius: 50px; 
 
} 
 

 
input[type="radio"] { 
 
    display: none; 
 
} 
 

 
input[type="radio"]:checked + label span::after { 
 
    left: -17px; 
 
    width: 11px; 
 
    height: 11px; 
 
    border-radius: 10px; 
 
    background-color: #98fbc9; 
 
    transition: left .25s, background-color .25s; 
 
} 
 

 
.group-label { 
 
    margin-right: 30px; 
 
    text-transform:uppercase; 
 
}
<form> 
 
    <div> 
 
    <b class="group-label">from</b> 
 
    <span class="input-wrapper"> 
 
     <input type="radio" id="from-hiragana" name="from" value="true"> 
 
     <label for="from-hiragana"> 
 
     <span>Hiragana</span> 
 
    </label> 
 
    </span> 
 
    <span class="input-wrapper"> 
 
     <input type="radio" id="from-katakana" name="from" value="true"> 
 
     <label for="from-katakana"> 
 
     <span>Katakana</span> 
 
    </label> 
 
    </span> 
 
    <span class="input-wrapper"> 
 
     <input type="radio" id="from-romaji" name="from" value="true"> 
 
     <label for="from-romaji"> 
 
     <span>Romaji</span> 
 
    </label> 
 
    </span> 
 
    </div> 
 
</form>

関連する問題