英文:
How to make a circular border around image instead of ellipse when image dimensions have be Altered?
问题
以下是要翻译的内容:
如标题所示,我想在我的图片周围添加一个圆形边框,我已经知道 border-radius: 50%;
,但由于我的图片尺寸已更改,它变成了椭圆。那么,如何在我的图片周围放置一个圆形边框呢?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Visit Citrus County</title>
</head>
<body>
<div class="block1">
<h1 id="title">Welcome to Citrus County</h1>
<h2 id="sub-title"> Home of the Manatees, and Great Wildlife!</h2>
</div>
<div class="block2">
<h1 id="things"> Top Three Activites to do in <span id="citrus-county">Citrus County.</span></h1>
<div id="activites">
<img id="kayaking" src="images/kayaking.jpg">
<img id="swim" src="images/swim-with-manatee.jpg">
<img id="hike" src="images/hiking.jpg">
</div>
</div>
</body>
</html>
英文:
As the title says, I want to add a circular border around my images, I already know about
border-radius: 50%;
but since my image dimensions have changed, it makes an ellipse. How do I put a circular border around my image then?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Visit Citrus County</title>
</head>
<body>
<div class="block1">
<h1 id="title">Welcome to Citrus County</h1>
<h2 id="sub-title"> Home of the Manatees, and Great Wildlife!</h2>
</div>
<div class="block2">
<h1 id="things"> Top Three Activites to do in <span id="citrus-county">Citrus County.</span></h1>
<div id="activites">
<img id="kayaking" src="images/kayaking.jpg">
<img id="swim" src="images/swim-with-manatee.jpg">
<img id="hike" src="images/hiking.jpg">
</div>
</div>
</body>
</html>
答案1
得分: 1
给定图片宽度和 aspect-ratio:1
。
img {
width: 200px;
border-radius: 50%;
aspect-ratio: 1;
border: 1px solid red;
}
<img id="kayaking" src="images/kayaking.jpg">
英文:
Give image width and aspect-ratio:1
.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
img {
width: 200px;
border-radius: 50%;
aspect-ratio: 1;
border: 1px solid red;
}
<!-- language: lang-html -->
<img id="kayaking" src="images/kayaking.jpg">
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论