猿问

使用 html 和 CSS 导航栏周围的边距问题

我正在使用 html 和 CSS 创建一个演示作品集(仍处于最初阶段)。尽管我已在样式表上将全局边距设置为 0,但我的导航栏各边都有边距,但我遇到了问题。我的目标是让导航栏跨越视口的宽度,周围没有边距(底部除外)。我以前没有遇到过这个问题,因此非常感谢您的任何建议!


我的HTML:


<!DOCTYPE html>

<html>

    <head>

        <link rel="stylsheet" type="text/css" href="Personal Portfolio Stylsheet.css">

        <title>Personal Portfolio</title>

    </head>

    <header>

        <nav id="navbar">

            <ul type="none">

                <li href="#About">About</li>

                <li href='#Work'>Work</li>

                <li href='#Contact'>Contact</li>

            </ul>

        </nav>

    </header>

    <body>

        <section id="welcome-section">

            <h1>Liam McBride</h1>

            <h2><i>Web Developer</i></h2>

        </section>

        <section id="projects">

            <h1>Portfolio</h1>

        </section>

        <section id="contact-info">

            <h1>Reach out to me at any of the following links:</h1>

        </section>

    </body>

</html>

和CSS:


@import url('https://fonts.googleapis.com/css?family=EB+Garamond|Roboto&display=swap')


 /* To call fonts, use the following:

  font-family: 'EB Garamond', serif;

font-family: 'Roboto', sans-serif; */

*{

    margin: 0;

    padding: 0;

    box-sizing: border-box;

}

/* Box sizing border box means that padding and border width are included in the total width for all elements. */


:root {

    --color-off-white: #fff6f6;

    --color-aluminum: #c4c4c4; 

    --color-charcoal: #494646;

    --color-black: #1f1919;

    --color-navy: #6385b1;

    --color-deep-water: #1a3861;

}


#navbar{

  width: 100%;

  background-color: var(--color-navy);

  border-bottom: 0.1em solid;

  margin: 0 0 1em 0;

}


nav>ul {

  font-family: 'EB Garamond', serif;

  font-weight: bold;

  font-size:1.15em;

  display: flex;

  justify-content: space-around;

  padding: 0.5em 0.7em 0.1em 50em;

}


header {

  position: relative;

  padding: 0;

}


GCT1015
浏览 103回答 1
1回答

潇潇雨雨

只需将 body 和 nav>ul margin 设置为 0@import url('https://fonts.googleapis.com/css?family=EB+Garamond|Roboto&display=swap')&nbsp;/* To call fonts, use the following:&nbsp; font-family: 'EB Garamond', serif;font-family: 'Roboto', sans-serif; */*{&nbsp; &nbsp; margin: 0;&nbsp; &nbsp; padding: 0;&nbsp; &nbsp; box-sizing: border-box;}body{margin:0;}/* Box sizing border box means that padding and border width are included in the total width for all elements. */:root {&nbsp; &nbsp; --color-off-white: #fff6f6;&nbsp; &nbsp; --color-aluminum: #c4c4c4;&nbsp;&nbsp; &nbsp; --color-charcoal: #494646;&nbsp; &nbsp; --color-black: #1f1919;&nbsp; &nbsp; --color-navy: #6385b1;&nbsp; &nbsp; --color-deep-water: #1a3861;}#navbar{&nbsp; width: 100%;&nbsp; background-color: var(--color-navy);&nbsp; border-bottom: 0.1em solid;&nbsp; margin: 0 0 1em 0;}nav>ul {&nbsp; font-family: 'EB Garamond', serif;&nbsp; font-weight: bold;&nbsp; font-size:1.15em;&nbsp; display: flex;&nbsp; justify-content: space-around;&nbsp; padding: 0.5em 0.7em 0.1em 50em;&nbsp; margin:0;}header {&nbsp; position: relative;&nbsp; padding: 0;}<html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <link rel="stylsheet" type="text/css" href="Personal Portfolio Stylsheet.css">&nbsp; &nbsp; &nbsp; &nbsp; <title>Personal Portfolio</title>&nbsp; &nbsp; </head>&nbsp; &nbsp; <header>&nbsp; &nbsp; &nbsp; &nbsp; <nav id="navbar">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ul type="none">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li href="#About">About</li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li href='#Work'>Work</li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li href='#Contact'>Contact</li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; &nbsp; &nbsp; </nav>&nbsp; &nbsp; </header>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <section id="welcome-section">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1>Liam McBride</h1>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h2><i>Web Developer</i></h2>&nbsp; &nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp; &nbsp; &nbsp; <section id="projects">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1>Portfolio</h1>&nbsp; &nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp; &nbsp; &nbsp; <section id="contact-info">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1>Reach out to me at any of the following links:</h1>&nbsp; &nbsp; &nbsp; &nbsp; </section>&nbsp; &nbsp; </body></html>
随时随地看视频慕课网APP

相关分类

Html5
我要回答