Posts Tagged ‘selectors’

CSS Selectors…learning something new is good!

Thursday, April 15th, 2010

Let be start off by saying the code I put up in my last post was wrong, it is corrected now. Didn’t realize it until I started clicking through some older posts a little bit ago, and noticed that EVERY link was getting a new tab. The code I wrote made it so that every href that started with ‘http’ should have target=”_blank”. I assumed the links within my blog would be relative, not absolute. WordPress got me on that one. Now it hits every href that does not contain my web address. Silly me.

Today I had to style/build a couple of pages my boss designed in Photoshop (which by the way, I really like – very clean design). The first one was easy because it contained a form, which had all the elements on the page for me to see. I had styled a submit button using a selector that finds an element that has a type = to something. This is what I used:

#divID input[type="submit"]

Now, when my boss saw it, he said “You could have just put an id or class on it.” Which is true, I could have, but I wouldn’t have learned anything. Styling it like that saved me on the second page. Why? Because the form on the second page was put in dymaically and didn’t have any ids or classes, but because of the above CSS, it still hit.

That CSS is basically saying look for an input within a div with and id of #divID, that has a type of “submit”. Pretty easy, but cool. Selectors are awesome, but each browser supports different things.