Spring-cleaning Unused CSS

Addy Osmani intros a Grunt task for removing unused CSS from your stylesheet before serving it.

While this is certainly a worthy goal, I look at the quotes from people who reduced their stylesheets by 3/4 or more and I’m like holy crap what kinda shop are you running over there?! I know “test, don’t guess”, but I’d guess that pretty close to 0% of the styles I write are unused. I’m sure HTML changes over time make a orphaned rule here and there, but I’d guess that is largely insignificant.

If you’re going to do this, make sure you run it against lots (if not all) of your pages so you aren’t removing selectors that are in use, just not on every page. I know I write minor styles all the time that make their way into the global stylesheet since that is cached and used anyway.

Direct Link to ArticlePermalink


Spring-cleaning Unused CSS is a post from CSS-Tricks

from CSS-Tricks http://ift.tt/1for8xJ

Advertisements

Rotated Table Column Headers

Say you have a table header (i.e. <th>) of “Number of Howler Monkey Species by Country” and the data in the corresponding <td> is like “3”. That’s an awkward mismatch of width.

Awkward

Perhaps not a huge problem for two columns, but if you had 20 that would be very hard to navigate and a poor use of space. A better use of space is to rotate the headers so that the column width can be much narrower.

Rotating 90-degrees is too far though. It makes it hard to read.

Interestingly, we get just about the same amount of space saving if we rotate the headers 45 degrees instead, and they are much easier to read.

The Trick

There are a couple of tricks here.

We’re going to need to user transform: rotate() to angle the headers. Chrome/Safari let you do that right on the <th>, but I had trouble with the text disappearing in Firefox that way, so let’s do that within a nested <div>. That

we’ll force to be the width we want the column to be (it also didn’t work to force the cell narrow directly). We’re going to need another nested element as well, so…

<th class="rotate"><div><span>Column header 1</span></div></th>
th.rotate {
  /* Something you can count on */
  height: 140px;
  white-space: nowrap;
}

th.rotate > div {
  transform: 
    /* Magic Numbers */
    translate(25px, 51px)
    /* 45 is really 360 - 45 */
    rotate(315deg);
  width: 30px;
}
th.rotate > div > span {
  border-bottom: 1px solid #ccc;
  padding: 5px 10px;
}

Note the magic numbers there. I bet some of you are smart enough to figure out the mathematical relationship to all the other numbers going on in there. In fact, my example started out life as a fork of Jimmy Boney’s Column Header Rotation article. I was able to do it without the skew() stuff he was doing which I think makes it a bit simpler, but he also had figured out some math stuff using tan() and cos() which might be a good starting point if you start digging in yourself.

Fallback

If you go down this road, you might wanna make sure you aren’t applying rules that screw up the table if the transforms don’t work. Modernizr can test for that and apply support/non-support classes to the <html> element, so you can write stuff like:

/* These aren't needed and will be weird if transforms don't work */
.csstransforms & th.rotate {
  height: 140px;
  white-space: nowrap;
}

How you want to do the fallback is up to you, but it could be worse than just having the table be super wide:

My final demo has this in place.

Demo

See the Pen Rotated Table Headers by Chris Coyier (@chriscoyier) on CodePen.

It’s in Sass in case you want to fork it and figure out some awesome way to use variables and math and stuff to make it more adaptable.


Rotated Table Column Headers is a post from CSS-Tricks

from CSS-Tricks http://ift.tt/QkOChX

Hatin’ on Web Tech

This article “Shadow DOM” by Steven Wittens is only vaguely about the Shadow DOM. It’s mostly about how awful everything is. HTML sucks, CSS sucks, the DOM sucks, SVG sucks, MathML sucks… I don’t want to pick on Steven. He is, without a doubt, many (many) times smarter than I am and has well articulated points. Let’s go wider.

I see this regularly from people who have been at this a long time and are very smart. They develop a dislike of the systems we have to work with. They see all the warts, mistakes, and especially what they see as deep systemic flaws or historical turns down the wrong path. This is all made worse as we trapse forwards, building upon these perceived cracks in the foundation.

