首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么标题要继承CSS中的正文字体以进行样式设计?

为什么标题要继承CSS中的正文字体以进行样式设计?
EN

Stack Overflow用户
提问于 2022-08-06 06:28:47
回答 3查看 79关注 0票数 0

我正在设计我的网站,我选择双体船和拉托分别作为标题和正文。但是,标题似乎继承了主体的样式,这使得字体和字体大小对于我的标题和段落来说是一样的。我在想,这是一个具体的问题,但我不知道哪里出了问题。

代码语言:javascript
复制
@import url("colors.css");
    
    /*Global Styles
    ------------------------------------------------*/
    html, body {
        margin: 0;
        padding: 0;
        font-family: 'Catamaran', Sans-Serif;
        font-size: 16px;
    }  
    
    p{
        color: var(--dark_text);
    }
    
    img{
        margin: 0;
        padding: 0;
    }
    
    h1 h2 h3 {
        font-family: 'Catamaran', Sans-Serif;
        font-size: 66px;
        margin: 0;
        padding: 0;
        color: var(--dark_red);
    
    }
    
    .content_wrap {
        width: 800px;
        margin: 0 auto;
        padding: 60PX 0;
    }
    
    
    /*Navigation Bar  
    ------------------------------------------------*/  
    #nav ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
        overflow: hidden;
        background-color: #333;
    }
      
    #nav li {
        float: left;
    }
    
    #nav li a {
        display: block;
        color: white;
        text-align: center;
        padding: 14px 16px;
        text-decoration: none;
    }
    
    
    /*Projects 
    ------------------------------------------------*/
    
    
    /*Profile
    ------------------------------------------------*/
    #profile{
        background: var(--dark_red);
        color: var(--white_text);
        text-align: center;
    }
    
    #profile p{
        color: var(--white_text);
    }
    
    #profile .button{
        text-decoration:none;
        color: var(--dark_text);
        background: var(--light_green);
        padding: 6px;
        border: 2px var(--light_green);
        border-radius: 6px;
        display: inline-block;
    }
    
    #profile .button:hover{
        text-decoration:none; 
        background: rgb(241, 227, 228,80);
    }
    
    
    /*Projects 
    ------------------------------------------------*/
    #projects{
        background-color: var(--light_green);
    }
    
    #projects .button{
        text-decoration:none;
        color: var(--white_text);
        background: var(--dark_red);
        padding: 6px;
        border: 2px var(--dark_red);
        border-radius: 6px;
        display: inline-block;
    }
    
    #projects .button:hover{
        text-decoration:none; 
        background: rgb(96, 123, 125, 80);
    }
    
    
    /*Work Experience 
    ------------------------------------------------*/
    #work_experiences{
        background-color: var(--light_red);
    }
    
    #work_experiences p{
        margin: auto;
    }
    
    
    /*Drawings and Paintigs
    ------------------------------------------------*/
    #drawings_paintings{
        margin: 0;
        padding: 0;
    }
    
    
    /*Footer
    ------------------------------------------------*/
    footer{
        margin: 0;
        padding: 0;
        background-color: var(--dark_green) ;
        color: var(--white_text);
    }
    
    footer a{
        color:seashell;
        text-decoration: none;
    }
