Search code examples
htmlcssweb-testing

How to make a circular border around image instead of ellipse when image dimensions have be Altered?


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? context

<!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>

Code ->


Solution

  • Give image width and aspect-ratio:1.

    img {
      width: 200px;
      border-radius: 50%;
      aspect-ratio: 1;
      border: 1px solid red;
    }
    <img id="kayaking" src="images/kayaking.jpg">