TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-11-2008, 10:54 PM   #1 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default adjacent selectors should allow for different elements

I just started implementing child selectors and adjacent siblings selectors into my CSS - previous to now I had used alternate classes or direct styles added to certain elements to get the effects I wanted, but I figured why not take advantage of what was available.

The problem I'm having is that it seems like adjacent sibling selectors (+) don't work with the body element. Anybody know why?

Code:
body + div {
/* css */
}
...should affect the first div element if it directly follows the body, but it doesn't. I tried to work around this by adding a span before the first div, and using the selector like so:

Code:
span + div {
/* css */
...almost worked, but it's affected all the divs, which it should only affect the first. I even tried some random elements like STRONG, just to mess around and see if it would work, but notta.

The adjacent selector is supposed to work on different elements but it seems so far that it only supports similar simple elements. p + p, h1 +h2, etc. No body + anything, or span + div...
-m
delayedinsanity is offline  
Reply With Quote
Old 07-11-2008, 10:55 PM   #2 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

Shouldnt you use a comma?
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 07-11-2008, 11:55 PM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Nope, that's if you want to style multiple elements.

Code:
/* style all the same */
h1, h2, h3 {
font-weight:700;
color:#222;
}

/* style first adjacent element, so the first p following a p, but not the third, fourth, fifth, etc or first */
p + p {
font-size:2em;
}
delayedinsanity is offline  
Reply With Quote
Old 07-13-2008, 04:56 PM   #4 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

An adjacent sibling is an element that follows right after another, as long as they both have the same parent.

Your problem is that the <div> is in the body, so they don't have the same parents. What you're looking for is the first-child pseudo-class.

body > div:first-child { } will select only the first <div> (in the body).
maZtah is offline  
Reply With Quote
Old 07-13-2008, 08:14 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Yeah I just hardwired the fix into the stylesheet, since :first-child isn't trustworthy. Thank you though.
-m
delayedinsanity is offline  
Reply With Quote
Old 07-13-2008, 09:21 PM   #6 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

True that current browsers (IE) don't support it.

Though, you could use jquery for it to work cross browser.

You should check out Selectors/firstChild - jQuery JavaScript Library for it.
maZtah is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:51 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design