terra: (Default)
[personal profile] terra posting in [community profile] vigils

One of the main differences between LJ and DW and how they let you code is that DW allows inline CSS in comments. This is a wonderful thing that can make your comment formatting much more elegant, because you can handle all of your formatting with a single string of code instead of using a string of <font><b><i>!

First, some codebabble

In the beginning, HTML was invented by programmers, and it made some really ugly looking Geocities c. 1997 style sites. Designers, wanting to make things not ugly, distorted the <table> tag in hideous ways in an attempt to trick webpages into looking presentable. But this was a trick, and it made for some really complicated coding that didn't translate well across browsers. As the web has evolved, best practices teach to separate content (the text, ideas, and meaning of the code) from style (the font and color and background images and fun stuff) by using HTML for content and CSS for style.

If you've been around LJ/DW for a while, or are watching this community, you probably know something about copy+pasting CSS into a "customize style" area, and that's a good way to understand what CSS does. It can radically change the look of a site, without changing its basic ingredients! This is important because it means that the basic "stuff" of a site can be interpreted even if the style doesn't load, which means screenreaders work better, search engines work better, mobile devices work better and the internet is a happier place.

Some people recognize CSS when it's written out like this:

span.demo {
font-size: 12px;
font-family: Georgia, serif;
font-weight: bold;
font-style: italic;
color: blue;
}

It follows a basic formula of property-name: value; and is framed off by curly brackets. You can probably guess from that code that this makes some bolded, italicized Georgia-fonted blue text sized 12px, and that's what I'd put in a CSS file if I wanted to make something bold and blue.

But you can also stick CSS directly into a tag you are writing up by way of the style property. Something like this:

<span style="font-size: 12px; font-family: Georgia, serif; font-weight: bold; font-style: italic;color: blue;"></span>

This is the exact same bit of formatting, but instead of sticking it at the beginning of the document, I'm dumping it directly into the tag I'm applying to. Instead of using curly brackets, I'm using style="", but it follows the exact same property-name: value; rule. And look, blue text.

The great thing about CSS is how flexible it is. You can apply the style declaration to most HTML tags. I.e.

<i style="color: red;"></i>

Makes your i tag red!

It's pretty nifty!

And now, a word about <span>

I see a lot of people using <font> when they should be using <span>. <font>, as a tag, is deprecated— meaning it's been declared out of date and marked off for future termination. (Read about it here, here and here.) <span> is its closest new-fangled replacement. A <span> tag doesn't do anything on its own, but it provides a container to stuff CSS in. Basically, if you want to make text look different and pretty, but don't want to change anything else about it, <span> is the tag for you.

Because CSS is so powerful, you can do all kinds of great stuff by putting <span> and the style property together. Here are some examples.


Georgia is a nice font.

<span style="font-family: Georgia, serif;">Georgia is a nice font.</span>

This text is large and in charge.

<span style="font-size: 24px; font-weight: bold; font-style: italic;">This text is large and in charge.</span>

This is the skin of a killer!!

<span style="background-image: url(http://i361.photobucket.com/albums/oo54/crackysparkles/sparkles/sparkle.gif);">This is the skin of a killer!!</span>

Fourth-walling! Lolrandom! Chimichanga!

<span style="background-color: yellow; color: black; padding: 2px;">Fourth-walling! Lolrandom! Chimichanga!</span>

TH1S 1S 4 TROLL T3XT QU1RK

<span style="font-family: Courier, monospace; color: #008282; font-weight: bold;">TH1S 1S 4 TROLL T3XT QU1RK</span>

For more of these, someone put together a whole big list of 'em.


Get the picture? If you want to experiment, here is a list of all the CSS properties, sorted alphabetically. If you have any questions, I'll do my best to answer them.

Comment Depth: 1

Date: March 25th, 2012 03:03 am (UTC)
jotunheim: (Default)
From: [personal profile] jotunheim
THANKS PROFESSOR ALEX
Comment Depth: 1

Date: March 25th, 2012 03:18 am (UTC)
glorious: A field of white flowers in bloom (Default)
From: [personal profile] glorious
This is amazingly helpful. Thank you!
Comment Depth: 1

Date: March 25th, 2012 03:29 am (UTC)
tropicsbear: Tadashi carrying Ainosuke bridal style (Default)
From: [personal profile] tropicsbear
Does the span tag also work for text alignment?
Comment Depth: 3

Date: March 25th, 2012 03:52 am (UTC)
tropicsbear: Tadashi carrying Ainosuke bridal style (Yo: fanboy)
From: [personal profile] tropicsbear
Ooooh thanks.
Comment Depth: 1

Date: March 25th, 2012 03:55 am (UTC)
superdickery: (Default)
From: [personal profile] superdickery
This is very useful, thank you!
Comment Depth: 1

Date: March 25th, 2012 04:21 am (UTC)
From: [personal profile] infini
This is really helpful, thank you! :)

Though, the span tag doesn't seem to work in the RSS feed?
Edited Date: March 25th, 2012 04:22 am (UTC)
Comment Depth: 1

Date: March 25th, 2012 08:38 am (UTC)
melodise: ((misc) art.)
From: [personal profile] melodise
Wow this is great! Thank you!
Comment Depth: 1

Date: March 28th, 2012 04:35 am (UTC)
From: [personal profile] ex_choir339
Thank you for this!
Comment Depth: 1

Date: June 7th, 2012 12:35 am (UTC)
augustine: (bffs)
From: [personal profile] augustine
this is pretty nifty, thanks for the info :]

Tags