Showing posts with label css. Show all posts
Showing posts with label css. Show all posts

Thursday, August 30, 2012

Simple Way to Toggle on Hover with CSS

Here’s a really simple way to toggle actions or more information to keep your pages clean.


View Demo

kick it on DotNetKicks.com

Monday, June 11, 2012

Making Prettier Forms: Converting Checkboxes into Images

A couple weekends ago I went to the Big Design Conference in Dallas (recap coming soon), and I always come back inspired to help the user’s experience with the applications I write. One of the things mentioned (several times) was making forms simpler. Basically, you don’t have to make the end-user feel like they’re filling out a form. There are ways to make it seem less intimidating. One way is to swap out the typically hard-to-click checkbox or radio button with an image. It gives the user a larger click area and it looks nice…at least in my opinion.

Basically, I’m helping a friend with a small project, and the image below is what I wanted to create.

image

If you buy Stephen Anderson's book "Seductive Interaction Design", you will see a similar form to the one above...primarily just the name and contact info stuff. By the way, I definitely recommend this book.

As you can see, the “Select Classification” is not your typical radio button setup. I googled for a bit if there was already a jQuery plugin to do this type of thing and came up empty. I’m sure you almighty readers know of one, but I couldn’t find it…so I made one.

So far I’ve tested it in Firefox, IE9, Chrome, and JAWS, and it works pretty good in all of them. The way I set it up to work is based on the input and label. So you’d have the most accessible standard markup with your preferred styles for the label, and that’s how you get the effect shown above. I think it’s probably better said with code:

So it looks like a pretty typical setup so far, right? You have an input with a label. To make it more accessible, you wrap it with a fieldset and give it a legend. The primary reason you’d do this is to give screen readers some context. If you don’t need to worry about that, you could just as easy wrap it all with a div. You’re going to want to wrap it so your jQuery selector is more precise. After you markup the form, you just add the following JavaScript.

Now you’re all wired up, and you just add in your styles to whichever stylesheet classes you specified. The default stylesheet class names I specified are:

  • .Selected-Checkbox – this class is added to the label after it has been clicked
  • .Checkbox-in-focus – this class is added to the label when the checkbox/radio button is in focus

If you’re not sure the plugin is working properly, you can put it in “testMode”, like this:

$('#classification_radio_wrapper label').checkMate({testMode: true });

If you need to override my default class names, you can do that too by specifying class or focusClass in the options. I might rename class to selectedClass in the near future.

Please leave a comment if you have any questions or feedback.

The source code is available on github at https://github.com/derans/checkMate

The demo is located on 1pg.it at http://1pg.it/v9etvtn5 (also on github as the example.htm file)



Shout it

kick it on DotNetKicks.com

Thursday, August 25, 2011

Blogging just to Blog…I mean Styling Tips!




Lately I have not felt like blogging, but I’m committed to at least once a month. I think the primary reason I haven’t felt th need to blog is because I haven’t really spent much time developing lately. I’ve been spending a lot of my time on user experience and interface design.

I thought I’d share a few styling tricks that are too easy not to do because they add a lot to usability.

  1. Changing the style of a row on hover. This allows the end user to easily see which row they’re looking at instead of having to trace the line.

    table tr:hover td {background: #e7e7e7}
  2. Changing the style of an input on focus. This allows the end-user to easily see where they’re at in a form without much thought.

    input:focus {border: solid 1px #f90}
  3. Changing the style of a hyperlink on hover. Granted this one has been around forever, but it’s a great one.

    a:hover {background: #333; color: #fff}

There are most definitely hundreds more, but these are a few of my favorites to use on a project. Also note that they do NOT work in all browsers.

Thanks for reading!

kick it on DotNetKicks.com

Sunday, January 02, 2011

Allowing HTML with iFrames and jQuery




So I’ve had a problem of displaying other people’s HTML on my page and their invalid HTML messing up my page’s formatting. So, I found a solution after digging through the Outlook Web Application (OWA) HTML to see how they handle the issue. I do it a little differently, but the idea is the same.

Basically, you have a blank page in an iFrame and you insert the encoded HTML into that blank page. Here’s how I do it:

Setup a blank.htm like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
<
head>
<
title></title>
</
head>
<
body>
<
div id="htmlcontent"></div>
</
body>
</
html>

Okay, so now on the page you need to display the HTML, you add this:

<iframe id="htmlcontent" frameborder="0" src="/blank.htm" width="600" height="400" style="background: #fff; margin: 0; padding: 0; border: 0">
<
p>Your browser does not support iframes.</p>
</
iframe>

Now all we need to do is setup the jQuery like this:

<script language="javascript" type="text/javascript">
function showHtml(id) {
$(
"#htmlcontent").contents().find("#htmlcontent").html($('#' + id).text());
}
</
script>

Now to call the jQuery:

<a href="#" onclick="showHtml('myEncodedHtmlDiv');">Sample Link</a>
<
div id="myEncodedHtmlDiv" style="display: none">&lt;p&gt;&lt;strong&gt;Greetings from the Encoded Sample!&lt;/strong&gt;</div>

With ASP.NET, you can do Server.HTMLEncode(htmlToEncode) to encode whatever string you want. The jQuery automatically decodes it when you call the .text() inside the .html() like I did above.

If you want the HTML to show up in a modal, all you need to add is this:

<div id="htmlmsg" style="display: none" class="modal">
<
iframe id="htmlcontent" frameborder="0" src="/blank.htm" width="600" height="400" style="background: #fff; margin: 0; padding: 0; border: 0">
<
p>Your browser does not support iframes.</p>
</
iframe>
</
div>
<
div id="overlay" style="display: none"></div>

Here’s the CSS to tag along:

#overlay {position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 1000;
background: #eeeeee 50% 50% repeat; opacity: .80;filter:Alpha(Opacity=80);
}

.modal { z-index: 10000;
position: absolute;
top: 100px;
margin: 0 auto;
background: #fff;
border:1px solid #ccc;
padding:10px;
text-align:center
}

Now you’re done. Please comment if you have any questions. Thanks for reading!


Shout it

kick it on DotNetKicks.com

Sunday, March 28, 2010

Different Approach to the Usual CSS Sprite to Reduce HTTP Requests




I just found this little tidbit today. If you ever have a problem with too many HTTP requests, this could be a solution for you over a CSS sprite. I’m using this approach for my CSS backgrounds that are simple small icons. I would not recommend this approach for anything much larger. FYI: IE8 limits URIs to max length of 32KB.

To help with this approach, you’ll need a couple tools. Here are the few I found:

Obviously, you can always write your own :)

So, this is what I wanted:

image

My original CSS looked like this:

a#createarticle {padding-left: 20px; background: url(/i/ico-addarticle.png) no-repeat center left}

This code will make two HTTP requests, one for the stylesheet and another for the icon. (assuming the above code is in a stylesheet, which in my case, it is)

To eliminate the additional HTTP request, I changed my CSS to look like this:

#createarticle {padding-left: 18px; background: url(data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBAQFBAYFBQYJBgUGCQsIBgYICwwKCgsKCgwQDAwMDAwMEAwODxAPDgwTExQUExMcGxsbHCAgICAgICAgICD/2wBDAQcHBw0MDRgQEBgaFREVGiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICD/wAARCAAQAA8DAREAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAQIHCP/EACUQAAICAQIEBwAAAAAAAAAAAAECAwQSAAUGERMhFCIjMTJSgf/EABYBAQEBAAAAAAAAAAAAAAAAAAAEBf/EABwRAQABBAMAAAAAAAAAAAAAAAARAQISIRMxQf/aAAwDAQACEQMRAD8A0nUoVpKMEhhjZ2jRmZkUkkqOZJI0DVl8NajEXlimOEkPIBQwQtknL2+HcaA0b1JKVdHsRo6xoGVnUEEL3BGgktniveJ6lafZbtmfjYSP19mJ6kYbEB/QzKqqKz4nH9+2TzXzqcprpHnXzt//2Q%3D%3D) no-repeat center left}

This might look intimidating, but it’s really pretty simple. You simply replace the “/i/ico-addarticle.png” in the first sample with the generated base64 from one of the tools mentioned above.

To get the base64, I used A Blue Star because I wanted to upload an image and get the base64, but you could also use the greywyvern.com and that’s what I’ll walk through now.

So I’ll grab an icon from famfamfam.com (which is where I get almost all my icons) and paste the URL on the greywyvern.com site.

Step 1: Grab URL
Paste it into the URI textbox on greywyvern.com like this:

image

Step 2: Generate Results
Click Submit Query & you’ll get this:

image

Step 3: Copy & Paste Results
Copy ALL the textarea and paste it into either the src of an img object or into the url of a CSS background attribute.

If you like your CSS to be readable and don’t want to deal with looking at base64, then I would stick to the CSS sprite, but I thought this method was cool. Especially for icons next to hrefs that don’t change a lot. However, I think the configuration for this is much simpler than a CSS sprite and having to deal with the different margins, widths, etc that come along with a CSS sprite :)

