A quick CSS3 sibling test with the video tag

I am working on a little widget that uses the html5 video tag on one of my test sites: Fyvr.net.
I wanted to display related information when the video is playing. The sibling selector makes this easy.

Here’s the basic markup

<li>
<video>...</video>
<p>...</p>
</li>

I wanted the paragraph to appear when the video is selected. So here’s the simple CSS

section#videolist li {
	position:relative;
}
section#videolist li p {
	display:none;
	position:absolute;
	bottom:-100px;
	left:0;
}
section#videolist li video:focus+p {
	display:block;
}

The sibling selector (+) is telling the browser to display the paragraph as block when its video brother has focus. This is a rough test. There could be some accessibility issues and I’ll need to test this out. Obviously this will not work in Internet Explorer.

Quick hint for using the YUI Container library

The YUI Container libraries work with visibility:hidden to hide your targeted div. I’ve spent too many hours trying to figure out why something wasn’t working only to realize I had display:none in the CSS. So, when you use these libraries remember visibility, not display. It’s a mantra that could keep you from pounding your forehead into a keyboard repeatedly.

And don’t forget to keep your libraries updated!

Multiple medias in the print.css

Let’s say you have a printer-friendly page that consolidates information from multiple sections. The page uses the print.css as all instead of just print. Let’s also assume you want to show things on the screen, such as a link back to the referral page, and different elements on the printed page, such as the url of the referral page.

Simple HTML Example

Go back to the last page.

http://www.last-child.com/multiple-medias-in-the-print.css

CSS solution

You can include multiple medias in one style sheet. Just declare the special rules under @media


@media print{/*show printer only elements, hide screen only elements */
.noprint {display:none;}
.print {display:block;}
}

Your main CSS file would have already declared .print {display:none;}.

The perfect FAQ page ! – by Thierry Koblentz

— This was originally published on www.tjkdesign.com. Visit the original site for updated code and to see a working copy of the script. Thierry has created a Dreamweaver plugin to make this super-easy to add to your site!

This is about using a Definition List and the DOM to create a nice FAQ page where clicking on the DTs (the questions) “toggles” the associated DDs (the answers).

Note: If you’re already using this solution, please check your version number (this is version 1.5.4). Before you download the newest version I suggest to go through the entire article again (since a few things have changed).

This is what it does:

Open AllClose All

Question 1?
The vitality of conceptual synergies is of supreme importance exploiting the productive lifecycle working through a top-down, bottom-up approach. To focus on improvement, not cost, from binary cause and effect to complex patterns, while those at the coal face don’t have sufficient view of the overall goals.
Question 2?
To focus on improvement, not cost, from binary cause and effect to complex patterns, while those at the coal face don’t have sufficient view of the overall goals. To ensure that non-operating cash outflows are assessed.
Question 3?
The vitality of conceptual synergies is of supreme importance exploiting the productive lifecycle working through a top-down, bottom-up approach. To focus on improvement, not cost, from binary cause and effect to complex patterns, while those at the coal face don’t have sufficient view of the overall goals. To ensure that non-operating cash outflows are assessed. The vitality of conceptual synergies is of supreme importance exploiting the productive lifecycle working through a top-down, bottom-up approach.
Question 4?
The vitality of conceptual synergies is of supreme importance exploiting the productive lifecycle working through a top-down, bottom-up approach. To ensure that non-operating cash outflows are assessed.
Question 5?
The vitality of conceptual synergies is of supreme importance exploiting the productive lifecycle working through a top-down, bottom-up approach. To focus on improvement, not cost, from binary cause and effect to complex patterns, while those at the coal face don’t have sufficient view of the overall goals. To ensure that non-operating cash outflows are assessed.

The main advantages of the basic technique (related to the DL):

  • It uses semantic markup.
  • It degrades nicely (hidden elements are visible in script-disabled UAs).
  • DTs do not appear as links without script support.
  • It does not use inline event attribute (onclick()).
  • It does not require A elements in the markup.
  • It is screen-readers “friendly”.
  • It is keyboard “friendly”.
  • It is IE Mac compatible.
  • It relies on one single hook.
  • It allows the author to add/move/delete DT/DD pairs easily (there is no variable in the script to edit and there are no class or ID to include nor change).
  • It is “powered” by a very light script (3Kb).

About the “Show All/Hide All” “links”:

  • they let the user expand all answers at once, so it is possible to search the document.
  • they are hidden from Javascript-challenged browsers.
  • they can be “Named Anchors”, images or SPANs (actually they can be any inline elements or any other elements styled as inline).

This is more or less a plug-and-play solution (script and stylesheets are at the bottom of this page).
You’ll need to:

  1. Create a Definition List (do not use more than one DD per DT.); the markup for the one above looks like this:

    Question 1
    The vitality of conceptual synergies...
    Question 2
    To focus on improvement, not cost, ...
    Question 3
    The vitality of conceptual synergies...
    Question 4
    The vitality of conceptual synergies...

  2. Assign a specific ID to your DL:

    <dl id="TJK_DL" />
  3. Download this ZIP File (3Kb) and unzip its content in the same directory as your FAQ page.
  4. In your FAQ page, right above the closing headtag cut and paste the following:
    <script type="text/javascript" src="TJK_ToggleDL/TJK_ToggleDL.js"></script>
  5. Call the script, for example using:

    <body onload="TJK_ToggleDL()">

    Note: In case you want to add multiple onload handlers to a page, make sure to read executing JavaScript on page load.

  6. In order to use the “Show All” / “Hide All” feature, you will need to create 2 named anchors with specific IDs (TJK_ToggleON and TJK_ToggleOFF). Dreamweaver users can take advantage of the “Named Anchor” icon in the toolbar to easily create the required markup. Dreamweaver will plug the name attribute as well, but that’s OK, you can either delete it or ignore it.
    This is the markup I’m using in this page:

    <a id="TJK_ToggleON">Open All<<a id="TJK_ToggleOFF">Close All</a>

    Note: adjacent anchors are confusing in text-browsers.

    important noteYou can also replace these Named Anchors with other inline elements, for example SPAN or IMG (yes, images). Just make sure to set the proper IDs.

  7. Because we want to hide these “links” from script-challenged UAs, you need to include the following rule somewhere inside your stylesheet:
    #TJK_ToggleON,#TJK_ToggleOFF {display:none}

    Note: You can also use a style element to include this rule in the head of your document (your FAQ page).

