首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CSS内容溢出Div

CSS内容溢出Div
EN

Stack Overflow用户
提问于 2021-03-28 23:47:35
回答 2查看 49关注 0票数 0

我正在尝试创建我的第一个从头开始的博客格式的网页。到目前为止,我的页眉/功能/侧边栏/页脚似乎表现良好,但我在两点上遇到了困难。我的导航栏链接不想停留在导航div中,功能部分中的flex-box也不想以行的形式出现。

导航栏是更令人头疼的地方,所以我们非常感谢你在这方面的具体帮助。如果你能同时解决这两个问题,那就更好了:)

谢谢!

代码语言:javascript
运行
复制
/* ----------------------------- */


/* BASIC SETUP */


/* ----------------------------- */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  color: rgb(13, 56, 0);
}

html {
  /* background-color: rgb(179, 223, 198); */
  font-family: "Lato", "Arial", sans-serif;
  /* this is the imported font */
  font-weight: 300;
  font-size: 20px;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}


/* ----------------------------- */


/* NAVIGATION */


/* ----------------------------- */

.main-nav {
  display: flex;
  flex-direction: row;
  list-style: none;
  margin-top: 55px;
  justify-content: center;
}

.main-nav li {
  /* this selects all li elements in .main-nav */
  display: inline-block;
  margin-left: 40px;
}

.main-nav li a:link,
.main-nav li a:visited {
  /* this selects the a tags inside each .main-nav li element */
  padding: 8px 0;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 90%;
  border-bottom: 2px solid transparent;
  transition: border-bottom 0.2s;
}

.main-nav li a:hover,
.main-nav li a:active {
  border-bottom: 2px solid rgba(13, 56, 0, 0.933);
}

#nav {
  border: 0.5px solid rgb(94, 2, 2);
  display: flex;
  flex-direction: row;
  justify-self: center;
  width: 100%;
  grid-area: nav;
}


/* ----------------------------- */


/* MAIN GRID & FLEX */


/* ----------------------------- */

.container {
  display: grid;
  width: 100vw;
  height: 100vh;
  grid-template-columns: 25% 25% 25% 25%;
  grid-template-rows: 5vh 10vh 70vh 10vh;
  grid-template-areas: "nav nav nav nav" "header header header header" "main main main sidebar" "footer footer footer footer";
  grid-gap: 5px;
  padding: 10px;
  border: 2px solid #000000;
  justify-content: center;
}

.box {
  display: grid;
  justify-content: center;
  align-items: center;
  background-color: #ffffff;
}

#b1 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 1;
  grid-area: header;
}

#b2 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 2;
  grid-area: main;
}

#b3 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 3;
  grid-area: sidebar;
}

#b4 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 4;
  grid-area: footer;
}


/* ----------------------------- */


/* FEATURE FLEX */


/* ----------------------------- */

.feature {
  display: flex;
  flex-direction: row;
  justify-content: center;
  border: 1px solid #000000;
}

#f1 {
  order: 1;
}

#f2 {
  order: 2;
}

#f3 {
  order: 3;
}

#f4 {
  order: 4;
}
代码语言:javascript
运行
复制
<!DOCTYPE html>
<html lang="en">
<html>

<head>
  <meta charset="UTF-8" />
  <title>Exercise 1</title>
  <meta content="width=device-width, initial-scale=1, maxium-scale=1" name="viewport" />
  <link rel="stylesheet" type="text/css" href="style.css" />
  <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;1,300&display=swap" />
  <link rel="preconnect" href="https://fonts.gstatic.com" />
</head>

<body>
  <div class="container">
    <div class="box" id="nav">
      <ul class="main-nav">
        <li>
          <a href="#">Home</a>
        </li>
        <li>
          <a href="#">Search</a>
        </li>
        <li>
          <a href="#">Archive</a>
        </li>
        <li>
          <a href="#">Other</a>
        </li>
      </ul>
    </div>
    <div class="box" id="b1">This is the Title Page of my Project.</div>
    <div class="box" id="b2">
      <article class="feature" id="f1">One</article>
      <article class="feature" id="f2">Two</article>
      <article class="feature" id="f3">Three</article>
      <article class="feature" id="f4">Four</article>
    </div>
    <div class="box" id="b3">
      This will be the right-hand Content column.
    </div>
    <div class="box" id="b4">This is the Footer of my project.</div>
  </div>
