【发布时间】:2020-12-20 19:18:40
【问题描述】:
我是 Web 开发新手,正在尝试使用 HTML/CSS 创建基本头像。
我创建了一个 style.css 文件、一个avatar.css 文件和一个 index.html。
在我设置 .avatar CSS 类之前一切正常。我想用它来圆我图像的角落。但是在我将 img 类设置为“头像”之后,图像保持方形,而我应该有 2 个圆形图像,一个 50x50ph 和另一个 30*30(一个被设置为class avatar,另一个在class avatar-small)。
页面如下所示:
这是我的代码
CSS 样式
/* --- Google Fonts--- */
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@500;600&family=Open+Sans:wght@300;400&display=swap" rel="stylesheet")
/* --- Components Design--- */
@import "avatar.css";
/*@import url("components/button.css");*/
/*@import url("components/dropdown.css");*/
/*@import url("components/card.css");*/
/*@import url("components/badge.css");*/
/*@import url("components/banner.css");*/
/*@import url("components/tabs.css");*/
/*@import url("components/list.css");*/
/* --- Fonts--- */
body {
font-family: "Open Sans", "Helvetica", "sans-serif"
}
h1, h2, h3 {
font-family: "Montserrat", "sans-serif"
}
CSS 头像
.avatar {
border-radius: 50%;
height: 50px;
width: 50px;
}
.avatar-small {
border-radius: 30%;
height: 50px;
width: 30px;
}
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href='style.css' rel='stylesheet'>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500;600&family=Open+Sans:wght@300;400&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/73fba8f7d3.js" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Web Components</title>
</head>
<body>
<div class="container">
<h1 class="text-center">UI components sprint</h1>
<h2>Avatar design</h2>
<img src="https://via.placeholder.com/50" alt="" class="avatar">
<img src="https://via.placeholder.com/50" alt="" class="avatar-small">
</div>
<!-- jQuery & Bootstrap JS for dynamic Bootstrap components -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
我真的不明白这里有什么问题。我尝试自己寻找答案,但没有设法...
感谢您的帮助。
【问题讨论】:
-
能否提供您的文件夹结构? avatar.css 相对于 HTML 文档的位置在哪里?
-
您好!这 3 个文件 avatar.css 、 style.css 和 index.html 都位于同一个文件夹中。我尝试使用完整路径和相对路径调用头像。另外,当我在 HTML 中用鼠标越过 class="avatar" 时,会出现一个指向 avatar.css 中的 .avatar 类的链接,这意味着 HTML 可以识别该类,是的,什么都没有出现...