Blurred border encircling a CSS circle styled with overflow: hidden;

Take a look at the JSFIDDLE of my cat animation without any drop-shadows to highlight the issue clearly. The problem appears to be related to the use of border-radius and possibly due to overflow: hidden.


Just to clarify, the owl is not the focus of this question - it's merely an example of a similar situation I encountered in the past. The main query pertains to the jsfiddle/cat animation; apologies for any confusion.

Here's another JSFIDDLE showcasing my cat with an inset box shadow using the blur property of box-shadow. However, the pixelated edge remains unchanged around the eye.

The solution provided here addresses issues relating to an owl image but does not align with the specifics of this question.

This feline features an inset box-shadow with a third value indicating blur for the eyes.


I've run tests on this fiddle across Safari, Chrome, and Firefox, yielding consistent results.

I'm currently working on a Cheshire Cat CSS project with two eyes, initiated yesterday. While everything appears fine on that front, I also created an Owl out of CSS (initially believed to face a similar issue, which is not the case) exhibiting a minor yet comparable concern regarding pixelation around the eyes.

Even applying a purple-colored border to the eyes fails to resolve the persistent pixelation around the edges.

In my latest CSS endeavor, the external edge of the eyes shows significant pixelation bearing a resemblance to the color (yellow) of the parent circle.

Below are the CSS styles for the eyes.

