粘性物品与父母有关

发布于 2025-02-01 08:06:30 字数 1542 浏览 2 评论 0原文

我有一个棘手的侧边栏,我想在父母的课程中保留。这停留在内。Inner框。

当前,它溢出到.outside框中。

的JSFIDDLE - https://jsfiddle.net.net/dky2ebyb3m/10/10/10/10/

这是带有示例 :

<div class="parent">
  <div class="other">

  </div>
  <div class="inner">
    <nav>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
      </ul>
    </nav>
    <div class="content">
      One
    </div>
    <div class="content two">
      TWO
    </div>
    <div class="content three">
      Three
    </div>
  </div>
</div>
<div class="outside">

</div>

scss

.content {
  height: 400px;
  background: red;

  &.two {
    background: green;
  }

  &.three {
    background: grey;
  }
}

.other {
  height: 300px;
  background: yellow;
}

.parent {
  //overflow: hidden;
}

nav {
  position: sticky;
  top: 25%;
  left: 100%;
  height: 0;

  ul {
    display: flex;
    flex-direction: column;

    li {
      list-style: none;
      position: relative;
      background: white;
      width: 80px;
      height: 80px;
      display: block;
      border-radius: 10px;
      color: #f47324;
    }
  }
}

.outside {
  height: 400px;
  background: orange;
}

I have a sticky sidebar that I'm trying to keep inside parent class. That is staying inside the .inner box.

Currently, it is overflowing into the .outside box.

Here is the JSFiddle with an example - https://jsfiddle.net/dky2eb3m/10/

HTML:

<div class="parent">
  <div class="other">

  </div>
  <div class="inner">
    <nav>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
      </ul>
    </nav>
    <div class="content">
      One
    </div>
    <div class="content two">
      TWO
    </div>
    <div class="content three">
      Three
    </div>
  </div>
</div>
<div class="outside">

</div>

SCSS

.content {
  height: 400px;
  background: red;

  &.two {
    background: green;
  }

  &.three {
    background: grey;
  }
}

.other {
  height: 300px;
  background: yellow;
}

.parent {
  //overflow: hidden;
}

nav {
  position: sticky;
  top: 25%;
  left: 100%;
  height: 0;

  ul {
    display: flex;
    flex-direction: column;

    li {
      list-style: none;
      position: relative;
      background: white;
      width: 80px;
      height: 80px;
      display: block;
      border-radius: 10px;
      color: #f47324;
    }
  }
}

.outside {
  height: 400px;
  background: orange;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-08 08:06:30

您希望您的nav在内部,然后可以这样做。

* {
  box-sizing: border-box;
}

body {
  height: 3000px;
}

.content-parent {
  background: purple;
  width: 100%;
}

.sidebar {
  float: left;
  position: sticky;
  top: 30px;
}

nav ul {
  display: flex;
  flex-direction: column;
}
nav ul li {
  list-style: none;
  /* order: 999; */
  position: relative;
  background: white;
  width: 80px;
  height: 80px;
  display: block;
  border-radius: 10px;
  cursor: pointer;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  color: #f47324;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.outside {
  height: 400px;
  background: orange;
}

.content {
  height: 400px;
  background: red;
}
.content.two {
  background: green;
}
.content.three {
  background: grey;
}

.other {
  height: 300px;
  background: yellow;
}
<div class="container">
  <div class="sidebar">
    <nav>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
      </ul>
    </nav>
  </div>
  <div class="content-parent">
    <div class="content">
      One
    </div>
    <div class="content two">
      TWO
    </div>
    <div class="content three">
      Three
    </div>
  </div>
</div>
<div class="outside">

</div>

You want your nav to be inside then you can do that like this.

* {
  box-sizing: border-box;
}

body {
  height: 3000px;
}

.content-parent {
  background: purple;
  width: 100%;
}

.sidebar {
  float: left;
  position: sticky;
  top: 30px;
}

nav ul {
  display: flex;
  flex-direction: column;
}
nav ul li {
  list-style: none;
  /* order: 999; */
  position: relative;
  background: white;
  width: 80px;
  height: 80px;
  display: block;
  border-radius: 10px;
  cursor: pointer;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  color: #f47324;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.outside {
  height: 400px;
  background: orange;
}

.content {
  height: 400px;
  background: red;
}
.content.two {
  background: green;
}
.content.three {
  background: grey;
}

.other {
  height: 300px;
  background: yellow;
}
<div class="container">
  <div class="sidebar">
    <nav>
      <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
      </ul>
    </nav>
  </div>
  <div class="content-parent">
    <div class="content">
      One
    </div>
    <div class="content two">
      TWO
    </div>
    <div class="content three">
      Three
    </div>
  </div>
</div>
<div class="outside">

</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文