You’re done!

Feel free to edit the rules in the CSS file to fit your needs.

important noteNote: in case your questions are more than one line long, you may want to change this: “background:0 50%” to this: “background:0 0” and add “display:block” to the #TJK_DL dt a {} rule (to avoid any “wrapping”).

For the curious

TJK_ToggleDL.js


// Copyright 2006 | Thierry Koblentz - www.TJKDesign.com All Rights reserved
// TJK_ToggleDL() Version 1.5.4 report bugs or errors to thierry@tjkdesign.com
if (document.getElementById && document.getElementsByTagName){
document.write("<link href=\"TJK_ToggleDL/TJK_ToggleDL.css\" type=\"text/css\" rel=\"stylesheet\" />")
document.write("<link href=\"TJK_ToggleDL/TJK_ToggleDL_ie5mac.css\" type=\"text/css\" rel=\"stylesheet\" />")
}
function TJK_doToggleDL(x){
var zDD=document.getElementById('TJK_DL').getElementsByTagName('dd');
var zDT=document.getElementById('TJK_DL').getElementsByTagName('dt');
zDD[x].className=(zDD[x].className=='hideDD')?'showDD':'hideDD';
zDT[x].className=(zDT[x].className=='DTplus')?'DTminus':'DTplus';
}
function TJK_ToggleDLopen(){//we open all of them
var zDD=document.getElementById('TJK_DL').getElementsByTagName('dd');
var zDT=document.getElementById('TJK_DL').getElementsByTagName('dt');
for(var i=0;i<zDT.length;i++){
zDD[i].className='showDD';
zDT[i].className='DTminus';
}
return false;
}
function TJK_ToggleDLclose(){//we close all of them
var zDD=document.getElementById('TJK_DL').getElementsByTagName('dd');
var zDT=document.getElementById('TJK_DL').getElementsByTagName('dt');
for(var i=0;i<zDT.length;i++){
zDD[i].className='hideDD';
zDT[i].className='DTplus';
}
return false;
}
function TJK_ToggleDL(){
if (document.getElementById && document.getElementsByTagName){
var zDT=document.getElementById('TJK_DL').getElementsByTagName('dt;
var zDD=document.getElementById('TJK_DL').getElementsByTagName('dd');
var ToggleON = document.getElementById('TJK_ToggleON');
var ToggleOFF = document.getElementById('TJK_ToggleOFF');
if (ToggleON && ToggleOFF){
ToggleON.onclick = TJK_ToggleDLopen;
ToggleON.title = "Show all answers";
ToggleON.href = "#";
ToggleOFF.onclick = TJK_ToggleDLclose;
ToggleOFF.title = "Hide all answers";
ToggleOFF.href = "#";
}
for(var i=0;i<zDT.length;i++){
var zContent = zDT[i].innerHTML;
var zHref = "<a href='#' onclick=\"TJK_doToggleDL("+i+");return false\" title='Show/hide the answer'>";
zDT[i].innerHTML = zHref + zContent + "</a>";
zDD[i].className='hideDD';
zDT[i].className='DTplus';
}
}
}

TJK_ToggleDL.css


/* "Show All" + "Hide All" links */
#TJK_ToggleON,#TJK_ToggleOFF {border:1px solid #333;padding:0 5px;margin-right:5px}
/* zeroing out padding and margin */
#TJK_DL dd,#TJK_DL dt {margin:0;padding:0}
/* margin for the DTs (shorthand) */
#TJK_DL dt {margin:7px 0}
/* image and left padding for DDs */
#TJK_DL dd {background:url(answer.gif) no-repeat;padding-left:55px}
/* styling all anchors in the DTs */
#TJK_DL dt a {background:0 50% no-repeat;padding-left:32px;color:#000;text-decoration:none}
#TJK_DL dt a:visited {color:#666}
#TJK_DL dt a:visited:hover, #TJK_DL dt a:hover, #TJK_DL dt a:active, #TJK_DL dt a:focus {font-weight:bold}
/* the + and - gif in the anchors */
#TJK_DL .DTplus a {background-image:url(toggleDLplus.gif)}
#TJK_DL .DTminus a {background-image:url(toggleDLminus.gif)}
/**********************************/
/**********************************/
#TJK_DL .showDD {position:relative;top:0}
#TJK_DL dd,.hideDD{top:-9999px;position:absolute}
#TJK_ToggleON,#TJK_ToggleOFF {display:inline;cursor:pointer; cursor:hand}

Note: “cursor:hand” is for IE5 Win, but this declaration will make this sheet fail Validation. If Validation is important to you, you can either delete this declaration or move it inside a Conditional Comment.

TJK_ToggleDL_ie5mac.css


/**//*/
#TJK_DL .showDD {display:block}
#TJK_DL dd,.hideDD {top:0; position:relative; display:none}
/**/

For the DOM police

Earlier versions of this script did not use document.write(), I was using the DOM to plug the stylesheets in the HEAD element. Unfortunately, setting the rel attribute of the LINK element makes Safari “go blank” and STYLE fails in IE Win. So, I decided to go with what works!

important noteThis script should work in HTML and XHTML documents.