</body>

</html>

</html>

EN

回答 2

Stack Overflow用户

发布于 2021-03-29 00:01:51

.main-nav删除页边距顶部,.box将显示更改为显示: flex;这应该可以解决您的问题。

票数 1
EN

Stack Overflow用户

发布于 2021-03-29 00:05:11

基于@BrentOwen的答案是工作片段。

代码语言:javascript
运行
复制
/* BASIC SETUP */


/* ----------------------------- */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
  color: rgb(13, 56, 0);
}

html {
  /* background-color: rgb(179, 223, 198); */
  font-family: "Lato", "Arial", sans-serif;
  /* this is the imported font */
  font-weight: 300;
  font-size: 20px;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}


/* ----------------------------- */


/* NAVIGATION */


/* ----------------------------- */

.main-nav {
  display: flex;
  flex-direction: row;
  list-style: none;
  justify-content: center;
}

.main-nav li {
  /* this selects all li elements in .main-nav */
  display: inline-block;
  margin-left: 40px;
}

.main-nav li a:link,
.main-nav li a:visited {
  /* this selects the a tags inside each .main-nav li element */
  padding: 8px 0;
  text-decoration: none;
  text-transform: uppercase;
  font-size: 90%;
  border-bottom: 2px solid transparent;
  transition: border-bottom 0.2s;
}

.main-nav li a:hover,
.main-nav li a:active {
  border-bottom: 2px solid rgba(13, 56, 0, 0.933);
}

#nav {
  border: 0.5px solid rgb(94, 2, 2);
  display: flex;
  flex-direction: row;
  justify-self: center;
  width: 100%;
  grid-area: nav;
}


/* ----------------------------- */


/* MAIN GRID & FLEX */


/* ----------------------------- */

.container {
  display: grid;
  width: 100vw;
  height: 100vh;
  grid-template-columns: 25% 25% 25% 25%;
  grid-template-rows: 5vh 10vh 70vh 10vh;
  grid-template-areas: "nav nav nav nav" "header header header header" "main main main sidebar" "footer footer footer footer";
  grid-gap: 5px;
  padding: 10px;
  border: 2px solid #000000;
  justify-content: center;
}

.box {
  display: grid;
  justify-content: center;
  align-items: center;
  background-color: #ffffff;
}

#b1 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 1;
  grid-area: header;
}

#b2 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 2;
  grid-area: main;
}

#b3 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 3;
  grid-area: sidebar;
}

#b4 {
  border: 0.5px solid rgb(94, 2, 2);
  order: 4;
  grid-area: footer;
}


/* ----------------------------- */


/* FEATURE FLEX */


/* ----------------------------- */

.feature {
  display: flex;
  flex-direction: row;
  justify-content: center;
  border: 1px solid #000000;
}

#f1 {
  order: 1;
}

#f2 {
  order: 2;
}

#f3 {
  order: 3;
}

#f4 {
  order: 4;
}
代码语言:javascript
运行
复制
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>Exercise 1</title>
  <meta content="width=device-width, initial-scale=1, maxium-scale=1" name="viewport" />
  <link rel="stylesheet" type="text/css" href="style.css" />
  <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;1,300&display=swap" />
  <link rel="preconnect" href="https://fonts.gstatic.com" />
</head>

<body>
  <div class="container">
    <div class="box" id="nav">
      <ul class="main-nav">
        <li>
          <a href="#">Home</a>
        </li>
        <li>
          <a href="#">Search</a>
        </li>
        <li>
          <a href="#">Archive</a>
        </li>
        <li>
          <a href="#">Other</a>
        </li>
      </ul>
    </div>
    <div class="box" id="b1">This is the Title Page of my Project.</div>
    <div class="box" id="b2">
      <article class="feature" id="f1">One</article>
      <article class="feature" id="f2">Two</article>
      <article class="feature" id="f3">Three</article>
      <article class="feature" id="f4">Four</article>
    </div>
    <div class="box" id="b3">
      This will be the right-hand Content column.
    </div>
    <div class="box" id="b4">This is the Footer of my project.</div>
  </div>
</body>

</html>

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

https://stackoverflow.com/questions/66843263

复制
相关文章

相似问题

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