Can you help me with a CSS challenge? I need to create circles around elements on a webpage, but my code is not working perfectly. The width of the circle is off and I can't seem to center it properly.
- The width does not match the content (it is always too big), and
- I am struggling to get it to center on the child element
Here is the code I currently have:
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Circle Demo</title>;
</head>
<body>
<style>
div.ccc {
display: run-in;
position: relative;
}
div.ccc:after {
display: inline-block;
content: '';
position: absolute;
top: -50px;
right: -50px;
bottom: -50px;
left: -50px;
opacity: 0.7;
border: 5px solid red;
border-radius: 50%;
padding: 10px;
}
</style>
<div class="ccc">
<img src="https://beautifulenvironments.files.wordpress.com/2017/12/twinkly-lights.jpg" width="10%">
</div>
<div class="ccc">
<img src="https://beautifulenvironments.files.wordpress.com/2017/12/twinkly-lights.jpg">
</div>
</body>
This code produces imperfect results as the circles are not centered on the images and the widths are incorrect.
Is it possible to correct this using just CSS?