2017-01-22 15 views
1

だから私は、コードのこの部分を持っている:CSSで背景上書きを停止するにはどうすればよいですか?

.active { 
 
\t background-color: black; 
 
\t color: white; 
 
} 
 
span { 
 
\t margin: 10px; 
 
} 
 
a { 
 
\t text-decoration: none; 
 
} 
 
.center { 
 
\t position: absolute; 
 
\t top: 50%; 
 
\t left: 50%; 
 
\t transform: translate(-50%, -50%); 
 
} 
 
.tabButton { 
 
\t margin: 2px; 
 
\t padding: 5px 10px; 
 
\t border: 1px solid black; 
 
\t cursor: pointer; 
 
\t background-color: white; 
 
} 
 
#shop, var { 
 
\t font-style: normal; 
 
} 
 
button { 
 
\t font-size:15px; 
 
\t margin :3px; 
 
}
<!DOCTYPE HTML> 
 
<!-- 
 
        Idle RPG 
 
        ========== 
 
       Copyrigh Az 2016 
 
       Inprise by Candy Box and A Dark Room 
 
       If you have interest in making more games like this, join my Studio :D 
 
       Studio Group: https://az-gamestudio.slack.com 
 
--> 
 
<!-- 
 
HEY! YOU'RE LOOKING AT THE SOURCE CODE! cheater ;) 
 
You're gotta go through ME, the DEVELOPER if you want to change the CODE!!!! MUAHAHAHAHA 
 
You're not going to past this laser! It burns every thing it TOUCH!!! 
 

 

 
     im one of the player. I tried to cheat but i can't just walk past this laser :( 
 
    \o/ 
 
|/=======================================================================\| 
 
WHAT!! YOU JUST WALK PAST IT???? 
 
UNFAIR!! 
 
Be careful, don't cheat too much... 
 
My code is too easy to change sooooo.... 
 
"You made the developer bored. He gave up." 
 
--> 
 
<HTML style="font-family:sans-serif"> 
 
<head> 
 
<title>Idle RPG</title> 
 
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/> 
 
<script src=Scripts/gameScript.js> </script> 
 
<link rel="stylesheet" href=Scripts/pageStyle.css> 
 
<body> 
 
<div id='tab' style="text-align: center;"> 
 
<a href="index.html"> 
 
    <button class='tabButton active'>Treasure room</button> 
 
</a> 
 
<a href="inventory.html"> 
 
    <button class='tabButton'>Inventory</button> 
 
</a> 
 
<a href="map.html"> 
 
    <button class='tabButton'>Map</button> 
 
</a> 
 
<a href="quest"> 
 
    <button class='tabButton'>Quest</button> 
 
</a> 
 
</div> 
 
<p id="numberOfCoins">You got 0 coin</p> 
 
<p id="numberOfGolds">You mined 0 gold</p> 
 
<button id="get1Coin" onclick="addCoins()">Collect a coin.</button> 
 
<button onclick="throwCoins()">Throw 10 coins away.</button> 
 
<button style=display:none id="add10Coins" onclick="add10Coins()">Get 10 coins.</button> 
 
<br> 
 
<div style=float:right; id="resources"> 
 
<form> 
 
    <fieldset> 
 
    <legend id="resource"><h3>RESOURCES</h3></legend> 
 
    <span>Iron: <var id='numberOfIrons'>0</var> 
 
    <br><br> 
 
    <span>Silver: <var id='numberOfSilver'>0</var> 
 
    <br><br> 
 
    <span>Coal: <var id='numberOfCoal'>0</var> 
 
    <br><br> 
 
    </fieldset> 
 
</form> 
 
</div> 
 
<div id="goldMine"> 
 
    <pre style= border: 3px solid black> 
 
_GOLD MINE_  _IRON MINE_  _GOLD MINE_  _IRON MINE_ 
 
|   |  |   |  |   |  |   | 
 
|   |  |   |  |   |  |   | 
 
    </pre> 
 
</div> 
 
<div style=display:none id="shop"> 
 
\t <pre> 
 
<h2>SHOP</h2> 
 
"Hi, im a blacksmith. I see you have a lot of coins, so i think that you might be interest in my weapons!" 
 
Buy a item to unlock a new item! 
 
<div id='woodenSword'> 
 
