Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

edit css style of an element with a space in its class name

I'm creating a tumblr them and I have to write an external CSS file but I am having trouble editing the css style of the post elements.

This its structure:

<li class="post quote">
    {other code}
</li>


The problem is that the class name has a space in it.

How would I create a CSS class to access this? And yes, I know I can just put a style attribute in the element tag but I was kind of hoping for another option.

like image 647
nkcmr Avatar asked Jan 14 '11 20:01

nkcmr


People also ask

Can you have a space in a CSS class name?

The class name can't contain a space, but it can contain hyphens or underscores. Any tag can have multiple space-separated class names.

How do you select a class with space in CSS?

You basically just need to make sure all the class names are connected (no spaces between them) and separated with a dot. Save this answer. Show activity on this post. Classes will never actually have spaces in their name.

Can CSS selector have space?

A space in a CSS selector has very special meaning. It means that the part of the selector that occurs right of the space is within (a child of) the part of the selector to the left.

How do you change the class style of an element?

The class name is used as a selector in HTML which helps to give some value to the element attributes. The document. getElementById() method is used to return the element in the document with the “id” attribute and the “className” attribute can be used to change/append the class of the element.


2 Answers

The problem is that the class name has a space in it.

This is not possible in CSS. What you are doing is giving the element two classes.

You can address them such:

.post.quote { .... }

but in your case, it's probably better to use a valid separator like

post_quote
like image 116
Pekka Avatar answered Nov 15 '22 06:11

Pekka


This element actually has two classes - it is marked with both the post class and the quote class. So, you can use the following selectors to access it:

// css
.post { ... }   // elements with the post class
.quote { ... }  // elements with the quote class

// jQuery
var postLis = $('.post');
var quoteLis = $('.quote');

You can also stack selectors to return all elements which meet all conditions in the selector, by including the different selectors together:

// css
.post.quote { ... }  // elements with both the post and quote classes

// jQuery
var postAndQuoteLis = $('.post.quote');
like image 35
Dexter Avatar answered Nov 15 '22 05:11

Dexter