They always have very good points. It’s hard to do anything but nod, because they are right, the web does some whacky stuff and has failed us in many ways. Wouldn’t it be wonderful if we could throw it all away and work with some new perfectly designed system that meets everyone’s modern needs. Sure, of course it would. Do you want to live in your town or a utopian village? I’ll take utopia.

Obligatory follow up sentence: but utopia doesn’t exist!

There is no alternate layout language for the web. There is no alternative way to deliver accessible content. There is no better replacements vying for the lead here. That’s because that’s a monumental task. Any contender would need to:

  1. Develop a new system for everything is empirically better.
  2. Get a world of developers to agree that this new system is better and demand it.
  3. Get standards bodies (or something like it) to support it so there is oversight and an independent source of implementation information.
  4. Get all browsers to agree and implement it perfectly.

lol right.

All those things are so insurmountably difficult that it’s no wonder it is rarely even attempted. I’d argue that #1 is the hardest. There are plenty of flaws with our current system, but imagine starting from scratch with something this complex.

I feel like what is going on now in web tech is that these problems are trying to be solved on a smaller scale.

It sure is a bummer HTML is our content, but also responsible for semantics, right? It would be nice to do whatever we wanted in there and not worry we were hurting semantics. Hopefully Shadow DOM can help with that. Maybe it can also help with CSS being to over-arching when you don’t want it to be.

Maybe flexbox, grid layout, and regions can be the truly powerful and intuitive layout system we’ve always needed, without the accessibility issues inherent to tables.

SVG isn’t perfect, but maybe it’s still better than using a raster image format for a vector image? Maybe SVG has the potential to help with icon systems on sites in a better way? Maybe we can start using a new image format that increasingly works with modern browsers.

Maybe preprocessors can be a solution to ease authoring of these complex languages and reduce complexity?

Perhaps we can extend the web right now how we might want to see it, using existing tech.

These things are proving that we can make the web better. We can do it slowly. We can do it with the help of standards bodies. We can educate developers and change their thinking over time. We can use the browsers already out there, so we don’t need to fight public behavior.

I think that sounds nice. And I don’t think we have much of a choice.


Hatin’ on Web Tech is a post from CSS-Tricks

from CSS-Tricks http://ift.tt/NVVUXm

SVG & WordPress Custom Fields

The following is a guest post by Ian Marquette. Ian learned that SVG can have a <text> element, meaning that text could come from a dynamic source while still being able to do cool custom SVG-specific stuff to it.

I was recently working on a WordPress-based website that needed an infographic. Being a proponent of responsive design, I drew the infographic in Illustrator and exported it to SVG for scalability. While tinkering around in the backend I discovered that you can add WordPress custom fields to SVG text elements that allow you to control text-based content from within your WordPress CMS. How awesome is that?

Here I’ll explain how I did it, and some further options you might find useful.

Preparing the SVG File

Create the graphic in your vector-editing software of choice. Add placeholder text to the area you’ll want to contain user-controlled text. Here I’ve created a simple graphic for demonstration purposes.

My SVG file. Note that the path is to demonstrate something uniquely SVG. It could be a filter or a stroke or anything else cool that SVG can do.

Now open your SVG file with your preferred editor. You’ll have to make some changes to the code. In my example the path had to be changed to a <textpath>, given an ID and linked to using xlink. If I didn’t do this, each individual character in my text would have its own tag, coordinates etc.

<svg width="1000px" height="300px" viewBox="0 0 1000 300"
     xmlns="http://ift.tt/nvqhV5" 
     xmlns:xlink="http://ift.tt/PGV9lw">
  <defs>
    <path id="MyPath"
          d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />
  </defs>

  <use xlink:href="#MyPath" fill="none" stroke="green"  />

  <text font-family="Helvetica" font-size="42.5">
    <textPath xlink:href="#MyPath">
      SVG Text on a path for WordPress!
    </textPath>
  </text>

</svg>

Here’s a live demo of some text-on-a-path:

See the Pen JoakC by Chris Coyier (@chriscoyier) on CodePen.