Wooden Sword \t \t  
 
    . 
 
/\ 
 
    | | 
 
    | | 
 
    |.| 
 
    |.| 
 
    |:| 
 
    |:| 
 
'--8--' 
 
    8 
 
    O 
 
Cost: 2000 coins  
 
<button id="buyWoodenSword" onclick='boughtWoodenSword();' disabled>Buy</button> 
 
</div> 
 
<div id='ironSword'> 
 
Iron Sword 
 
    . 
 
/\ 
 
    | | 
 
    | | 
 
    |.| 
 
    |.| 
 
    |:| 
 
    |:| 
 
_|*|_ 
 
\--+--/ 
 
    8 
 
    8 
 
    O 
 
Cost: 50 Golds 
 
<button id="buyIronSword" onclick="boughtIronSword();" disabled>Buy</button> 
 
<div> 
 
\t </pre> 
 
</div> 
 
</HTML>

proplemはあなたが見ることができるように、私の「トレジャールーム」ボタン(空白のボタン)は、それが思うもののように作用しない、あります(黒の背景と白のテキスト)にする。私はクラス.tabButtonの背景色は、クラス.activeの黒の背景色を上書きしていると思います。誰かがこれで私を助けてくれますか?ありがとう!

+0

CSSで '!important'を使用して、その文を上書きしないようにします。私はあなたが「トレジャールーム」ボタン*によってどんな要素を意味するかわからない。 –

+0

@ Spencer Wieczorek空白のボタンは、「Treasure room」ボタンです。申し訳ありません。 – AzDeveloper

答えて

1

クイックフィックスは、あなたのCSSに.activeの前で.tabButtonを追加することです:

あなたが !importantルールを使用することができそうで

.tabButton.active { 
 
\t background-color: black; 
 
\t color: white; 
 
} 
 
span { 
 
\t margin: 10px; 
 
} 
 
a { 
 
\t text-decoration: none; 
 
} 
 
.center { 
 
\t position: absolute; 
 
\t top: 50%; 
 
\t left: 50%; 
 
\t transform: translate(-50%, -50%); 
 
} 
 
.tabButton { 
 
\t margin: 2px; 
 
\t padding: 5px 10px; 
 
\t border: 1px solid black; 
 
\t cursor: pointer; 
 
\t background-color: white; 
 
} 
 
#shop, var { 
 
\t font-style: normal; 
 
} 
 
button { 
 
\t font-size:15px; 
 
\t margin :3px; 
 
}
<!DOCTYPE HTML> 
 
<!-- 
 
        Idle RPG 
 
        ========== 
 
       Copyrigh Az 2016 
 
       Inprise by Candy Box and A Dark Room 
 
       If you have interest in making more games like this, join my Studio :D 
 
       Studio Group: https://az-gamestudio.slack.com 
 
--> 
 
<!-- 
 
HEY! YOU'RE LOOKING AT THE SOURCE CODE! cheater ;) 
 
You're gotta go through ME, the DEVELOPER if you want to change the CODE!!!! MUAHAHAHAHA 
 
You're not going to past this laser! It burns every thing it TOUCH!!! 
 

 

 
     im one of the player. I tried to cheat but i can't just walk past this laser :( 
 
    \o/ 
 
|/=======================================================================\| 
 
WHAT!! YOU JUST WALK PAST IT???? 
 
UNFAIR!! 
 
Be careful, don't cheat too much... 
 
My code is too easy to change sooooo.... 
 
"You made the developer bored. He gave up." 
 
--> 
 
<HTML style="font-family:sans-serif"> 
 
<head> 
 
<title>Idle RPG</title> 
 
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/> 
 
<script src=Scripts/gameScript.js> </script> 
 
<link rel="stylesheet" href=Scripts/pageStyle.css> 
 
<body> 
 
<div id='tab' style="text-align: center;"> 
 
<a href="index.html"> 
 
    <button class='tabButton active'>Treasure room</button> 
 
</a> 
 
<a href="inventory.html"> 
 
    <button class='tabButton'>Inventory</button> 
 
</a> 
 
<a href="map.html"> 
 
    <button class='tabButton'>Map</button> 
 
</a> 
 
<a href="quest"> 
 
    <button class='tabButton'>Quest</button> 
 
</a> 
 
</div> 
 
<p id="numberOfCoins">You got 0 coin</p> 
 
<p id="numberOfGolds">You mined 0 gold</p> 
 
<button id="get1Coin" onclick="addCoins()">Collect a coin.</button> 
 
<button onclick="throwCoins()">Throw 10 coins away.</button> 
 
<button style=display:none id="add10Coins" onclick="add10Coins()">Get 10 coins.</button> 
 
<br> 
 
<div style=float:right; id="resources"> 
 
<form> 
 
    <fieldset> 
 
    <legend id="resource"><h3>RESOURCES</h3></legend> 
 
    <span>Iron: <var id='numberOfIrons'>0</var> 
 
    <br><br> 
 
    <span>Silver: <var id='numberOfSilver'>0</var> 
 
    <br><br> 
 
    <span>Coal: <var id='numberOfCoal'>0</var> 
 
    <br><br> 
 
    </fieldset> 
 
</form> 
 
</div> 
 
<div id="goldMine"> 
 
    <pre style= border: 3px solid black> 
 
_GOLD MINE_  _IRON MINE_  _GOLD MINE_  _IRON MINE_ 
 
|   |  |   |  |   |  |   | 
 
|   |  |   |  |   |  |   | 
 
    </pre> 
 
</div> 
 
<div style=display:none id="shop"> 
 
\t <pre> 
 
<h2>SHOP</h2> 
 
"Hi, im a blacksmith. I see you have a lot of coins, so i think that you might be interest in my weapons!" 
 
Buy a item to unlock a new item! 
 
<div id='woodenSword'> 
 
Wooden Sword \t \t  
 
    . 
 
/\ 
 
    | | 
 
    | | 
 
    |.| 
 
    |.| 
 
    |:| 
 
    |:| 
 
'--8--' 
 
    8 
 
    O 
 
Cost: 2000 coins  
 
<button id="buyWoodenSword" onclick='boughtWoodenSword();' disabled>Buy</button> 
 
</div> 
 
<div id='ironSword'> 
 
Iron Sword 
 
    . 
 
/\ 
 
    | | 
 
    | | 
 
    |.| 
 
    |.| 
 
    |:| 
 
    |:| 
 
_|*|_ 
 
\--+--/ 
 
    8 
 
    8 
 
    O 
 
Cost: 50 Golds 
 
<button id="buyIronSword" onclick="boughtIronSword();" disabled>Buy</button> 
 
<div> 
 
\t </pre> 
 
</div> 
 
</HTML>

、あなたのに次のような3210:

.active { 
    background-color: black !important; 
    color: white; 
} 

しかし、私は強く最初の解決策を使用することをお勧めします。

3

あなたのCSSに.active優先権を与える方法はたくさんあります。

  1. 同じ要素の別のクラスを追加します。つまり、 .active.tabButton.activeに置き換えてください。
  2. .tabButtonの場合、CSSの下に.activeのCSSを宣言してください。
  3. 直接子(>)演算子を使用して宣言します。それがここにあなたのCSSの最初の行のみが変更され、作業の抜粋です.active

