繁体   English   中英

为什么 border-radius 对图像不起作用?

[英]Why border-radius doesn't work on the image?

图片

我已经尝试了所有方法,但边界半径在此图像上不起作用。 它只是对它没有反应。 我已经尝试了 % 和 px。 图像对您可以看到的任何其他 CSS 值或我在组件中的 img 标记中传递的属性做出反应。 一切,除了边界半径。 我没有想法。

这是组件:

import React from "react";
import {
  UserContainer,
  User,
  UserProfilePicture,
  UserProfileName,
  UserChevronIcon,
} from "./User.style";
import Logo from "../../../images/ProfileFace.jpg";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faChevronDown } from "@fortawesome/free-solid-svg-icons";

function UserProfile() {
  return (
    <UserContainer>
      <User>
        <UserProfilePicture>
          <img src={Logo} height="50" width="50" border-radius="50px" />      -----> both px and % don't work
        </UserProfilePicture>
        <UserProfileName>Olivia Wilde</UserProfileName>
        <UserChevronIcon>
          <FontAwesomeIcon icon={faChevronDown} color="#7a7e7e" />
        </UserChevronIcon>
      </User>
    </UserContainer>
  );
}

export default UserProfile;

这是样式组件:

import styled from "styled-components";

export const UserContainer = styled.div`
  height: 90%;
  width: 30%;
  margin: 0px;
  padding: 0px;
  background-color: inherit;
  color: white;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
`;

export const User = styled.div`
  height: 70%;
  width: 100%;
  background-color: inherit;
  display: flex;
  text-align: end;
  justify-content: space-around;
`;

export const UserProfilePicture = styled.image`
  height: 50%;
  width: 50%;
  border-radius: 100px;      -----> both px and % don't work
  display: flex;
  justify-content: center;
  align-items: center;
`;

export const UserProfileName = styled.div`
  height: 40%;
  width: 40%;
  color: #7a7e7e;
  font-size: 17px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: flex-start;
`;

export const UserChevronIcon = styled.div`
  height: 50%;
  width: 10%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
`;

您可以通过以下方式对其进行样式设置:

   <img src={Logo} height="50" width="50" style={{borderRadius: '50%'}}/>

我假设您想让该图像变圆。 将 100 像素的边框半径添加到 50 像素的图像将不起作用。 改用百分比。 例如,要使方形图像看起来圆形,请使用以下样式:

border-radius: 50%;

如果它不起作用,可能是另一种样式覆盖了它,因此请尝试使用重要标签:

border-radius: 50% !important;

如果这也失败了(可能会被 css 中某个地方的另一个 !important 标签覆盖)尝试将其设置为内联样式:

<img src={Logo} height="50" width="50" style="border-radius: 50%" />

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM