Q: What is the difference between .selector, #selector and selector? I'm always guessing at which one to use.
A: selector is called a Type selector. These generally refer to site-wide HTML elements like <a …>…</a>, <body>…</body>, <h1>…</h1>, <h2>…</h2>, <table>…</table>, (<div>…</div>), etc.
note !
Since the wikidot-editor is no HTML-editor and a css-declaration is build out of html-selectors, you need to know the conversion of wiki-syntax to html-syntax. Therefore a list is provided at [somewhere]
If you use just the selector name in your CSS, ALL the containers of type selector will have the settings as described there. For simple sites this works great. However if you want to specify something for one (lets say) <H2> element, and you do not want it to affect other <H2> elements, you can create a class selector (.selector) and apply it to just a single <H2> element if you like.
.selector is called a Class selector. These are used to apply the class to a specific general used element. Imagine a page that you build up using a <table> element. (If you really are interested in CSS, you should try to stop doing this). You can imagine that there could be a table on that page to show some data. Well you want to show the data table, but not the layout table… to do this you can apply a class selector to your table. Here is some Wikidot syntax to demonstrate:
[[table class="datatable"]]
[[row]]
[[cell]]data[[/cell]]
[[/row]]
[[/table]]
If you add the class selector .datatable { … } to your custom CSS, your can apply the styles by using the syntax in the sample code above.
NOTE : Since it is a table, it will inherit all the settings of the table{}-selector… so if you want other value's you should add them to your datatable{}-selector to overwrite the general value's of the table{}-selector. For an example have a look @ CSS test on table
#selector is called an ID selector. These are used to apply styles and are commonly used with javascript behaviors on containers that are given an id attribute like <input id="name"> and on <div id="name"> containers. In terms of editing these selectors for use with Wikidot's CSS, you will primarily be editing IDs related to the HTML <div>…</div> blocks that make up Wikidot pages.
Here's some specific examples from some Wikidot HTML sources and corresponding CSS:
HTML Source | Selectors | Related CSS |
<blockquote> <p>Could you take a second to review <a href="http://blog.wikidot.com/design:2">http://blog.wikidot.com/design:2</a> and make sure it gives you what you need? Thanks.</p> </blockquote> |
blockquote, p, a |
blockquote{ border: 1px dashed #999; padding: 0 1em; background-color: #f4f4f4; } a{ color: #00A; } p{ font-family: verdana,arial,helvetica,sans-serif; } |
<div class="gallery-box"> | .gallery-box |
.gallery-box{ overflow: hidden; width: 98%; } |
<div id="side-bar"> | #side-bar |
#side-bar{ float: left; width: 14em; padding: 1em; margin: 0 0 1em 0; clear: left; } |
If you found this info useful rate it up and hit "+"
This is not a <HTML>-CSS reference base. For that we direct you to other excellent places on the web: CSS-tutorials via Google
Thanks for the input to
- Asked by leiger
- Lasted Edited by cloraja
- Ed Johnson
- Steven Heynderickx
selector is called a Type selector. These generally refer to site-wide HTML elements like <a …>…</a>, <body>…</body>, <h1>…</h1>, <h2>…</h2>, <table>…</table>, etc.
.selector is called a Class selector. These are used to apply the class to an element like <table class="mytablestyle">…</table>.
#selector is called an ID selector. These are used to apply styles to DIVs that are given an id attribute like <div id="mydiv">…</div>.
Here's some specific examples from some Wikidot HTML sources and corresponding CSS:
<p>Could you take a second to review <a href="http://blog.wikidot.com/design:2">http://blog.wikidot.com/design:2</a> and make sure it gives you what you need? Thanks.</p>
</blockquote>
Community Admin
That makes perfect sense :)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
@Steven,
Why are you going off on javascript and programming in this section? Wikidot CSS is full of ID selectors that we all edit regularly. If I need to change the placement of the #side-bar, I can't do it by creating a .side-bar class. Wikidot developers (well, developer - Michal) had the foresight to apply IDs to virtually every DIV block that makes up a page. I was going to hack away at the answer, but before I do I was wondering where this line of thinking is coming from.
I think these answers need to be centered around what we can do in terms of custom themes and Wikidot's pre-defined layout and not try to be all inclusive and give advice that someone can only apply to a web site they're building from scratch.
-Ed
Community Admin
I would say that your post Ed, is enough. The part that was added to the beginning by Heynderickx just confuses me even more :S
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
I take this a bit personal… I put effort in the page and I get remarks like "confusing". Why don't you say what you think is confusing than I can alter the text. Or you can suggest what should be altered an we can discuss it here. Or even better start making pages with content.
keep in mind, not everybody who will read this is a pro or guru… And Ed's explination was not saying why one should choose for one selector or the other. But he made a very good start… and also… Why the HTML? We use wiki-syntax here.
I read further down in this thread the story about the musicians… (good story BTW)
What if I made a page where Ringo Start had a chat with John Lennon and ALL the things Lennon said needed to have no clothes?
Where would you be then with your ID#selector?
People should not choose between #header or .header …. It is already in the page and they should use the page selectors if they want to change things… And why is it #header you think? because there is only one and people should be advised not to make another one.
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
Sorry, I didn't mean to cause offence. Basically, I think that the simpler an explanation is, the better.
I may be a "Guru", but CSS is one of those things that - without a tool like Firebug to help me a little bit - I'd be completely stuck on. So this was a genuine question that I was hoping for an answer for. So when you suggested "Or even better start making pages with content", that's a problem. I contribute where I can, but on this site I'm the beginner and have to leave it to others to contribute despite itching to get involved somehow ;-)
Getting back to the answer… I believe that the simpler an explanation is, the better it is. You are attempting to go into a lot of depth and to answer the problem properly, to make sure that there is no misunderstanding… except, that wasn't needed because as a result of Ed's post I believe I understand perfectly now :)
The KISS principle = "Keep It Simple Stupid" (i.e. try to answer the question with as few sentences as possible)
Hope that explains why I said that it confused me.
For a step-by-step guide or tutorial - what you wrote is probably exactly what is needed… but when trying to answer a question, the simpler it is the better (at least, that's how I prefer it to be, anyway).
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
Okay thanks for your explination… Mostly after a short explination, new questions come… just like yours
I would like to read this on this page if I was looking for info.
But I'll keep your remark in my head and try to be more brief…
A - S I M P L E - P L A N by ARTiZEN a startingpoint for simple wikidot solutions.
Well, in my opinion (which may not be shared by everyone here), what you're wanting to do is the type of thing you would add to a comprehensive tutorial or guide on the subject, similar to what can be found on the CSS Primer pages.
A short answer will do exactly that, answer the question and nothing more, which will inevitably lead to more questions in most cases. You're right there. But for the sake of understanding and not overwhelming people like myself1 with too much information, I think that simpler is better :)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
@Steven, I hope you don't think I was making a personal attack. My main point is that I think our answers need to focus on Wikidot custom CSS and not get too deep into general CSS tutorials. There are hundreds of other sites that do a great job explaining the nuts and bolts of CSS and I don't want this site to turn into another "me too" CSS site. The main focus of this site, in my opinion, needs to stick with what specifically applies to Wikidot and how we can make our sites sing and dance with custom CSS.
That said, I think the CSS Primer section is a great place to cover some general CSS knowledge (with references to other sites for more detail), but we should keep as much of that out of our FAQ/Q&A section as possible.
That is all I was trying to say.
Thanks for the table example - I learned something new!
-Ed
Community Admin
CSS stands for Cascading Style Sheets. Forget that for now. Really, put that term out of your mind and think about musicians, as they contain the secret to CSS, or rather, allow me to explain 90% of everything you ever need to know about CSS very quickly.
Musicians, as a rule, wear clothes. Sadly, it's true. Musicians don't walk around naked like they used to. As they have clothes (as a rule) we can also assume that they own their clothes. We can say the clothes are the musician's property. (Musicians don't uh.. steal their clothes like they used to.)
In CSS, the rule would look like this :
Yup. That's a CSS rule and looks exactly like what you will be using to make themes with. Remember, as a rule, musicians wear clothes, which is their property. Moving on…
Not all musicians are the same. They fall in several interesting (or not) classes of musicians. By defining a class of musician, we can describe the look of several musicians at once. Again, in CSS (vaguely) :
Note the dot in front of the class name. This shows that it is a class of musician, not a specific rock-star. In CSS, there is even a way to describe a specific musician by name. (or by id). In CSS :
Doh! Well, there you have it, musicians just don't run around naked like they used to. As you go through this CSS guide, I want you to keep that image in your mind (no, not naked John Lennon and Yoko Ono, the code format!). It may seem like you have learned little (and imagined much), but I guarentee you are already halfway to a CSS expert.
—— from : wikidotthemes.wikicomplete.info
you have my full permission to make it your bitch, i mean use it any way you want, i mean…. heh. :)
— hartnell
That made me laugh — a good guide :)
By the way hartnell… you've suddenly started posting all over the place. Are you making a return to Wikidot as an active contributor again? :) I see your name all over the community site, yet it seems that most of that is from a couple of years ago.
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
Hmm… what would happen if both an ID and Class are defined in a div block? Am I right in suspecting that the one defined last in the CSS file is the one that is applied?
e.g.
CSS:
So, he'd be wearing nothing? ;-)
And in this case:
CSS:
He'd be wearing black leather, because he's a rock star as well?
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
Happy to know you like. It's been gathering dust for awhile. It's less dusty now. :)
About me coming back… here's my blog : http://shawn-hartnell.wikidot.com I make no promises, but time will tell. :)1.
— hartnell
Part of that would have to do with where #john-lennon and .rock-star are defined.
If .rock-star is defined in an external stylesheet, and #john-lennon is defined in the html page itself, he'd be naked (and probably wrapped around yoko.)
Cascading Style Sheets override each other :
So if #john-lennon is a P then
<p style="clothes:nude"> nakie!! </p>
then he's always be naked. Nothing (i know of) trumps inline styles. (unless you flag it as !important)
I'm not sure what would happen if they are defined in the same scope. I suspect the id would win , but I'm going to write a test just to confirm.
— hartnell
Quick - edit your post before pieter sees it! :)
~ Leiger - Wikidot Community Admin - Volunteer
Wikidot: Official Documentation | Wikidot Discord server
The Test of Which That I Spoke of Doing and Did Do.