代码语言:javascript
复制
<!DOCTYPE html>
    <HTML lang="en-US" dir="ltr">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" 
                content="width=device-width, initial-scale=1">
            <meta name="description"
                content="Clycine Yuanqing Hao's personal website and some 
                funny stuffs : )">
            <link href="https://fonts.googleapis.com/css?family=Catamaran|Lato:400i" 
                rel="stylesheet">
            <link href="styles.css" rel="stylesheet">
            <title>Clycine's personal website</title>
            <script src="main.js"></script>
        </head>
     
    <BODY>
        <H1 aria-label="Hello World"> <!--to add CSS code to make this displayed in random positions inside of a rectagle-->
            <div class="grid" aria-hidden="true">
            <span>H</span>
            <span>E</span>
            <span>L</span>
            <span>L</span>
            <span>O</span>
            <span>W</span>
            <span>O</span>
            <span>R</span>
            <span>L</span>
            <span>D</span>
            </div> </H1>
    
    
                         <!--***************** TABLE OF CONTENTS *****************-->
    
    <section id="nav">
        <nav role="navigation"> 
            <ul>
                <li> <a href="/~yhao19">About Me</a></li>
                <li> <a href="cs_related.html">Computer Science related</a></li>
                <li> <a href="drawings_paintings.html">Drawings and Paintings</a></li>
                <li> <a href="funny_stuffs.html">Funny Stuffs</a></li>
            </ul>
        </nav>
    </section>
    
                         <!--***************** PROFILE ******************-->
    <section id="profile">
        <div class="content_wrap">
            <h1>Clycine Yuanqing Hao </h1> 
            <picture>
                <source media="(min-width:600px)"
                        srcset="pictures/cly/behindLilas815x929.JPG">
                <source srcset="pictures/cly/behindLilas546x602.JPG">
                <img src="pictures/cly/behindLilas815x929.JPG" 
                        alt="Clycine next to a lilas tree" 
                        width="163" height="186">
            </picture>
            <h2>CS student + Digital & Conventional Artist</h2>
            <p>As a Computer Science student, I look forward to explore the world of innovation and 
                technology. I am interested in understanding how my knowledge and skills can apply 
                to real-life tech projects. </p>
            <p>As an artist, I am passinoante to discover beauty and to express them in my own way, 
                with a cup of tea in my hand, of course.</p>
            <a class="button" href="file/Yuanqing(Clycine)_Hao_Resume.pdf">Click here to see PDF of my resume</a>
        </div>
    </section>
    
                         <!--***************** PROJECT ******************-->
    <section id="projects">
        <div class="content_wrap">
            <h3 class="title">Projects & Researches</h3>
            <p>Biology research project (written report) - <i>L’hydroponie : une alternative à l’agriculture conventionnelle ?</i></p>
            <p>Language: French</p>
            <blockquote>"The main objectives of this research were to understand how different hydroponic systems
                function and what equipment they require, to acknowledge this technique's limits and
                advantages, to explore the role played by nutrients in plants' growth, and ultimately, to
                determine if hydroponics can be an alternative to conventional agriculture."  
                (Boutiba & Hao, 2019)</blockquote>
            <a class="button" href="file/rapport_final_biologie.pdf">PDF of the research</a> 
        </div>
    </section>
    
                         <!--***************** WORK EXPERIENCES ******************-->
    <section id="work_experiences">
        <div class="content_wrap">
            <h3 class="title">Work Experiences</h3>
            <p>Private French Tutor</p>
            <p>01/2022 to 12/2022</p>
            <p>Individuals – Montréal, Québec</p>
            <ul>
                <li>Offered tutoring for intermediate French learners.</li>
                <li>Helped students learn more about Québec culture through practical conversations.</li>
                <li>Integrated French lessons into real-life scenarios and role-playing.</li>
            </ul>
    
                
            <p>Project Intern</p>
            <p>06/05/2022</p>
            <p>Soteria120 – Calgary, Alberta</p>
            <ul>
                <li>Obtained real-work experience by participating in 
                    a user experience testing for website in Soteria120</li>
                <li>Collaborated with a team of 3 students and program manager 
                    that included data entry (input validations), design validations, 
                    user-experience testing, and quality assurance report writing.</li>
            </ul>
        </div>
    </section>
        
    
    
                    
    <footer>
        <div class="content_wrap">
            <a href="#navbar">Back to the table of contents</a>
            <a href="https://www.mcgill.ca/">McGill University</a>
            <p><pre>Phone number: (819)815-3589         Email: clycinehao@gmail.com </pre> </p>
        </div>
    </footer>
    </BODY>
    
    </HTML>    

非常感谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-08-06 07:06:58

以下内容将包含的CSS规则应用于整个HTML文档(通过html标记):

代码语言:javascript
复制
html, body {
    ...
}  

当您试图将样式规则应用于<h1><h2><h3>元素时,您将这些规则应用于所有<h3>,后者是<h2>元素的后代,而后者又是<h1>元素的后代。

代码语言:javascript
复制
h1 h2 h3 {
    ...
}

相反,用逗号(,)分隔每个标记以按需要应用规则,如下所示:

代码语言:javascript
复制
h1, h2, h3 {
    ...
}
票数 0
EN

Stack Overflow用户

发布于 2022-08-06 06:55:15

使用

代码语言:javascript
复制
h1, h2, h3 {
    font-family: 'Catamaran', Sans-Serif;
    font-size: 66px;
    margin: 0;
    padding: 0;
    color: var(--dark_red);
}

而不是

代码语言:javascript
复制
h1 h2 h3{
    ...
}

(使用逗号(<h1> (,))分隔标题( <h2><h3>)标记。

票数 0
EN

Stack Overflow用户

发布于 2022-08-06 07:15:32

您应用于父级的任何内容也应用于子级,除非您特别更改子属性,否则扩展的HTML树生成器是很好的树结构抓取工具。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73257657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档