【发布时间】:2019-06-13 10:59:38
【问题描述】:
我已经尝试了 position:fixed 的 css 属性。我也试过position:sticky, top:0,但标题不固定。
这是我的代码,如你所见,我使用 react 和 antd 作为组件库。
import * as React from "react";
import { render } from "react-dom";
import { Row, Col } from "antd";
import "./styles.css";
function App() {
return (
<div>
<Row className="header">
<Col
span={24}
style={{
background: "#0392FD",
position: "sticky",
top: 0
}}
>
<div>
<Row>
<Col>Col1</Col>
<Col>Col1</Col>
<Col>Col1</Col>
</Row>
</div>
</Col>
</Row>
<Row className="content">
<Col span={24} style={{ height: "120vh" }}>
Content
</Col>
</Row>
</div>
);
}
const rootElement = document.getElementById("root");
render(<App />, rootElement);
这是我的 CSS:
.App {
font-family: sans-serif;
text-align: center;
}
我知道有很多解决方案,我尝试了很多。
【问题讨论】:
-
添加minimal reproducible example 在问题本身,而不仅仅是指向外部资源的链接(可能因其他原因离线、被阻止或无法访问... )
-
尝试使用位置:固定!重要
-
position: fixed; top: 0; width: 100%应该可以工作。 -
您的样式应用于标题内的列,而不是标题 div