Could one tag have more than one class?

And what if someone decides to use <p class="ul_nobullet">?

And what if someone decides to use <p class=“ul_nobullet”>?

Why would they? The fact it’s called ul_nobullet is presentational enough (though handy admittedly). I can read it and know that it removes the bullets on unordered lists… until someone edits the style, then it’s screwed :slight_smile:

first, the class say nobullet, not highlight, not empahsize, not font, etc…

second, wouldn’t any one look at the code of the class before they assign it to a tag ?

Stephen
Actually, that’s a pretty good estimate. Since the formula for the total number of combinations of n number of classes, where the number of classes used can vary from 1 to n and where the order of the classes does not matter, is n^2 - (n - 2), you have (theoretically) reduced the potential number of classes to 9,8 percent (11 / (11^2 - (11 - 2))) by using multiple classes in each tag.

Beats me, but I’ve seen people do far stranger things. The point was that including the element type within the class name gives no advantage over using an element type selector in the style sheet if you want to restrict the effects to certain element types. In fact, it’s a bad idea, since you never know if you’ll want to reuse that class for something else in the future. (Although it’s unlikely with such a presentational and specific name.)

Yes, but it will also removed the numbers from an ordered list if applied as <ol class="ul_nobullet">, although the name is then less intuitive.

Er. For the CSS don’t you mean “ul.section”? Because <ul class=“section” wouldn’t be correct for what you had (or maybe I’m just tired).

No. :slight_smile:

Let’s say you have these CSS rules,

.section ul {list-style-type:square}
.nobullet {list-style-type:none}

Then you have this markup,

<div class="section">
  <ul class="nobullet">
    <li>First</li>
    <li>Second</li>
    <li>Third</li>
  </ul>
</div>

Your list items will have square markers, even though the list has class="nobullet". The reason is that the first rule has higher specificity (0,0,1,1) than the second (0,0,1,0).

In this case you could change the selector in the second rule to ul.nobullet to increase its specificity to 0,0,1,1. Since the second rule comes after the first rule, it will be applied.

My point was that one reason for including an explicit type selector in this type of rules is to increase the selector’s specificity.

If they were bad enough to put .ul_nobullet, they’d probably have .ol_numbers :slight_smile:

I include the element type if I’m using it on a particular tag… much easier when scanning the stylesheet quickly. I also have everything upfront, so I know whether I need to re-use that class or not however, which is a different scenario to not knowing what’ll be on other pages.

Sleep deprovation. I thought that the HTML was set up like <ul class=“section”>.

Just on another note, I often use more than one class on the body tag when I am styling menu lists. The list can be the same html on each page but styled differently on each page by using those classes. Very handy.

Hello A(a)rem, nice to see you came over here. Love my post count?

Anyway shouldn’t just one class on <body> be sufficient? Why would you need 2 or more classes for a page?

They can be used independently for different things. For instance, one class can be used to describe the subsection of the site where the page is (for highlighting the current nav menu item) while another can indicate whether the page has a column of related information.

<body class="news related">
.home #home,
.news #news,
.about #about
{
  /* style for current nav menu item */
}

#wrapper {margin:0 0 0 12em}
.related #wrapper {margin-right:14em}

Doing this with a single class will require several different classes (six for the simple three-section site in my contrived example) and will lead to severely and unnecessarily bloated CSS.

Yes, that’s what I use it for. Nicely put. It’s so beautifully efficient, I love this method.

Yes, yours is much bigger than mine. :lol: Happy?
I’m figuring to spend more time here, where there are more experts, thus more to learn. And besides, I live round the corner from SP and know some of its people, so it makes sense to use it.

In all the coding sites I’ve done I have never done classes on body tag. I used to find it redundant…

It just allows for come very efficient coding. Look at the Happy Cog site, for example. Click on News, for example, and on the news page the News tab is white. Yet the menu code remains the same. Doing this means you can use php includes on menus, yet have a menu styled differently on each page.

Yes lol. I love this more because I can act myself, not a 60 year old man. Hell there are like 4 Kravvitz’s here.

I use simple PHP to add a class to the current page item.

Yes, that’s another option. How do you set it up? I haven’t done it before.

Two options.

Function

<?php
	function currentPage($page) {
		$file = basename($_SERVER['SCRIPT_NAME']);
		$file = substr($file, 0, -4);
		if($file==$page) echo ' class="current"';
	}
?>

Basically, gets the page name, strips the .php, then if the page called is the current page it echos class=“current”.

<li<?php currentpage(‘index’); ?>><a href=“index.php”>home</a></li>

Name

At the top of every page give it a name. Such as $page=“about”. Then call it in the menu:

<li<?php if($page==“about”) echo ’ class=“current”'; ?><a href=“#”>About</a></li>

Works nice for simple sites. I always use PHP includes for easy maintainability. Not the best solution for anything that’s big as it’s all done manually, in that case a CMS is better.