侧面导航菜单中的多余空格

问题描述 投票:0回答:1

作为练习,我使用flexbox分别为topnav和CSS Grid 12列布局创建了一个基本网页。我在sidenav上遇到问题,由于某种原因,它有多余的空格?我试图切换到flexbox导航,显示:块等,但我很困惑。应该注意,我对这一切仍然很陌生,显然仍然有很多东西要学习,所以请放轻松。

/* Global styles */

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-size: 16px;
}

body {
  background-color: #d8d8d8;
}

header {
  background-color: #fff;
  color: #000;
  border-bottom: 3px solid #fa58f4;
  position: absolute;
  top: 0;
  width: 100%;
}


/* Top navbar styles */

.topnav ul {
  list-style-type: none;
  display: flex;
  justify-content: center;
}

.topnav li a {
  padding: 12px 12px;
  text-decoration: none;
  color: #000;
}

.topnav a:hover {
  text-decoration: underline;
}


/* about me style */

.text-wrap {
  float: left;
  margin: 5px;
}

.about-me-wrapper>h1 {
  text-align: center;
  text-decoration: underline;
}


/* main content styles */

.content-container {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-gap: 20px;
  margin: 4em 10px;
}

aside {
  grid-column: 1 / 4;
  grid-row: 1;
}

article {
  grid-column: 4 / 10;
  grid-row: 1;
}


/* Side navbar style, still needs work */

.sidebar {
  grid-column: 10 / 13;
  grid-row: 1;
}

.sidebar ul {
  background-color: #fff;
  list-style-type: none;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
}

.sidebar li a {
  text-decoration: none;
  color: #000;
}

.sidebar a:hover {
  text-decoration: underline;
  color: blue;
}

.sidebar ul:hover {
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}

.about-me-wrapper {
  background-color: #fff;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
}

.about-me-wrapper>h1 {
  font-size: 18px;
}

.about-me-wrapper:hover {
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}

.aside-card {
  /*generic card for the left
  hand column -aside- that can be used
  multiple time */
  background-color: #fff;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  transition: 0.3s;
}

.aside-card:hover {
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
}
<header>
  <nav class="topnav">
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">Shop</a></li>
      <li><a href="#">About Us</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
</header>

<div class="content-container">
  <aside>
    <div class="about-me-wrapper">
      <h1>About me</h1>
      <img src="//unsplash.it/100/100" alt="random photo" class="text-wrap">
      <p>A bunch of random words A bunch of random words A bunch of random words A bunch of random words A bunch of random words A bunch of random words</p>
    </div>
    <div class="aside-card">
      <p>Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis,
        luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum</p>
    </div>
    <div class="aside-card">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper
        porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora</p>
    </div>
  </aside>
  <div class="sidebar">
    <ul>
      <li><a href="#">Example 1</a></li>
      <li><a href="#">Example 2</a></li>
      <li><a href="#">Example 3</a></li>
      <li><a href="#">Example 4</a></li>
      <li><a href="#">Example 5</a></li>
      <li><a href="#">Example 6</a></li>
      <li><a href="#">Example 7</a></li>
    </ul>
  </div>
  <article>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper
      porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p>

    <p>Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus
      non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. </p>

    <p>Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse
      potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. </p>

    <p>Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non
      quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet
      mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. </p>

    <p>Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis
      ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. </p>
  </article>
</div>
html css flexbox css-grid
1个回答
0
投票

列表项带有默认的填充/边距缩进(取决于浏览器)。

将此添加到您的代码中:

.sidebar ul {
    background-color: #fff;
    list-style-type: none;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
    transition: 0.3s;
    margin-left: 0;  /* new */
    padding-left: 0; /* new */
}
© www.soinside.com 2019 - 2024. All rights reserved.