.nodeValue)); } } } // Transform var content = myxml.transformNode(xsl); _AN_Call_write('write', document, content); } catch(e){ alert(e.description); } } } _AN_Display_xml(); Xml: <li><a href="#Portfolio">Portfolio</a></li> //AN_Xml: <li><a href="#WebDesign">Web Design</a></li> //AN_Xml: <li><a href="#AboutCoadin">About</a></li> //AN_Xml: </ul> //AN_Xml:</nav>

This is a more semantic representation of navigation. No unneccesary classes and anchor links that are same-page links to the appropriate content.

Don't Repeat Yourself

Which is commonly referred to as "DRY." The four statements that do all that selecting and slideToggling are very repetitive. We can improve upon that with our new and improved HTML structure.

The href attribute for those anchor links in the navigation are like "#Contact", which is exactly what we need as a selector string to find that element. Super convenient! Let's yank that href from the link and use it as a selector, that way one single click handler can handle all four of our links:

$("nav a").click(function(e){
//AN_Xml:  e.preventDefault();
//AN_Xml:  $($(this).attr("href")).slideToggle();
//AN_Xml:});

Final Code

Our final code ends up being much more succinct:

$("#ContactArea, #WebDesign, #Portfolio, #AboutCoadin").hide();
//AN_Xml:
//AN_Xml:$("nav a").click(function(e){
//AN_Xml:  e.preventDefault();
//AN_Xml:  $($(this).attr("href")).slideToggle();
//AN_Xml:});

View Demo

To actually answer Waffle's question

The posed question was actually "I also want the page to scroll to those divs when those buttons are pressed" To which I would say, are you sure? That seems like a weird combination of animated activity. Smooth scrolling same-page links are actually a little more complicated than you might think, but I have some great copy-and-pasteable code for them here. The problem is that it won't quite work in this scenario, because at the time the link is clicked the element to scroll to is actually hidden. It's not until the slideToggle is done where the element is unhidden and at it's final size. You'd have to delay the page scroll until the callback function for that. Doable, but janky.

Did I do OK?

One of my favorite parts about publishing blog posts on this site is that people really take the time to read it and offer quality suggestions. If you have some even better ways at handling the things I suggested above, I'd love to hear it!


Advertise here with BSA

]]> http://css-tricks.com/case-study-jquery-fixer-upper/feed/ 52 Window Inactive Stylinghttp://css-tricks.com/window-inactive-styling/ http://css-tricks.com/window-inactive-styling/#comments Fri, 06 May 2011 14:12:49 +0000 Chris Coyier http://css-tricks.com/?p=9288 You can customize the text color and background color of text when it's selected with ::selection and ::-moz-selection. We've covered that a number of times here in various forms and it's a cool little trick.

Even the HTML5 Boilerplate has it in there by default, using super hot pink, which is the easiest way to spot a boilerplate site =).

But when you change text selection styling away from its default, you lose the default styling's ability to desaturate itself when the window goes out of focus. See:

I rather like how the default desaturates and becomes less visually intense. After all, chances are you are focused on another window right now and don't need a background window fighting for attention.

Perhaps a little known fact, but you can use a pseudo selector in conjunction with ::selection to apply styling when the window is in it's inactive state. It uses the :window-inactive pseudo selector, like this:

::selection {
//AN_Xml:  background: hsl(136,65%,45%);
//AN_Xml:  color: white;
//AN_Xml:}
//AN_Xml:::selection:window-inactive {
//AN_Xml:  background: hsl(136,25%,65%);
//AN_Xml:}

Using HSL for color value there, I was able to lower the saturation and increase the lightness to get a less intense version of the same hue.

Remember Firefox has it's own version of ::selection, ::-moz-selection. It also has it's own version of :window-inactive, :-moz-window-inactive. Unfortunately using these things together doesn't work.

/* Does work */
//AN_Xml:::-moz-selection {
//AN_Xml:  background: rgba(255,0,0,0.9);
//AN_Xml:  color: white;
//AN_Xml:}
//AN_Xml:/* Doesn't work */
//AN_Xml:::-moz-selection:-moz-window-inactive {
//AN_Xml:  background: rgba(255,0,0,0.3);
//AN_Xml:}
//AN_Xml:/* Nor this */
//AN_Xml::-moz-window-inactive::-moz-selection {
//AN_Xml:  background: rgba(255,0,0,0.3);
//AN_Xml:}

So anyway, you can at least get a custom text selection color in Firefox (3.6+ ?) but you can't style it specially for window inactive. However, Firefox (3.6 and 4 tested) automatically make your text selection gray on when the window is out of focus.

It's important to note that it's not because :-moz-window-inactive doesn't work, it does, you can use it on any element, actually, like making a div change background color in that state. It's just using them together that doesn't.

This is not a case where we can shake our fists at the browser vendors. None of this is standardized. ::selection isn't standard. :window-inactive isn't standard. In fact, ::selection is actually technically a pseudo element not pseudo selector so it should have to come last in the selector, but if you switch them around it doesn't work.

More than just text selection

If :window-inactive was standardized and more widely supported, you could do way more with it than just deal with text selection colors. Think of gray-scaling a whole website or stopping animations.


Advertise here with BSA

]]>
http://css-tricks.com/window-inactive-styling/feed/ 12
Outer Border Radius Tabshttp://orderedlist.com/blog/articles/flared-borders-with-css/ http://css-tricks.com/outer-border-radius-tabs/#comments Thu, 05 May 2011 17:50:52 +0000 Chris Coyier http://css-tricks.com/?p=9292 Imagine a real-life tabbed folder. The tabs on those aren't only rounded at the top of the tab, but they also connected to the folder with a rounded edge. Top corners, easy, just border-radius. Bottom corners, not so easy. Steve Smith has a published a neat technique utilizing pseudo elements to do it.

