treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Trouble Rendering Circle Overlays in Chrome and Safari

  • This is a rewrite of a post from yesterday...I have created circle overlays for my thumbnails using a plugin I downloaded from ThumbFX. It renders fine in Firefox but not in Chrome and Safari.

    In order to create the gray circle borders for the thumbs, I had to attach the border to the .thumbnail a link rather than the actual image, in order to get it to render correctly in Chrome and Safari. I have tried doing a similar thing for the overlays but nothing is working so far.

    debbierking.com

       <ul class="thumbnails">
                        <li class="span4">
                          <div class="thumbnail">
                                <a data-overlayer="effect:bottom;" href="projects/karensalon/ks.php">
                                <img src="img/thumbs/thumb-ks.png" alt="Thumb - Karen's Salon">
                                <div class="overlay">
                                  <h3>Karen's Salon</h3>
                                  <p>Web Design</p>
                              </div></a>
                          </div><!--End Thumbnail-->
                      </li>
              </ul>
    

    CSS:

      .thumbnail a { 
      border: 1px solid #c5c5c5;
      background: #d5d5d5; 
      display: block; 
      padding: 6px;
      text-decoration: none;
      -moz-border-radius: 50%; 
      -webkit-border-radius: 50%; 
      border-radius: 50%;
    }
    
    .thumbnail img {
        -moz-box-sizing: border-box;
        height: auto;
        position: relative;
        width: 100%;  
        -moz-border-radius: 50%; 
        -webkit-border-radius: 50%; 
        border-radius: 50%;
    }
    
    .thumbnail h3, .thumbnail p {
      display: none;
    }
    
    .thumbnail a:hover {
      border: 1px solid #0f7a7d;
      background: #118f92;
    }
    
    .overlayer .overlay {
      background-color: #333;
      background: none rgba(0,0,0,0.75);
      z-index:99;
      padding-right: 20px; 
      -moz-border-radius: 50%; 
      -webkit-border-radius: 50%; 
      border-radius: 50%;
    }
    
    .overlayer .overlay h3, .overlayer .overlay p {
      color: #fff;
      display: block;
      text-align: center;
      text-shadow: 0 -1px rgba(0,0,0,.7);
    }
    
    .overlayer .overlay > div { 
      padding: 5px 0 15px 10px; 
    }
    
    .overlayer .overlay.remove-padding > div { 
      padding: 0;
    }
    
  • That s/b debbierking.com/bootstrap.

  • .overlayer .overlay {
         border-radius: 50%;
          height: 100% !important;
    }
    
  • Thanks Atelierbram...It's getting there...I need the height to be only only about 33%, but when I use that height instead, the circle flattens out in Chrome and Safari, rather than looking the way it does in Firefox (which is the way I want it to look.)

  • Yeah, I see now what you're after. That's odd though, and in a way I don't understand why it does work in Firefox ...

  • Chrome and Safari don't render circles properly...Firefox does. Do you have any ideas? Right now I've lost my styling for the site so am trying to restore that....not sure why.

  • I guess it has probably more to do with ( the differences in rendering by browsers of ) the stacking order of absolute and relative positioned elements, using z-index, then anything else. In you're case the a-element with the 50% border-radius should be above the overlay. Well that's what you want, but maybe the creators of this javascript didn't have this scenario in mind ... in a way also a paradox: an overlay that wants to be behind a parent. Tried to solve it with different z-indexes for the different elements, but unfortunately with no success. z-index property , how z-index works , demo page z-Indexing positioning

  • Atelierbram...I appreciate all your efforts with this! In the end, I broke down and made a .png of the overlay image...I hated to do it...but oh well....I do hope Chrome and Safari get their act together soon to render circles properly ;o

  • That's too bad, if you ever have a change of heart you could always try this:

    .thumbnail * { 
      /* outline: 1px dotted red */
    }
    .overlayer[style] {
        position: absolute !important;
        width: 290px !important;
        height: 290px !important;
        z-index: 2 !important; 
        border-radius: 50%;
        overflow: hidden;
    }
    .thumbnail {
        position: relative;
        width: 290px;
        height: 290px;
        border-radius: 50%;
        z-index: 99999;
        overflow: hidden;
    }
    .thumbnail .size-auto {
        width: 290px;
        height: 290px;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1; 
        border-radius: 50%;
    }
    .thumbnail .overlayer .overlay[style] {
        z-index: 2;
        border-radius: 50%;
        width: 290px !important;
        height: 290px !important;
        clip: rect(133px, 290px, 290px, 0); /* you will have to edit these values */
    }
    .thumbnail .overlayer .overlay > div {
        margin-top: 67%;  /* you will have to edit this value */
    }
    

    So I changed the position values around, z-indexes, with some clipping. Note that only the combination of [style] with !important is able to override ( in the stylesheet ) the injected inline css styling in the DOM by javascript. I would recommend considering to drop the javascript for the hover effect all together, and instead try CSS3 (; the thing you might lose though is the 'easing effect', but that is in a way also gone now ...). Good luck, keep it up and persevere: these are interesting problems.

  • Thank you! Hate to let go of the Hover plugin since I paid $$$ for it. Will try this though. The image thing isn't working out at all cause I can't get it to resize on hover...will definitely try your code!

    Do you know jquery? Am trying to get several bootstrap js functions to work. Are you familiar with Bootstrap?

  • This looks good in Firefox but again, it isn't rendering properly in Chrome or Safari ...the thumbs come in as squares.

  • I've gone back to my previous code and surprisingly, it is rendering properly now in Chrome, but still not in Safari. Am using this for .overlayer .overlay.

    .overlayer .overlay {
      background-color: #333;
      text-shadow: none;
    z-index:99;
    }
    
  • @DesignLady94 , one of these days, when I find some extra time, I will make a codepen to see this thing work. Here are my thoughts however: you're .overlayer .overlay > div doesn't need to have 50% border-radius for all corners, but what's essential here is that it has to sit behind you're .overlayer .overlay which surely does have to be a 'perfect circle', and therefore will need to have full height and width ( here 290px), but then be clipped from the top in order to have the look that you're after. But then also make sure to override or change the javascript to give the .thumbnail a.overlayer[style] ( which is given the overflow:hidden by means of injected inline css by javascript ) the position absolute instead of relative , also make sure of full widht and height (use !important in stylesheet after the value, and have the extra [style] attribute with the property: you're overriding inline css here! ). Then give you're .thumbnail wrapper a position of relative, and z-index: , we're almost there. A last tip is to disable the history in your're browser, flush the cache, and in Chrome webdeveloper-tools to disable the cache, if you want to stay sane as a web-designer/developer.

      .thumbnail .overlayer .overlay[style] {
        z-index: 99;
        border-radius: 50%;
        width: 290px !important;
        height: 290px !important;
       clip: rect(194px, 290px, 290px, 0); 
        /* you probably will have to edit the first value ( 194px = 2/3 from top of image which is 290px height */
    }
    

    Oh, and yes, I can work with jQuery, but am not familiar with Bootstrap js, and generally more of a frontend tweaker; just know some basic javascript, but am trying to learn more.

  • Thank you...this totally works in terms of rendering the half circles in all three browsers! Was not familiar with the clipping property...will definitely have to remember that!

    Btw, what exactly does .thumbnail .overlayer .overlay > div { do?

    Just two things left to work out...for some reason, the text is not displaying, and I needed to resize for responsive...is there a way for the half-circles to automatically r esize? Or do I just need to make the changes for each media query? I tried setting the widths to max-width, but when I did that the overlay half-circle disappeared.

    Here's what I have:

    .thumbnails {
      margin: 0;
      padding: 0;
    }
    
    .thumbnails > li {
      margin-left: 10px;
    }
    
    .thumbnail {
      border: none;
      box-shadow: none;
      position: relative;
      z-index: 100;
    }
    
    .thumbnail a { 
      border: 1px solid #c5c5c5;
      background: #d5d5d5; 
      display: block; 
      padding: 6px;
      text-decoration: none;
      -moz-border-radius: 50%; 
      -webkit-border-radius: 50%; 
      border-radius: 50%;
    }
    
    .thumbnail img {
      -moz-box-sizing: border-box;
      height: auto;
      position: relative;
      width: 100%;
      vertical-align: middle;
    
      -moz-border-radius: 50%; 
      -webkit-border-radius: 50%; 
      border-radius: 50%;
    }
    
    .thumbnail a:hover {
      border: 1px solid #0f7a7d;
      background: #118f92;
    }
    
    .thumbnail .overlayer .overlay {
      background-color: rgba(0,0,0,0.7);
      z-index: 99; 
      border-radius: 50%; 
      width: 290px !important;
      height: 290px !important; 
      clip: rect(194px, 290px, 290px, 0);
    }
    
    .thumbnail .overlayer .overlay > div { 
      padding: 5px 0 15px 10px; 
      z-index: 20px;
    }
    
    .thumbnail .overlayer .overlay h3, .overlayer .overlay p {
      color: #fff;
      display: block;
      text-align: center;
      text-shadow: 0 -1px rgba(0,0,0,.7);
    }
    
    .thumbnail .overlayer .overlay.remove-padding > div { 
      padding: 0;
    }
    
    .thumbnail .overlayer .overlay h3 {
      font: normal 24px 'Museo300Regular', Arial, sans-serif;
      margin-bottom: 0;
    }
    
    .thumbnail .overlayer .overlay p {
      font-size: 14px;
    }
    
  • Actually, the text does show up in black for just a moment and then disappears..It should be in white.

  • Okay, got the text to display by adding a top margin of 195px to the .thumbnail .overlayer .overlay > div. I figured it was getting clipped off the top by the clip selector in .overlayer .overlay. Though I am still not clear on the difference between this selector and .overlayer .overlay.

    Still need to figure out resizing.

  • Glad to see it start getting there. The .overlayer .overlay > div is the div that's holds you're pop-up description text: 'Karen's Salon etc. ( The greater-then-sign > is the child combinator selector, which makes it that it will only select 'html-elements or divs or what have you' that are direct children of the parent: Chris did a great article about it . BTW: you can see/open up the div, can't you, when you do inspect element in firefox' firebug or chrome webdeveloper tools?) I see there is a issue with the calculated width and height which needs to be more than 290px, probably 302px, or 304px, now I think about, because of the padding on the a link element ( 2 x 6px = 12px + border 2 x 1px = 14 ), or do box-sizing: border-box. About the resizing, responsive thing: that's a whole different can of worms that I might see about this weekend if I find the time to make some sort of simple reduced test case . Easier to get into details, and to the heart of the matter in that way. P.s. There is a typo in you're css: z-index: 20px , which should be just the naked value without px like this: z-index: 20 . Have a great weekend.

  • Thanks Atelierbram! Actually, I think I've got this :) Just did everything on a smaller scale for the responsive layout.

    Thanks for the article...will read this weekend...I've never totally understood why you need the > sign in some cases. And I fixed the typo.

    As for the resizing of the larger circles to 304, I tried that but the overlays didn't fit anymore so I set them back to 290px. However, for the smaller circles, it worked better to add the extra 14px to the overlays...go figure.

    The only issue on this now is that sometimes on reload, an expanded circle background and black text flicker up before going away. Do you know how I could get rid of this?

  • I think that setting the width of the larger circles' overlay ( .thumbnail .overlayer .overlay ) to 300px will work, if you also set the clip to match ( rect(194px, 300px, 290px, 0) ).

    This looks right to me in Chrome and Firefox.

  • I tried that...but the overlay didn't fit all the way across the circle...I am now noticing that when the circles expand the overlay isn't expanding with them. Is there some way to resize them automatically as they expand and contract?

  • I should say that I've already tried max-widths and auto widths but those don't work.

  • The hovering, clipping, and popup in this codepen I just made looks promising, I think, in Chrome and Firefox, but some 'slipping/flickering' ( on hover ) in Safari ... Any ideas?

  • Oh man...I'm so sorry...I should have posted on here last night to let you know that it looks like I have everything resolved on this. I removed a width of 100% on .thumbnail a, which cleared up the problem of the overlay not fitting on expansion. I feel badly that you went to all this effort. Before I try to incorporate your code here, why don't you take a look at the site as it is now and see what you think.

    The only problem I am still having is the ugly flicker you mentioned on page reload where the circle backgrounds expand and ugly black text shows up. It's happening for me in all the browsers, not just Safari.

    Thank you again! Your help has been invaluable...especially learning about the clip attribute.

  • @DesignLady94 : please don't be sorry ...; I'm doing this also for my own curiosity in this matter, ( something I'm eager to find an excuse for using oneday ) so congratulations, and maybe you can call this question solved! What I think of you're homepage is that it looks good, and I mean that, but that ( parts of ) the underlying css are still vulnerable. By making this codepen I experienced how tricky this issue really is. One thing, which is odd and hard to explain, but what can be improved in you're code is the .thumbnail .overlayer .overlay : ( 'cause of the padding ) the circles are just a tiny bit oval, so by compensating this in the height for this element, you will have a better fit. You can check this by temporarily disabling the clip property in Firebug or developer-tools:

    .thumbnail .overlayer .overlay {
        background-color: rgba(0,0,0,0.7);
        z-index: 99;
        border-radius: 50%;
        width: 290px!important;
        height: 303px !important;
       clip: rect(194px, 290px, 303px, 0);
      }
    

    Also noticed that, by disabling the border on the .thumbnail a , the layout breaks on hover; that can be a sign that the css is still not bulletproof . And I don't understand this jQuery.thumbFX.css file that you include, which says .css, but is really html. So good luck with optimizing: that's the trouble with using other's frameworks, plugins ( no matter how solid it is ) : there's always some 'dead wood' to get rid of!

  • I'll try these things..thanks! Hopefully they will take care of that awful flicker.

  • I see what you mean about the layout breaking down....not sure how to fix though. I have removed the jQuery.thumbFX.css as I took the overlay css and put it in my style sheet, so it wasn't really needed. The latest version is now at debbierking.com.

  • Made this new codepen of the clipped overlay on hover for images this time with css transitions , 'triggered by' a few lines of jQuery on hover. This one's the most solid so far.

  • So this will be the third and last codepen of clipped overlay on hover for images It's simply a combination of the two others, and only to be used if you like to experience javascript and css fighting The Ultimate Battle of Specificity. Which is bad, while it works ... although it is a improvement over the first one I made but would recommend anyone to use the one above with css transitions and lightweight inline jQuery : it's much cleaner and far more lightweight (and no more need to override inline css in the stylesheet by putting !important and [style] in there ). @DesignLady94 : please note that I had to do some tweaking of the layout in the css. Which is both good and bad news for you at the same time. Good news first: the slipping+flickering is no more. Has to do with lots of things, but one of the things I had to remove was the padding on the thumbnail wrapper. It gives unnecessary complications. But since the padding was there for reasons of giving some space between the pictures, I had to come up with something else, which was larger margins on the grid-unit-floats: span4. And after that the .container with had to be adapted with a few pixels more and/or less ( and in the media-queries ). Lastly I also put in an extra media-query with (min-width: 980px) , to be able to go with the mobile first approach. So keep that in mind if you would use the lean and mean variation above : not all compatible right now with what you have in bootstrap.css, but can of course be adapted. I would like to add that this latest codepen variation, I also strongly discourage for you, at least for you're homepage, it's best to go with the one above and drop the ThumbFx.

  • Thank you so much for your persistence and thoroughness in your code pens...However, I am having a little problem with figuring out which is your code and which is already in Bootstrap. I don't want to repeat the Boostrap code in my style sheet.

    As for ThumbFX, I'm going to get rid of the css for that as I copied the relevant portions into my style sheet.

  • Speaking for myself, I would do the following: use the codepen as a template, just locally on the server on you're computer (localhost ~/) and copy the styles and markup on top of that: build it up again one line at the time, in some new html and css files that you make in a folder within you're ~/Sites folder. And yes be aware of repeated code, I didn't want to say but I did see some of it around in you're css. Ultimately comes from bad habits, copying and pasting snippets of code around and then forgetting about removing the repeats, which I also suffer from sometimes. If one takes the mobile first aproach however, you're life becomes easier, because you don't have to repeat and override so much in the media-queries.

  • I tried the mobile approach and was having such a rough time of it that I went back to doing the full screen version first...I have had a really, really difficult time with this site....I needed to get up a working version so I've done that now...but still have several nagging issues. I have just discovered that the thumbnails section seems to be the reason for my problem with the About link...that is, when I click on it from another page, it drops down to go the bottom of the section, rather than the top.

    Am sending you a PM.