のCSSルールの後!importantを追加#tab a>.active

  • .activeを置き換えることを意味します。

    .tabButton.active { 
     
    \t background-color: black; 
     
    \t color: white; 
     
    } 
     
    span { 
     
    \t margin: 10px; 
     
    } 
     
    a { 
     
    \t text-decoration: none; 
     
    } 
     
    .center { 
     
    \t position: absolute; 
     
    \t top: 50%; 
     
    \t left: 50%; 
     
    \t transform: translate(-50%, -50%); 
     
    } 
     
    .tabButton { 
     
    \t margin: 2px; 
     
    \t padding: 5px 10px; 
     
    \t border: 1px solid black; 
     
    \t cursor: pointer; 
     
    \t background-color: white; 
     
    } 
     
    
     
    
     
    #shop, var { 
     
    \t font-style: normal; 
     
    } 
     
    button { 
     
    \t font-size:15px; 
     
    \t margin :3px; 
     
    }
    <!DOCTYPE HTML> 
     
    <!-- 
     
            Idle RPG 
     
            ========== 
     
           Copyrigh Az 2016 
     
           Inprise by Candy Box and A Dark Room 
     
           If you have interest in making more games like this, join my Studio :D 
     
           Studio Group: https://az-gamestudio.slack.com 
     
    --> 
     
    <!-- 
     
    HEY! YOU'RE LOOKING AT THE SOURCE CODE! cheater ;) 
     
    You're gotta go through ME, the DEVELOPER if you want to change the CODE!!!! MUAHAHAHAHA 
     
    You're not going to past this laser! It burns every thing it TOUCH!!! 
     
    
     
    
     
         im one of the player. I tried to cheat but i can't just walk past this laser :( 
     
        \o/ 
     
    |/=======================================================================\| 
     
    WHAT!! YOU JUST WALK PAST IT???? 
     
    UNFAIR!! 
     
    Be careful, don't cheat too much... 
     
    My code is too easy to change sooooo.... 
     
    "You made the developer bored. He gave up." 
     
    --> 
     
    <HTML style="font-family:sans-serif"> 
     
    <head> 
     
    <title>Idle RPG</title> 
     
    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/> 
     
    <script src=Scripts/gameScript.js> </script> 
     
    <link rel="stylesheet" href=Scripts/pageStyle.css> 
     
    <body> 
     
    <div id='tab' style="text-align: center;"> 
     
    <a href="index.html"> 
     
        <button class='tabButton active'>Treasure room</button> 
     
    </a> 
     
    <a href="inventory.html"> 
     
        <button class='tabButton'>Inventory</button> 
     
    </a> 
     
    <a href="map.html"> 
     
        <button class='tabButton'>Map</button> 
     
    </a> 
     
    <a href="quest"> 
     
        <button class='tabButton'>Quest</button> 
     
    </a> 
     
    </div> 
     
    <p id="numberOfCoins">You got 0 coin</p> 
     
    <p id="numberOfGolds">You mined 0 gold</p> 
     
    <button id="get1Coin" onclick="addCoins()">Collect a coin.</button> 
     
    <button onclick="throwCoins()">Throw 10 coins away.</button> 
     
    <button style=display:none id="add10Coins" onclick="add10Coins()">Get 10 coins.</button> 
     
    <br> 
     
    <div style=float:right; id="resources"> 
     
    <form> 
     
        <fieldset> 
     
        <legend id="resource"><h3>RESOURCES</h3></legend> 
     
        <span>Iron: <var id='numberOfIrons'>0</var> 
     
        <br><br> 
     
        <span>Silver: <var id='numberOfSilver'>0</var> 
     
        <br><br> 
     
        <span>Coal: <var id='numberOfCoal'>0</var> 
     
        <br><br> 
     
        </fieldset> 
     
    </form> 
     
    </div> 
     
    <div id="goldMine"> 
     
        <pre style= border: 3px solid black> 
     
    _GOLD MINE_  _IRON MINE_  _GOLD MINE_  _IRON MINE_ 
     
    |   |  |   |  |   |  |   | 
     
    |   |  |   |  |   |  |   | 
     
        </pre> 
     
    </div> 
     
    <div style=display:none id="shop"> 
     
    \t <pre> 
     
    <h2>SHOP</h2> 
     
    "Hi, im a blacksmith. I see you have a lot of coins, so i think that you might be interest in my weapons!" 
     
    Buy a item to unlock a new item! 
     
    <div id='woodenSword'> 
     
    Wooden Sword \t \t  
     
        . 
     
    /\ 
     
        | | 
     
        | | 
     
        |.| 
     
        |.| 
     
        |:| 
     
        |:| 
     
    '--8--' 
     
        8 
     
        O 
     
    Cost: 2000 coins  
     
    <button id="buyWoodenSword" onclick='boughtWoodenSword();' disabled>Buy</button> 
     
    </div> 
     
    <div id='ironSword'> 
     
    Iron Sword 
     
        . 
     
    /\ 
     
        | | 
     
        | | 
     
        |.| 
     
        |.| 
     
        |:| 
     
        |:| 
     
    _|*|_ 
     
    \--+--/ 
     
        8 
     
        8 
     
        O 
     
    Cost: 50 Golds 
     
    <button id="buyIronSword" onclick="boughtIronSword();" disabled>Buy</button> 
     
    <div> 
     
    \t </pre> 
     
    </div> 
     
    </HTML>

  • 関連する問題