Thanks for reading!

kick it on DotNetKicks.com

Saturday, December 26, 2009

CSS – It’s been a while old friend…




I remember back in 2003 reading Zeldman’s book called Designing with Web Standards and it is one book that truly changed the way I was marking up my pages. Since then, Zeldman’s on his 3rd edition and I haven’t developed a site using table-based layout.

Since the baseline of standards came into play, I have developed many sites with css-based layout and thought I was doing good. Well my wife had this little project for me and I thought I’d look and see if anything has changed or if there are any new standards I could really start using since I last started using back in 2003. I think I’ve researched one other time around 2005 for CSS sprites, so it appears I look into CSS every couple years or so. I guess it doesn’t change too often, which is a good thing!

Basically, what I found was that there are some new things out there. You have the CSS Pseudo-classes (kinda new), the reset stylesheet, the 960 grid, the YUI library, etc. I’ve been developing and dealing with a lot of these headaches just by figuring out “hacks” myself, but obviously there has been progress and I’ve just missed out the last couple years.

So based-off the recent research, these are the things I’ve started to use.

  1. reset.css – I ended up using Eric Meyer’s Reset CSS
    • I did consider using Yahoo’s since it’s hosted and probably already cached on a lot of different end-user machines, but ultimately went with the “Master of CSS”.
  2. Taking advantage of a type of if statement for IE, which looks like this:
    <!--[if gte IE 7]><!-->
    <link rel="stylesheet" type="text/css" media="screen, projection" href="~/_c/screen.css" />
    <!-- <![endif]-->
    <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen, projection" href="~/_c/ie.css" /><![endif]—>
  3. Taking advantage of having one reference to a stylesheet called “screen.css”. My screen.css looks like this:
    /* import css and hide on IE/Mac \*/
    @import url("reset.css");
    @import url("lo.css"); /*lo = Layout*/
    /* end import/hide */
  4. There are a couple of Pseudo-classes I’m using in my CSS and they are :first-letter and :after…of course I’ve always used :visited, :hover, :active, and :link
    • I’ve noticed the pseudo-classes seem to be the least dependable other than those relating to anchors.

As of right now, that’s all I’m using to help my layout. I will probably end up using some of the tools on the YUI site and possibly the 960 grid system. I  haven’t yet though.

Whenever I go learn about CSS, there are a couple main places I go. They are:

I usually look at their source first to see if I see commonalities and if anything looks different than I’m used to seeing. Occasionally I’ll buy a book on the topic, but it’s been a while…probably 2 years.

So there’s the what’s new with CSS to me…I’m sure most of you are thinking…shouldn’t this post have been made 2 or 3 years ago?

Ah well, it’s done now! Have a good one and thanks for reading!

kick it on DotNetKicks.com

Related Posts Plugin for WordPress, Blogger...