Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

Kenny Parewijck
Kenny Parewijck
4,602 Points

Why can't I add css code like html here in the post forms?

Hello

Look at this:

I paste a piece of html code in here:

<ul>
  <li>
    <p>a piece of code</p>
  </li>
</ul>

As you can see it comes in a nice black background and is proper indented. But if I paste a piece of css in here like this:

ul {
  margin:0;
  padding:0;
}

Then you can see it is shown as pure text and not in a proper view like my html code.

i saw a lot of other questions on this community and with these other post i can see that their css code is also shown in a good way, backgrounded, indented, ..

Do I have to do something or set a preference for my posts in order to be able to post css code in a good view?

thanks!

3 Answers

I just amended your post to show the css code block. Edit your post to see the changes I made.

You'll note that your html did not show up in total - only a small part shows - you need to use the backticks to segment the block properly. Again, you can see what I amended in your post if you edit it. Try it - remove my edits and see the difference with your html.

Steve.

Hey Kenny,

If you want the syntax highlighting to activate for some code you're posting, you have to wrap the code with 3 backticks (```). Sometimes, the syntax highlighting correctly guesses what programming language you're using but most of the time, you also want to declare the name of the programming language after the first group of backticks. Also, you need to have a new line before and after your code — it looks like this:

```css

.a-css-declaration {

}

```

Kenny Parewijck
Kenny Parewijck
4,602 Points

Allright! Helpfully.

Thanks!