我有一个应用程序,有两个页面,其中一个是主屏幕,我们称之为主屏幕(默认页面,或者更确切地说,当所有其他页面加载时,应该显示的页面,使用react router的Outlet组件),而另一个是另一个页面,称为other.

现在我在主屏幕上的页面底部有一些文本,但是,如果另一个屏幕中的文本超过了页面的长度,那么应该出现在页面底部的文本实际上与另一个屏幕中的文本重叠.

Example

这是我的意思的一个例子,无论我实际上 Select 了什么页面,wine 吧、电话号码和邮箱都应该在那里,理论上应该向下推,但它们是重叠的

代码:这是主文件:

import './App.css';
import Sidebar from './components/sidebar';
import { Outlet } from 'react-router-dom';

export default function App() {
  return (
    <div className="App" id="outer-container">
      <Sidebar />

      <hr id='line' />
      <p id='p'>Phone: +1 (XXX) XXX-XXXX</p>
      <p id='p2'>Email: XXXXX@XXXXX.com</p>
      <p id='p3'>Follow me on:</p>
      <Outlet />
    </div>
  );
}

其对应的CSS文件为:

hr#line {
    position: absolute;
    width: calc(100vw - 46px);
    height: 0px;
    left: 23px;
    right: 23px;
    top: 80vh;

    border: 1px solid #000000;
}

p#p {
    position: absolute;
    width: 20vw;
    height: 34px;
    left: 19px;
    top: 85vh;

    font-family: 'PT Serif';
    font-style: normal;
    font-weight: 400;
    font-size: 13px;
    line-height: 95.52%;

    /* or 12px */

    color: #000000;
}

p#p2 {
    position: absolute;
    width: 20vw;
    height: 34px;
    left: calc(50vw - 10vw);
    top: 85vh;

    font-family: 'PT Serif';
    font-style: normal;
    font-weight: 400;
    font-size: 13px;
    line-height: 95.52%;

    /* or 12px */

    color: #000000;
}

p#p3 {
    position: absolute;
    width: 20vw;
    height: 34px;
    left: calc(100vw - 20vw);
    top: 85vh;

    font-family: 'PT Serif';
    font-style: normal;
    font-weight: 400;
    font-size: 13px;
    line-height: 95.52%;

    color: #000000;
}

对于我描述的"其他文件",我们有:

export default function About() {
    return (
      <div className="about-container">
        <div className='peach-gradient color-block-5 mb-3 mx-auto rounded-circle z-depth-1 upper-about'>
          <h2>About</h2>
        </div>
          <p>
The standard Lorem Ipsum passage, used since the 1500s

"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC

"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
1914 translation by H. Rackham

"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC

"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
1914 translation by H. Rackham

"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."
</p>
      </div>
    );
  }

此文件没有CSS

推荐答案

如果我正确理解了你的问题和要求,那么你似乎希望有一个"页脚",它"粘"在页面底部,直到有足够的内容将其向下推.为此,我建议重构组件容器并改进CSS样式.

例子:

创建页脚组件:

const Footer = () => (
  <footer>
    <hr />
    <div className="row">
      <p>Phone: +1 (XXX) XXX-XXXX</p>
      <p>Email: XXXXX@XXXXX.com</p>
      <p>Follow me on:</p>
    </div>
  </footer>
);

更新应用程序容器组件:

const App = () => (
  <div className="outer-container">
    ...
    <div className="page">
      <Outlet />
    </div>
    <Footer />
  </div>
);

CSS

.outer-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page {
  flex: 1;
}

footer {
  position: relative;
  margin: 0 1rem;
}

footer .row {
  display: flex;
  flex-direction: row;
  width: 100%;
  justify-content: space-between;
}

hr {
  height: 0px;
  margin: 0;
  border: 1px solid #000000;
}

footer p {
  width: 20vw;
  height: 34px;

  font-family: 'PT Serif';
  font-style: normal;
  font-weight: 400;
  font-size: 13px;
  line-height: 95.52%;
  
  color: #000000;
}

工作原理

"outer-container" div的最小高度是填充屏幕,而嵌套的"page" div包裹Outlet并增长以填充可用空间.当"page" div中有足够的内容时,它将溢出并向下推页脚元素.

Edit how-to-make-sure-content-stays-below-when-using-react-router-and-outlet

通过调整视图宽度在Sandbox 中进行测试,使"关于"页面的lorem ipsum文本在高度方向上增长/收缩,从而将页脚向下推或粘到底部.

Css相关问答推荐

Vue3日期 Select 器:作用域样式不起作用

悬停时可展开的按钮与屏幕右侧对齐,如何保持未悬停的按钮正确对齐?

如何将Ant设计日期 Select 器的图标设置在输入 Select 器之前而不是之后

将CSS栅格行高设置为其余视口高度

如何为 MUI Slider 字段中 markLabel 的第一个和最后一个实例提供边距?

如何将动态参数从react tsx文件发送到css

在 Shiny 中动态更改 bslib 值框的类

使用 CSS 定位悬停/弹出 div - 字形浏览器网页

CSS 中的 :not(style) ~ :not(style) 是什么?

如何向 Highcharts 迷你图添加具有淡入淡出效果的线性渐变?

在变量中存储匹配 Select 器的子元素的计数

.SVG 文件对象在锚标签下可点击

Angular 以Angular 获取当前聚焦的元素

将框架放入 bootstrap 模式的正确方法是什么?

Nativewind 的某些样式不适用于本机 (Android),但它们适用于网络

卡在 CSS 中的grid-template-columns中

在移动设备上touch 屏幕边缘的元素(Material UI)

如何通过 JavaScript 重新触发 WebKit CSS 动画?

CSS - 使 div 水平对齐

是否允许在链接中嵌套链接?