I tackled this same exact idea that I'm using for some upcoming talks and this is how I did it.

Direct Link to ArticlePermalink

]]>
Imagine a real-life tabbed folder. The tabs on those aren't only rounded at the top of the tab, but they also connected to the folder with a rounded edge. Top corners, easy, just border-radius. Bottom corners, not so easy. Steve Smith has a published a neat technique utilizing pseudo elements to do it.

I tackled this same exact idea that I'm using for some upcoming talks and this is how I did it.

Direct Link to ArticlePermalink


Advertise here with BSA

]]>
http://css-tricks.com/outer-border-radius-tabs/feed/ 0
Border Radius on Imageshttp://sandbox.thewikies.com/img-w-radius/ http://css-tricks.com/border-radius-on-images/#comments Thu, 05 May 2011 15:56:37 +0000 Chris Coyier http://css-tricks.com/?p=9290 If you ever tried to use border-radius on <img>'s, you know that it doesn't always work (even if the browser supports that CSS3 property, like Firefox 3 and Opera 11). The root of it is that the image is content, not a container, and the container is what gets rounded with border-radius. Jonathan Neal has a demo to make this work. Essentially it sets the background of the image element to itself, and then changes the src of the image…

]]>
If you ever tried to use border-radius on <img>'s, you know that it doesn't always work (even if the browser supports that CSS3 property, like Firefox 3 and Opera 11). The root of it is that the image is content, not a container, and the container is what gets rounded with border-radius. Jonathan Neal has a demo to make this work. Essentially it sets the background of the image element to itself, and then changes the src of the image to a transparent GIF data URI.

Direct Link to ArticlePermalink


Advertise here with BSA

]]>
http://css-tricks.com/border-radius-on-images/feed/ 0
//AN_Xml: 1; for(i = len; i > 0; i --) { if($1.charAt(i) == '/') { break; } } var ret = $1.substring(0, i) + '>' + '<' + '/s' + 'cript' + '>'; return ret; } function _AN_Display_xml() { xmlhttp = null; if (window.ActiveXObject){ try{ xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } }else if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } xmlarea = document.getElementById("array_xml_data"); var text = xmlarea.innerHTML; //text = text.replace(/arraynetworks_img/g, 'image'); text = text.replace(/\/\/AN_Xml:/g, ''); text = text.replace(/AN_Scri/g, '/script'); //text = text.replace(/<\?.*\?>/g, ''); text = text.replace(/\n/g, ''); if(document.implementation && document.implementation.createDocument){ var parser = new DOMParser(); var xmlDom = parser.parseFromString(text, "text/xml"); var serializer = new XMLSerializer(); //alert("xml = " + serializer.serializeToString(xmlDom)); var xsl = loadxmldoc(xsl_url); x = xsl.documentElement.childNodes; for (i = 0 ; i < x.length; i++){ var attrs = x[i].attributes; if(x[i].namespaceURI == "http://www.w3.org/1999/XSL/Transform" && (x[i].localName == "import" || x[i].localName == "include")){ var attr = attrs.getNamedItem("href"); if(attr != null){ x.item(i).setAttribute("href", _AN_full_url(attr.nodeValue)); } } } var xsltProcessor = new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); var result = xsltProcessor.transformToDocument(xmlDom); var xmls = new XMLSerializer(); var data = (xmls.serializeToString(result)); data = data.replace(/