body样式不级联到按钮



查看以下 HTML,用于演示目的:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Untitled</title>
        <link rel="stylesheet" href="css/style.css">
        <link rel="author" href="humans.txt">
        <style>
            body {
                padding: 0;
                margin: 0;
                font-family: verdana;
                font-size: 2em;
                color: #444;
            }
            .primary-btn {
                color: #eee;
                outline:none;
                border:none;
                padding:10px 20px;
                text-transform: uppercase;
                cursor: pointer;
                text-shadow: 1px 1px 1px rgba(0,0,0,.3);
                display: block;
                background: tomato;
                margin: 0 auto;
                font-weight: bold;
            }
            .modal {
                height: 200px;
                max-width: 400px;
                border-radius: 5px;
                line-height: 200px;
                text-align: center;
                margin: 30px auto;
                -webkit-box-shadow: 1px 1px 4px rgba(0,0,0,.1);
                box-shadow: 1px 1px 4px rgba(0,0,0,.1);
                -webkit-transition:  .5s;
                -o-transition:  .5s;
                transition:  .5s;
                position: relative;
                border: 1px solid rgba(0,0,0,.2);
                text-transform: uppercase;
            }
            .fade {
                transform: translate(0 , -50px);
                opacity: 0;
            }
            .in {
                transform: translate(0 , 0px);
                opacity: 1;
            }
        </style>
    </head>
    <body>

        <div class="modal fade" id="modal">
                Hey i am a modal        
        </div>
        <button data-toggle="#modal" class="primary-btn">Show Modal</button>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script src="js/smallest-modal.js"></script>
    </body>
</html>

来自 <body> 标签的以下样式没有级联到 button 元素,所以我必须将它们显式应用于<button>

font-family: verdana;
font-size: 2em;
color: #444;

有什么问题??

body 元素与您的按钮无关。或者你需要这样做:为什么不从正文继承字体?

如果你使用"身体",你是在对身体元素说话,而不是里面的东西。如果你使用类,你可以给多个元素相同的CSS,如果你使用id,你可以只与那个元素说话。

最新更新