.eye {
  border-radius: 50%;
  height: 100px;
  width: 100px;
  background: #FAD73F;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  overflow: hidden;
  position: relative;
  display: inline-block;
  box-shadow: 0 3px 15px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.pup {
  border-radius: 50%;
  height: 20px;
  width: 20px;
  background: #2b2b2b;
  display: block;
  position: absolute;
  top: 40px;
  left: 40px;
}

.lidT {
  display: block;
  width: 100px;
  height: 100px;
  background: #821067;
  position: absolute;
  top: -80px;
  z-index: 20;
}

.lidB {
  display: block;
  width: 100px;
  height: 100px;
  background: #821067;
  position: absolute;
  bottom: -80px;
  z-index: 20;
}

Check out the JSFIDDLE used to create this animation/creature.

JSFIDDLE

A potential cause of the issue could be...

The problem might stem from the .lidT and .lidB classes nested within my .eye structure, causing a 1px trim around the eyelids, notably visible when attempting to animate blinking.

Using images as an alternative is feasible, but I prefer sticking to CSS creations for instructional purposes.

List of unhelpful styles

  1. box-shadow

  2. border

  3. box-sizing

  4. Not specific to Firefox only

End List

Updates

An interim solution involves adding an outer "eye socket" or primary tag surrounding the eye, concealing pixelation but serving as a workaround rather than a fix.

Refer to apaul34208's response for further insights.

However, one noticeable flaw in apaul34208's solution lies in the flattened appearance on the left and top sides of the eye, prompting speculation over whether the issue lies within browsers or CSS.

End Updates

Current best approach as of 11/13/2013

Applying a background gradient to the .eye element emerges as the most effective remedy thus far. Consult ScottS' answer for details.

This method is compatible with Firefox, Chrome, Safari, and even IE, although the result may vary slightly on IE compared to other browsers.

All contributions and guidance are highly valued!

Answer №1

Creating a Background Gradient Effect

You can achieve this effect without adding extra HTML elements. After testing it on multiple browsers, including Firefox, Safari, and Chrome (as mentioned in the comments), I found a way to create a gradient background for the eye with two different colors – purple closer to the edge and yellow towards the center. This technique uses radial background gradients to prevent any blending or discoloration along the edges caused by the combination of border-radius and overflow: hidden.

If you want to see the original solution/fiddle example with a 1px purple border, you can check it out here. Even with the drop shadow removed, there is still a slight discoloration visible as shown in this updated fiddle. To address this issue, I have modified the code below to include a 2px wide purple border, ensuring that there is no discoloration when the drop shadow is removed, like in this improved version featuring a winking cat.

Here is the latest (updated to 2px) CSS code snippet:

.eye {
    border-radius: 50%;
    height: 100px;
    width: 100px;
    background: #fad73f; /* Old browsers */
    background: -moz-radial-gradient(center, ellipse cover,  #fad73f 0, #fad73f 48px, #821067 49px); /* FF3.6+ */
    background: -webkit-gradient(radial, center center, 0, center center, 100%, color-stop(0,#fad73f), color(48px,#fad73f), color-stop(49px,#821067)); /* Chrome,Safari4+ */
    background: -webkit-radial-gradient(center, ellipse cover,  #fad73f 0,#fad73f 48px,#821067 49px); /* Chrome10+,Safari5.1+ */
    background: -o-radial-gradient(center, ellipse cover,  #fad73f 0,#fad73f 48px,#821067 49px); /* Opera 12+ */
    background: -ms-radial-gradient(center, ellipse cover,  #fad73f 0,#fad73f 48px,#821067 49px); /* IE10+ */
    background: radial-gradient(ellipse at center,  #fad73f 0,#fad73f 48px,#821067 49px); /* W3C */

    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    overflow: hidden;
    position: relative;
    display: inline-block;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

Answer №2

After careful consideration, I believe I have found a suitable solution to address your issue. Essentially, the key is to incorporate eye sockets and manage the overflow specifically within those sockets rather than focusing on the eyes themselves.

Take a look at the working example here

<span class="socket">
  <span class="eye>
    <span class="lidT"></span>
    <span class="pup"></span>
    <span class="lidB"></span>
   </span>
</span>

.socket {
    border-radius: 50%;
    height: 102px;
    width: 102px;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    overflow: hidden;
    position: relative;
    top: -1px;
    left: -1px;
    display: inline-block;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.4);
    z-index: 100;
}
.eye {
    border-radius: 50%;
    height: 100px;
    width: 100px;
    background: #FAD73F;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    position: relative;
    top: 1px;
    left: 1px;
    display: inline-block;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

Answer №3

Check out this response : stackoverflow.com/questions/6001281/firefox-border-color-border-radius-and-background-color-creates-ragged-edges-a#6001374

Also, take a look at this accepted answer: Border-radius bleeding

Consider clipping your background:

.your-element {
    -webkit-background-clip: padding-box;
    -moz-background-clip: padding-box;
    background-clip: padding-box;
}

Upon further reflection, it appears to be normal for the edge pixel to blur. Browsers are trying to convert something square into something round, resulting in blurred pixels similar to a photoshop selection.

Here is a visual representation of the blurry pixel.

Unfortunately, a background image is necessary, using a real image file.png.

In my case, I attempted to adjust your markup by adding an outer container to apply border-radius. User Mosher has done this successfully, refer to his solution on jsfiddle.

Answer №4

It seems that the distortion you are noticing is actually caused by the box-shadow CSS property, rather than the border-radius or overflow.

When the browser attempts to render a 1px #2b2b2b line inside the circular shape, it can appear pixelated due to the curved nature of the path and the need for it to be displayed as precisely 1px in width.

Consider adjusting the blur value (third value) in the box-shadow property to see if it improves the quality.

Take a look at the comparison between two rounded <div/> elements in this demo on jsFiddle.

Answer №5

Check out the live demonstration here: jsFiddle

Place the content of .eye in a different container like this:

<span class="eye">
    <div id="eyeCover">
        <span class="lidT"></span>
        <span class="pup"></span>
        <span class="lidB"></span>
    </div>
</span>

Remove overflow:hidden from .eye. The updated style for .eye is as follows:

.eye {
    border-radius: 50%;
    height: 100px;
    width: 100px;
    background: #FAD73F;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    position: relative;
    display: inline-block;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.4);
    z-index: 100;
    overflow: visible;   /*  modification made here  */
}

Adjust the width of .lidT and .lidB to 105px, then apply this style for #eyeCover:

#eyeCover{
width: 102px;
height: 102px;
top:-1px;
left:-1px;
border-radius: 50%;
overflow: hidden;
position: relative;
}

See the updated demo here: jsFiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Excessive content spilling over into the footer area due to an integrated forum feature within

We have integrated a Muut forum into our website, and it is working well when embedded in a coding block within the page's body. However, there is an issue where the sidebar of the forum gains extra features when logged in as an admin. This causes the ...

What exactly does this jquery library aim to achieve?

Recently, I discovered a new library for CSS3 animations. As someone who is still learning JavaScript, I am unsure of the benefits it offers. It appears to replicate what jQuery can already achieve but by utilizing CSS3. So, what advantage does using a to ...

What could be causing the Bootstrap ProgressBar to not show up?

Having an issue with the ProgressBar component from react-bootstrap: <ProgressBar now={dynamicValue} /> The value dynamicValue changes for each component. However, I am unable to get the progressBar to display in my case. ...

The position of the carousel items changes unpredictably

My jQuery carousel consists of 6 individual items scrolling horizontally. Although the scroll function is working correctly, I have noticed that 2 of the items are randomly changing their vertical position by approximately 15 pixels. Upon reviewing the HT ...

What is the process for using jQuery to systematically alter the src attribute of all avatar images on Twitter.com?

Summary: I am learning JavaScript and jQuery, and wanted to write a script to replace "_normal.png" with ".png" for all "img.avatar" images on Twitter.com. I encountered an error which I will explain below. Background: Practice makes perfect, so I like to ...

As I spun four images along the outer edge of a circular border, one image came to a halt at 90 degrees, revealing its content. Now, I am looking to enlarge that particular

I managed to rotate four images around a circular border and stop one image at every 45-degree angle. However, I am struggling to enlarge the image that stops at 90 degrees on the website while still showing the content of the respective image when it reac ...

How can JavaScript be used to create a unique signup and login process on

I am struggling with storing sign up and login details in JavaScript. In my previous project, I used PHP and a database to handle this information, so transitioning to JavaScript has been challenging. Here is an example of the sign-up HTML code: <!DOC ...

"Creating a custom navigation bar with full width and navigation corners on both left

I am struggling to make my website's navbar stretch to the edges of the container while maintaining full width. I have added left and right padding to each navigation item, but in smaller laptop resolutions, the items break onto a new line, which is n ...

Angular.js does not trigger validation for input[type='date'] if only a part of the date is entered (such as just the day)

There is an input[type='date'] with no additional validation rules. The issue arises when only a portion of the date is entered (for example, just the day and month). In this case, if you enter '01/02/YYYY', it will be recognized as an ...

Utilizing aliases for CSS/SASS file imports with webpack

Can we use aliases to import .scss / .css files? // webpack.config.js resolve: { alias: { styles: path.resolve(__dirname, "src/styles/"), } } In the main.js file: // main.js import "styles/main.scss"; ...

Angular Appreciation Meter

Looking to create a rating system using Angular. The square should turn green if there are more likes than dislikes, and red vice versa (check out the stackblitz link for reference). Check it out here: View demo I've tried debugging my code with con ...

Angular 2: Change Boolean value depending on a condition

I find myself facing a challenge with a search-bar feature. My goal is to display all the filtered names when the input value reaches a length of 2 or more characters. After successfully extracting the value.length from the input field, I encountered a ro ...

svg rect mistakenly appearing as a rounded polygon

I found a cool SVG pie chart on this codepen that I want to modify. The original chart is 50 x 50 and animated, but I want to make it 20 x 20. To resize the pie chart, I tried changing the width, height, radius, and center points in the code. I also adjus ...

When the page first loads, the slider is responsive, but it does not adjust

I installed the Moving Boxes plugin and customized it to create a full-width image slider. While it works well when the page loads, I'm facing challenges with making it responsive on resize. It appears that the JS script sets fixed widths upon load, w ...

What are some methods for toggling text visibility in PHP?

I am facing confusion regarding the functionality of this code. Here is the snippet in question : //start date to end date <?php if($show5 < $show6) { ?> <a>show content</a> <?php }?> If both 'start da ...

Send the completed form to the websocket for processing

I am currently in the process of sending basic login information to a server. The requests and functions are functioning perfectly for the test user "testuser." I want individuals to have the ability to input their own username and password for considerati ...

Could you provide some advice for creating a Single Page website?

I am working on a simple HTML setup with various elements such as a navbar and content blocks. <html> <head> <title>My HTML5 App</title> <meta charset="UTF-8"> <meta name="viewport" content="wid ...

Seeking assistance with setting up BxSlider installation

I'm struggling with adding bxslider to my HTML template. No matter what I try, the slider doesn't work as expected. When I preview my website, all three images are displayed together in a single column. Can someone please guide me on how to fix t ...

Select Year - Calendar View

I am currently making adjustments to a basic datepicker. I am looking to only include the Year dropdown (Month is not necessary). https://i.sstatic.net/AEpaj.png I have attempted to eliminate the Month dropdown by applying the following CSS: select.cus ...

Ways to access the value of an input field using Javascript

I am currently utilizing the valums-file-uploader plugin for file uploads via ajax. However, I have encountered an issue with its functionality. Below is the script that I am using: <input type="text" id="Gaurav" name="Gaurav" /> <script src="fil ...