Border radius still square internally
Border radius still square internally
I have a page that lists some predefined avatars that users can selected, as seen here -

These are defined as follows -
<span class="avatar-box">
<img src="..." class="avatar" style="width: 100px; height: 100px;" />
</span>
.avatar-box
width: 120px;
height: 120px;
text-align: center;
vertical-align: middle;
.avatar
border-radius: 50%;
margin: 10px;
When I click on an avatar, jQuery adds a class of "selected" to "avatar" -
.selected
border: 10px solid #40ac2b !important;
However, when this happens, the following happens on Chrome -

As you can see, while the avatar remains round, the border added is still square. This behaviour does not happen in Firefox, only Chrome.
What can I do to ensure the border remains round, like the avatar itself?
border-radius: 50%;
.selected
it adds
selected on avatar or on avatar-box?– Deepak Sharma
Aug 30 at 2:41
selected
avatar
avatar-box
@Barmar doing this seems to make no change to the outcome
– Paul McLean
Aug 30 at 2:53
@DeepakSharma it adds selected to avatar, not avatar-box
– Paul McLean
Aug 30 at 2:53
"the border added is still square." I want to clarify this. Isn't your original image square in the first place?
– reiallenramos
Aug 30 at 3:18
1 Answer
1
Set default border with transparent color, and after hover/active border color changed, because border size effect the size i.e height and width.
Have a look below example.
body
background:#ccc;
.avatar-box
width: 120px;
height: 120px;
text-align: center;
vertical-align: middle;
margin: 10px;
.avatar
border-radius: 50%;
border:10px solid transparent;
.avatar:hover
border:10px solid #ff0000;
<span class="avatar-box">
<img src="https://i.stack.imgur.com/CpldL.png?s=328&g=1" class="avatar" style="width: 100px; height: 100px;" />
</span>
Please explain what you changed and, more important, why.
– Barmar
Aug 30 at 15:09
i set default border with transparent color, and after hover/active border color changed, because border size effect the size i.e height and width.
– Nikesh Kumar
Aug 31 at 6:36
The explanation should be in the answer, not a comment.
– Barmar
Aug 31 at 7:06
thanks got your points
– Nikesh Kumar
Aug 31 at 8:26
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can't you add
border-radius: 50%;to.selectedas well?– Barmar
Aug 30 at 2:10