2017-12-15 13 views
0

オンボタン5px border-bottomのアクティブなクラスを追加しています。ボタンサイズが5ピクセル増加します。私はボタンのサイズを増やしたくない。そうする簡単な方法はありますか?ボックスサイズは機能しません。5 pxボーダーがボタンに追加され、ボタンのサイズが増加します。ボックスサイズが機能しない

*, 
 
*:after, 
 
*::before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    width: 100%; 
 
    border: 2px solid blue; 
 
} 
 

 
.button { 
 
    background: black; 
 
    width: 150px; 
 
    border: 0; 
 
    padding: 20px; 
 
    margin: 0; 
 
    color: white; 
 
} 
 

 
.active { 
 
    border-bottom: 5px solid yellow; 
 
}
<div class="container"> 
 
    <button class="button active">button active</button> 
 
    <button class="button">button</button> 
 
</div>

+0

ボックスサイズはボタン/入力タグではサポートされていません – Mahmoud

答えて

0

解決策1:box-shadow

*, 
 
*:after, 
 
*::before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    width: 100%; 
 
    border: 2px solid blue; 
 
} 
 

 
.button { 
 
    background: black; 
 
    width: 150px; 
 
    border: 0; 
 
    padding: 20px; 
 
    margin: 0; 
 
    color: white; 
 
} 
 

 
.active { 
 
    box-shadow: 0 -5px 0 yellow inset 
 
}
<div class="container"> 
 
    <button class="button active">button active</button> 
 
    <button class="button">button</button> 
 
</div>

解決策2:擬似要素::after

*, 
 
*:after, 
 
*::before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    width: 100%; 
 
    border: 2px solid blue; 
 
} 
 

 
.button { 
 
    /* Add Position Relative for Button */ 
 
    position: relative; 
 
    background: black; 
 
    width: 150px; 
 
    border: 0; 
 
    padding: 20px; 
 
    margin: 0; 
 
    color: white; 
 
} 
 

 
.active::after { 
 
    content: ''; 
 
    display: block; 
 
    position: absolute; 
 
    bottom: 0; 
 
    left: 0; 
 
    height: 5px; 
 
    width: 100%; 
 
    background: yellow 
 
}
<div class="container"> 
 
    <button class="button active">button active</button> 
 
    <button class="button">button</button> 
 
</div>

-2

.activeクラスとbox-sizing: border-boxの内側にあなたのボタンheightを宣言します。あなたは......行ってもいいです:)

*, 
 
*:after, 
 
*::before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    width: 100%; 
 
    border: 2px solid blue; 
 
} 
 

 
.button { 
 
    background: black; 
 
    width: 150px; 
 
    border: 0; 
 
    padding: 20px; 
 
    margin: 0; 
 
    color: white; 
 
} 
 

 
.active { 
 
border-bottom: 5px solid yellow; 
 
box-sizing: border-box; 
 
height: 55px; 
 
}
<div class="container"> 
 
    <button class="button active">button active</button> 
 
    <button class="button">button</button> 
 
</div>

+0

誰かが指摘したように、何らかの理由で投票しました。 –

-1

デフォルトボタンのスタイルに黒5pxのボーダーを追加しようと、アクティブなボタンの黄色の色
.button { 
    background: black; 
    border-bottom: 5px solid black; 
    width: 150px; 
    border: 0; 
    padding: 20px; 
    margin: 0; 
    color: white; 
} 

.active { 
    border-bottom: 5px solid yellow; 
} 
-1

私の理解によれば、ボタンの影が必要です。 ボタンの影を使うほうが良いです。

は、あなたが望むようにそれを設定する次に、この

box-shadow: 10px 10px 5px #aaaaaa; 

を使用してください。あなたは ボタン要素に固定の高さを与えている場合borderbox-sizing: border-boxに関して

0

は動作します。固定高さ

解決法1

*, 
 
*:after, 
 
*::before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    width: 100%; 
 
    border: 2px solid blue; 
 
} 
 

 
.button { 
 
    background: black; 
 
    width: 150px; 
 
    border: 0; 
 
    padding: 20px; 
 
    margin: 0; 
 
    color: white; 
 
    height: 53px; 
 
} 
 

 
.button.active { 
 
    border-bottom: 5px solid yellow; 
 
}
<div class="container"> 
 
    <button class="button active">button active</button> 
 
    <button class="button">button</button> 
 
</div>

対処方法2固定高させずに(使用:CSS擬似セレクタ前)

*, 
 
*:after, 
 
*::before { 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
} 
 

 
.container { 
 
    width: 100%; 
 
    border: 2px solid blue; 
 
} 
 

 
.button { 
 
    background: black; 
 
    width: 150px; 
 
    border: 0; 
 
    padding: 20px; 
 
    margin: 0; 
 
    color: white; 
 
    position: relative; 
 
} 
 

 
.button.active:before { 
 
    content: ""; 
 
    border-bottom: 5px solid yellow; 
 
    position: absolute; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
}
<div class="container"> 
 
    <button class="button active">button active</button> 
 
    <button class="button">button</button> 
 
</div>

+0

しかし、問題は、サイズを増やしているボーダーではなく、ボックスサイズを使用しています。ボーリングボックスとボーダーがボックスモデルに含まれています。問題は彼が内高さを減らすことができないように彼が最小高さに達したことです...十分な高さがある場合、境界線を追加しても全体の高さには影響しません。 –

+0

@TemaniAfifの 'border-box-sizing:border-box'に関しては、ボタンに固定された高さを与えても動作しますが、この場合の高さは修正されません。 – Bhuwan

+0

はい私は全部合意しており、高さを指定していないので、要素はコンテンツの高さ(最小高さ)を取得しており、それ以上減少することはできません;)...その理由は、ボックスサイズは機能していません。私たちは高さについての説明を追加する場合は、彼は理解する:) –

関連する問題