首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用react-bulma-component使图像具有响应性

使用react-bulma-component使图像具有响应性
EN

Stack Overflow用户
提问于 2020-04-29 06:08:30
回答 1查看 516关注 0票数 0

我在一个开源项目中使用了react-bulma组件,但我不能在移动设备上使图像响应。

它们应该看起来像这样:

Desktop-view

但它们看起来像这样:

Mobile-view

下面是来自父组件的代码:

代码语言:javascript
复制
const Nomenclature = props => {

  const auth = useContext(AuthContext)

  return (
    <Columns.Column size= "half" breakpoint="desktop">
      <Box>
        <Media>
          <Media.Item renderAs="figure" position="left">
            {props.nomenclature.cards.slice(0, 1).map(card => (
              <Card
                key={card.id}
                alt={card.originalname}
                src={card.location}
                imageCount={props.nomenclature.cards.length}
                images={props.nomenclature.cards}
              />
            ))}
            {auth.isLoggedIn && (
            <Button
              renderAs={Link}
              to={`/nomenclature/${props.nomenclature.id}`}>
              Télécharger
            </Button> )}
          </Media.Item>

          <Media.Item>
            <Content>
            <Heading size={3}>
              {props.nomenclature.name ? props.nomenclature.name : 'sans nom'}
            </Heading>
            <small>Par <strong>{props.nomenclature.author}</strong></small>
            <Tags tags={props.nomenclature.tags} />
            </Content>
          </Media.Item>
        </Media>
      </Box>
    </Columns.Column>
  );
};
export default Nomenclature;

下面是来自子组件的代码:

代码语言:javascript
复制
const Card = props => {
  const cardPreviewImages = props.images.map((image, index) => {
    return (
      <img
        className="image-preview"
        key={index.toString()}
        src={image.location}
        alt={image.alt}/>
    );
  });
  return (
    <div className="thumbnails">
      <div className="image-previews-container">{cardPreviewImages}</div>
      <Tag rounded size="large" className="nomenclature-image-count">
        {props.imageCount}
      </Tag>
      <div className="thumbnail">
        <img src={props.src} alt={props.alt}/>
      </div>
    </div>
  );
};

export default Card;
EN

回答 1

Stack Overflow用户

发布于 2020-04-29 06:17:16

仅仅是css就足够了。如果可以设置大小,则可以执行以下操作:

代码语言:javascript
复制
.container {
  width: 200px;
  height: 200px;
}

.container img {
  width: auto;
  height: auto;
  max-width: 200px;
  max-height: 200px;
}

这当然是一个例子,但如果你提供600x1200px的图像,它会自动缩放以适合你的容器。也许你可以让它适应你的实际代码。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61490804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档