gpt4 book ai didi

reactjs - 悬停时的 React-Bootstrap 下拉菜单

转载 作者:行者123 更新时间:2023-12-03 19:42:56 24 4
gpt4 key购买 nike

我正在我的第一个 react-bootstrap 网站上工作,我注意到导航栏中的下拉菜单不允许在悬停时下拉。

我想知道是否有解决方法。我尝试在我的 CSS 中添加一些代码。
演示 - https://codesandbox.io/s/react-bootstrap-nav-active-link-5v5jq?fontsize=14&hidenavigation=1&theme=dark

/*MENU*/
.dropdown:hover {
display: block;
}
/*END MENU*/

然而,这并没有奏效

这是代码。
import React from 'react';
import {Nav, Navbar, NavDropdown } from 'react-bootstrap';
import '../App.css';

function Header() {
return (
<Navbar bg="transparent" variant="dark" expand="lg">
<Navbar.Brand href="#home" className="App-logo">AdStichr</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto">
<Nav.Link href="#home">Home</Nav.Link>
<Nav.Link href="#link">Link</Nav.Link>
<NavDropdown title="Dropdown" id="basic-nav-dropdown" alignRight>
<NavDropdown.Item href="#action/3.1">Action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.2">Another action</NavDropdown.Item>
<NavDropdown.Item href="#action/3.3">Something</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="#action/3.4">Separated link</NavDropdown.Item>
</NavDropdown>
</Nav>

</Navbar.Collapse>
</Navbar>
)
}
export default Header;

甚至试过这个
const Header = props => {
const { location } = props;
const [isOpen, updateIsOpen] = useState(false);
return (
<Navbar bg="transparent" variant="dark" expand="lg">
<Navbar.Brand href="#home" className="App-logo">AdStichr</Navbar.Brand>
<Navbar.Toggle aria-controls="basic-navbar-nav" />
<Navbar.Collapse id="basic-navbar-nav">
<Nav className="ml-auto" activeKey={location.pathname}>
<Nav.Link href="/">Home</Nav.Link>
<Nav.Link href="/advertisers">Advertisers</Nav.Link>
<NavDropdown title="Publishers" id="basic-nav-dropdown" alignRight
onMouseOver={() => updateIsOpen(true)}
onFocus={() => updateIsOpen(true)}
onMouseLeave={() => updateIsOpen(false)}
onBlur={() => updateIsOpen(false)}
toggle={() => updateIsOpen(!isOpen)}
isOpen={isOpen}>
<NavDropdown.Item href="/publishers/radio">Radio Stations</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="/publishers/podcasters">Audio Podcasters</NavDropdown.Item>
<NavDropdown.Divider />
<NavDropdown.Item href="/publishers/videopodcasters">Video Podcasters</NavDropdown.Item>
</NavDropdown>
<Nav.Link href="/case-studies">Case Studies</Nav.Link>
<Nav.Link href="/contact">Contact</Nav.Link>
</Nav>

</Navbar.Collapse>
</Navbar>
);
};
const HeaderWithRouter = withRouter(Header);
export default HeaderWithRouter;

但没有成功。

最佳答案

const [show, setShow] = useState(false);
const showDropdown = (e)=>{
setShow(!show);
}
const hideDropdown = e => {
setShow(false);
}
  <NavDropdown title="Dropdown" 
id="collasible-nav-dropdown"
show={show}
onMouseEnter={showDropdown}
onMouseLeave={hideDropdown}
>
我已将其用于在 React Bootstrap 中悬停时打开下拉菜单。

关于reactjs - 悬停时的 React-Bootstrap 下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60373789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com