在Reactjs/Nextjs中选择导航项时加粗,可以通过CSS样式来实现。具体步骤如下:
.bold {
font-weight: bold;
}
import React, { useState } from 'react';
const NavigationItem = ({ text }) => {
const [selected, setSelected] = useState(false);
const handleClick = () => {
setSelected(true);
};
return (
<li onClick={handleClick} className={selected ? 'bold' : ''}>
{text}
</li>
);
};
export default NavigationItem;
import React from 'react';
import NavigationItem from './NavigationItem';
const Navigation = () => {
return (
<ul>
<NavigationItem text="Home" />
<NavigationItem text="About" />
<NavigationItem text="Contact" />
</ul>
);
};
export default Navigation;
这样,在Reactjs/Nextjs中选择导航项时,选中的导航项会应用加粗的样式。当用户点击某个导航项时,该导航项的状态会改变为选中状态,从而触发加粗样式的应用。
推荐的腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云