reactjs - 将常规引导代码转换为 React Bootstrap 样式的组件
问题描述
我正在关注一个教程,其中有人教我如何编写 Bootstrap 代码。他们使用以下代码创建了一个跨越整个浏览器宽度的顶部栏
CSS
.top-bar {
background: #7aaec4;
height: 2.8rem;
padding: .5rem 0;
}
.topbar a {
color: #fff;
text-decoration: none;
font-size: 1.1rem;
}
HTML 代码
<div class="top-bar">
<div class="container">
<div class="col-12 text-right">
<p>
<a href="tel:+18885555555">Call us at +1 (888) 555-5555</a>
</p>
</div>
</div>
</div>
上面的代码创建了跨越浏览器宽度并具有特定高度的顶部栏。
现在我试图获得相同的行为,但使用 react-bootstrap 和 styled-components。所以我写了这段代码
import React from 'react';
import {Container, Row, Col} from 'react-bootstrap';
import styled from 'styled-components';
const Styles = styled.div`
background: #7aaec4;
height: 2.8rem;
padding: .5rem 0;
text-align: right;
a {
color: #fff;
text-decoration: none;
font-size: 1.1rem;
};
`;
export const TopBar = () => {return (
<Container>
<Styles>
<Row>
<Col xs={12} sm={12} md={12} lg={12} xl={12}>
<a href="tel:+18885555555">Call us at +1 (888) 555-5555</a>
</Col>
</Row>
</Styles>
</Container>
)}
然后最后使用我的组件作为
<React.Fragment>
<GlobalStyles />
<TopBar />
<div>Hello World</div>
</React.Fragment>
我看到顶栏没有在浏览器屏幕上运行。看起来像这样
解决方案
推荐阅读
- swift - Xcode 11 及其新框架(如 SwiftUI)是否需要更改为 .gitignore?
- android - etc2 纹理不适用于 OpenGL ES 3.2
- python - 如何在pyQt5中获取ProgressBar的当前值?
- mysql - 破解表达式
- sql - Sql Server 加载时间过长
- python - 为什么当数据帧上存在混合数据类型时,我不能使用 loc 分配一个值?即有些列有字符串,其他列有数字
- reactjs - 如何通过反应检查字符串是否包含数字
- sql-server - 之前如何用 IF 条件让 SQL 将行作为一个组处理而不是一个接一个?
- firebase - 在 initState 中初始化变量
- javascript - 如何使用 html 选择器选项禁用和启用输入元素