Pages

Showing posts with label css3. Show all posts
Showing posts with label css3. Show all posts

Friday, January 13, 2012

0

Tip: Anonymous avatar for new Blogger threaded comments

Update Feb 2nd 2012: Blogger has updated the threaded comments, and it now includes an avatar for anonymous commenters by default. So this is now obsolete.


Previously I've told how to use anonymous "mystery man" avatar in the "old" commenting system, article here. But if you start using Blogger's new threaded commenting system, that old CSS won't display the mystery man anymore.

To make anonymous avatar work for the new commenting system, I had to use CSS3. Most browsers luckily support it now. Here's a simple CSS3 definition, that puts the mystery man back into his place. Add this to your template's CSS section (you can use Template Designer|Advanced|Add CSS):
.avatar-image-container img[src$="blogblog.com/img/blank.gif"] { width:36px;height:36px;
background:url(http://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&s=36) no-repeat center center;
}
(double click code to select for copying) This tip works for non-dynamic views. You can use a custom avatar instead of the Gravatar's mystery man, uploaded to your Picasa web albums, for example.

Friday, November 18, 2011

1

Combined CSS and image comment bubbles

This article concludes my three part comment bubble article series. If you want comment bubbles in your Blogspot blog, you can pick one these three hacks.

1. Comment bubbles using only CSS
2. Comment bubbles using an image
3. Combined solution, which uses CSS whenever possible (installed in this blog)

As I explained in the CSS only comment bubble hack article, Internet Explorer does not support all CSS needed for rounded comment bubbles with gradient background. And the support varies from version to version.

Internet Explorer 8 and lower

I start with the "CSS only" hack installed, and then add there stuff for different Internet Explorer versions.

IE8 and lower don't have rounded corners and IE7 does not support :after, so I decided simply to use a comment bubble image, when IE version is lower than 9. First I thought that I'll use conditional comments like this:

<!--[if lt IE 9]>
..stuff for ie versions below 9..
<![endif]-->

But after trial and error I found out that it was not so easy. I learned that the browser version number does not actually determine the CSS capabilities, but the document mode (compatibility mode) instead. Well at least in Blogspot blogs, and that's where I'm targeting with my code.

I finally came up with this solution for IE (documentMode) < 9:

<!--[if IE]><script type='text/javascript'>
if(typeof document.documentMode == 'undefined' || document.documentMode < 9)
document.write('<style type="text/css"> a.comment-bubble { background:url(http://lh6.googleusercontent.com/-IVVxPuuguig/Tr_NWRIN3HI/AAAAAAAAAWs/weLvk3eWQtM/s800/comment_bubble.jpg) no-repeat;width:36px;height:26px;border:0;padding-top:3px;} a.comment-bubble:after { border:0; };</style>');
</script><![endif]-->

That code is placed somewhere after template stylesheet and before </body>. The javascript is seen and runs only on IE. If documentMode < 9 (IE8, IE7, ...), new style definitions are written: bubble background uses an image, set width and height, no border and right padding, and for a:after remove the border that made the triangle. Basically make comment-bubble use same styles as in the image comment bubble hack.

Internet Explorer 9

As we saw in the CSS only comment bubble hack, IE9 does quite well with the comment bubble CSS: only the gradient background is missing. There is a filter provided by Microsoft to make gradients, but that messes the rounded corners. There are workarounds for that, too, but I chose another way: I made a gradient background image and encoded it in base64 to make a data URI, so it could be directly embedded in CSS without external file. Background image is correctly clipped by the rounded corners.

So the comment bubble CSS became:

Data provided by Pastebin.com - Download Raw

Line 15 is new (compared to CSS only solution) and contains the gradient for IE9. Because it is before the background gradient definitions, they override it on browsers that support gradients. And on IE8 and below the background is later reset to use an image (see previous chapter).

The discovery of data URIs base64 gradient PNG lead me do a simple linear gradient tool for making embeddable gradient backgrounds.

Complex solution?

So, is there any point in this complex solution, one might ask. Well, to be honest, I don't know :) You might prefer to use either CSS only or image only solution, for simplicity. I could also have used either, but this way I learned more. In a year or two Internet Explorer will do CSS comment bubbles, too, and then these browser version dependend hacks won't be needed anymore.

Thursday, November 17, 2011

0

Pure CSS3 comment bubbles for Blogger

A week ago or so I implemented the comment bubbles for this blog. There are some comment bubble hacks for Blogger that use image, but I found none with CSS3 bubbles, so that is what I started from. I show in this article, how you can make CSS3 comment bubbles like this for Blogger.

"Pure" in this context means that I don't use images. I really don't know much CSS so I don't know if the product-dependent -webkit-, -moz- and -o- style settings are "pure CSS3" or not.

Browsers like Firefox, Opera and Chome already support CSS3, and soon also Internet Explorer will, so you might already want to have this clean CSS only solution in your blog. It also loads a bit quicker without external images that cause http request. This CSS solution degrades to quite nice looking and usable element on Internet Explorers (version 9 and below), too, see the end of this article.

Because CSS3 is not fully supported by Internet Explorer versions below 10, in this blog I expanded this CSS only solution to use image in IE8 and below, and CSS + gradient data URI in IE9. So this CSS only hack is not installed in this blog. I'll tell you about "pure image comment bubbles" and the combined solution in later articles.

Add comment count code

First we add the link to "post.url#comments" next to the post title, where link's text is the number of comments in that post. Open your template html, and expand widget templates. Find lines:
<b:includable id='post' var='post'>
  <div class='post hentry'>
    <a expr:name='data:post.id'/>
    <b:if cond='data:post.title'>
      <h3 class='post-title entry-title'>
After those lines add (doubleclick to select for copying):
<b:if cond='data:post.allowComments'><a class='comment-bubble' expr:href='data:post.url + &quot;#comments&quot;' expr:title='&quot;Comments to &amp;quot;&quot; + data:post.title + &quot;&amp;quot;&quot;'><data:post.numComments/></a></b:if>
Save the template.

Add CSS for comment bubbles

I chose the colors for my bubbles like this, you might want to use some other colors that suit your template:


Go to Template designer, choose Advanced, Add CSS. Add the following CSS:

Data provided by Pastebin.com - Download Raw

Apply to blog. And you have your CSS comment bubbles!

This hack and Internet Explorer

In IE7 and below the bubble is only a rectangle with borders and solid background color.
In IE8 the comment bubble has solid background color and no rounded borders.
IE9 does quite well, only the gradient background is missing (background is solid color).
See the hack
for this dynamic
views icon: