【问题标题】:How do you remove text-decoration (underline) on the text in a Bootstrap Card when you make the card clickable?当您使卡片可点击时,如何删除引导卡片中文本上的文本装饰(下划线)?
【发布时间】:2019-03-03 00:05:01
【问题描述】:

我在卡片中添加了一个 onClick 功能,因此您可以转到项目详细信息视图并阅读更多内容并查看更多图像。 onClick 使文本变为蓝色并给它一个下划线。我覆盖了蓝色文本,但当我悬停时似乎无法删除蓝线。

组件:

import React, { Component } from 'react';
import { withRouter } from 'react-router';
import { Card, CardImg, CardText, CardBody,
  CardTitle, CardSubtitle } from 'reactstrap';
import './ItemCard.css';

class ItemCard extends Component {

  render() {

    return (
    <div>
      <Card className="text-center item-card" onClick={this.props.clicked} > 
        <CardImg top width="100%" src={this.props.image} alt="Card image cap" />
        <CardBody className="item-card-body">
          <CardTitle>{this.props.title}</CardTitle>
          <CardSubtitle>${this.props.price}</CardSubtitle>
          <CardText>{this.props.description}</CardText>
        </CardBody>
      </Card>
    </div>
    );
  }
}

export default withRouter(ItemCard);

组件 CSS:

.item-card {
  max-width: 20em;
  flex: 1;
  color: black;
}

.item-card :hover {
  color: black;
  text-decoration: none !important;
}

【问题讨论】:

  • 请不要为了你自己的利益使用 !important :P
  • 如果你需要重写一些包样式,没关系,但是需要在这个地方评论一下,说明你为什么这样做。在所有其他情况下需要避免!important
  • 只是在尝试一些东西。我通常不使用它。现在没了。

标签: css reactjs react-bootstrap


【解决方案1】:

text-decoration没有可继承属性,需要直接设置给子元素:

.item-card {
  max-width: 20em;
  flex: 1;
  color: black;
}

.item-card *:hover {
  color: black;
  text-decoration: none !important;
}

【讨论】:

  • 不太清楚你的意思。但是,如果您的意思是为&lt;Card&gt; 的所有孩子添加一个类并添加text-decoration: none;。它仍然不起作用。我尝试向&lt;CardTitle&gt;text-decoration: none; 添加一个类作为测试,但没有任何改变。
  • 尝试重现您的问题,但没有成功。可能你有一些其他样式覆盖了这个 CSS?
  • 我解决了这个问题。超链接是由我渲染卡片的组件中的路由器链接引起的。我必须在链接中添加一些内联样式来覆盖文本装饰:&lt;Link style={{ textDecoration: 'none' }}
猜你喜欢
  • 1970-01-01
  • 2019-04-15
  • 2014-05-26
  • 2014-10-26
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
  • 2010-10-07
  • 2022-01-20
相关资源
最近更新 更多