You can just copy and paste the markup straight into a WordPress template. You could also use on of the other methods of using SVG on your page, such as linking to the file as an object. Essentially it needs to be inline SVG, not SVG used as an or background-image.

You’ll want to replace the content between the <text> tags with the following code, replacing custom_field with whatever name you want to give yours:

<?php
  global $wp_query;
  $postid = $wp_query->post->ID;
  echo get_post_meta($postid, 'custom_field', true);
  wp_reset_query();
?>

Dropping that within the SVG will look like:

<svg width="1000px" height="300px" viewBox="0 0 1000 300"
     xmlns="http://ift.tt/nvqhV5" 
     xmlns:xlink="http://ift.tt/PGV9lw">

  <defs>
    <path id="MyPath"
          d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />
  </defs>

  <use xlink:href="#MyPath" fill="none" stroke="green"  />

  <text font-family="Helvetica" font-size="42.5">
    <textPath xlink:href="#MyPath">
       <?php
        global $wp_query;
        $postid = $wp_query->post->ID;
        echo get_post_meta($postid, 'custom_field', true);
        wp_reset_query();
       ?>
    </textPath>
  </text>

</svg>

Now create a custom field in the WordPress CMS with this label and populate it.

Now if you check out that page, you should see the custom text sitting inside your custom SVG graphic! Of course custom fields are just one way to do this that is rather extensible. You could use do the post title this way, menus, or anything else that dynamically spits out text from any CMS.

Custom field added to your SVG

Once it’s in there the text can be styled just like regular markup. For instance:

...
<textpath class="text-path" ... >
  ...
.text-path {
  fill: orange;
}

Or any other SVG CSS property. That means using custom fonts via @font-face work just fine. You also have access to nice features such as SVG filters and animation.


SVG & WordPress Custom Fields is a post from CSS-Tricks

from CSS-Tricks http://ift.tt/1h1I3dv

CGI Paul Walker in Fast & Furious Sequel?

Paul_Walker

When Fast & Furious star Paul Walker passed recently, the film sequel was put on hold. Now that producers are moving forward, and the question is how should they finish a film that is already more than half-way done filming?

There has been talk of rewriting, re-editing or even using stand-ins to film the remaining scenes.

But one suggestion has stirred a lot of controversy: Use a CGI Paul Walker! (Basically a computer generated likeness) Some people have suggested this is bad taste, disrespectful, creepy.  Maybe it is, I don’t know.

BUT… I personally think they SHOULD use CGI Paul Walker. And here’s why. (And it is not because CGI has improved. That doesn’t matter!)

His Real Performances!

Typically, I’m against bringing back actors but the movie was already at least half-way done filming before Paul Walker passed. SO they have his REAL last performances in the film.

Now since movies are typically filmed out-of-order,  it’s possible these finished scenes are missing important connecting moments that are needed to tell the story and maintain continuity.

So producers have to choose:

1. Cut his character entirely and re-shoot/rewrite the film without Paul Walker. (Movie insurance would cover the cost):

END RESULT: No Real Paul & No CGI Paul.

2. Use a CGI-version of the character to finish the missing scenes and keep the majority of his REAL performance in the movie:

END RESULT: Real Paul with Some CGI Paul.

Whether you are a fan of the movies or not, they were always fun and well made.  And these films may well be his legacy so I think it would be a shame to cut all of his last performances over some CGI that is only meant to help keep the true Paul Walker in the film so producers don’t have to cut him out.

NOTE: I’m not tied to production so I’m not sure the specifics of how they plan to do the CGI stuff but I wanted to make this post to offer some perspective. Hopefully they have the same idea!

Vía Video Copilot Blog http://ift.tt/Q2FRZS

I’m going to NAB!

AK_NAB

 

Are you going to NAB in Las Vegas?

If so please stop by the Adobe booth on Tuesday and Wednesday for my presentation! I’ll be on around 2pm both days. Come one, come all, I’d love to have a chance to meet some of my digital friends!

Plus you can hang around the show floor and see many great new gadgets! Should be fun!

Vía Video Copilot Blog http://ift.tt/1iKQ5Ie