css - 如何在 react 样式组件中添加 'title' 标签(用于工具提示)

标签 css reactjs

我在我的 react 应用程序中使用样式组件 我想添加标题属性(用于工具提示) 应用于我的样式组件

我尝试使用包装 div html 元素并在其上应用标题标签,但无法做到这一点,也尝试使用 css`` 样式组件帮助程序无法做到这一点。

my styled components: (with ellipsis):
const FilterTitle = styled.div`
    display: inline-block;
    width: 100%;
    line-height: 40px;
    height: 40px;
    color: ${blackChosen};  
    font-family: Poppins;   
    font-size: 16px;    
    letter-spacing: 0.15px;  
    padding-left: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: ${props => (props.chosen) ? '500' : 'initial'};
`;

and:

<FilterTitle> I might be a long sentence shown with ... and the title tag should tooltip me</FilterTitle>

最佳答案

<FilterTitle>仍在渲染 div因此您可以将任何您想要的属性直接放在该组件上,它们将被传递到 div:

<FilterTitle title="A long sentence, eh?">...

关于css - 如何在 react 样式组件中添加 'title' 标签(用于工具提示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56259123/

相关文章:

css - 如何定位标题,就好像它仍在表格内一样

html - 如何为 img 标签的 alt 属性编写 css (word-break : break-all property doesn't work in IE)

reactjs - React Hook useEffect 缺少依赖项 Props

ios - 世博发布还更新弹出的世博应用程序吗?

c# - 如何在 Visual Studio C# 中将按钮单击事件添加到我自己的按钮

javascript - 我的样式被我用 ajax 得到的 html 覆盖了

javascript - 为什么下拉菜单只能在标题中正常工作?

reactjs - 使用 React Hooks 时来自 ESLint 的警告消息

javascript - 带日期 DD-MM-YYYY 的 Chart.js x 轴 - React

javascript - “Redux”未定义...以及 ReactRedux 和 ReactDOM