【发布时间】:2021-10-19 01:20:39
【问题描述】:
我正在尝试使用 Routes 更改 React 应用程序中的页面。这是我的 App.js:
import './App.css';
import Notifications from "./Components/Notifications";
import Home from "./Components/Home";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
function App() {
return (
<div className="App">
<Router>
<header className="appHeader">
<Link to="/" className="logoLink">
<img className="logo"/>
</Link>
<div className="headerLinks">
<li>
<Link className="notificationsLink" to="/notifications"> Notifications </Link>
</li>
<li>
<Link className="updatesLink" to="/updates"> Updates </Link>
</li>
<li>
<Link className="searchLink" to="/search"> Search </Link>
</li>
<Route path="/" component={Home} />
<Route exact path="/notifications" component={Notifications} />
<Route path="/updates" component={Notifications} />
<Route path="/search" component={Notifications} />
</div>
</header>
</Router>
</div>
);
}
export default App;
这是logoLink的css:
.logoLink {
background-color: pink;
width: 55px;
height: 55px;
left: calc(50% - 27.5px);
position: relative;
display: inline-block;
margin-top: 2.5px;
}
链接大小为 55 x 55 像素,所有链接都应该是可点击的。但只有一半(我假设 27.5px)是可点击的。以下是展示这一点的图片:
如您所见,只有链接的左半部分是可点击的。我该如何解决这个问题?
【问题讨论】:
-
为什么要在css中添加
left? -
所以它位于屏幕中间
-
删除左边的属性并设置 display: flex;宽度:100%
-
或者简单的 text-align: center; if width: 100% 会破坏你的布局
-
text-align: center 不在屏幕上居中,宽度 100% 意味着整个屏幕都可以点击
标签: css reactjs react-router-dom