Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 490071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:52:18+00:00 2026-05-13T01:52:18+00:00

I’m hoping this is simple. I’m not a CSS guy. I’m trying to make

  • 0

I’m hoping this is simple. I’m not a CSS guy.

I’m trying to make some code look a little better on a blog and I have the following <code> CSS style.

code {
        display: block;
        white-space:normal;
        background-color: #eeeeee;
        font: 1em, 'Courier New', Courier, Fixed;
        padding: 7px;
        margin: 7px 7px 7px 7px;
    }

This is working fine for me, except where there are line breaks in the code contained in my <code> tag, the background color is white not light gray.

Is there a CSS tweak I can make to force my entire <code> block have a background color of gray?

Thanks.

Comment: If I put a space on the empty line, I get what I want – a gray background on that line.

Comment2: I have only plain text inside of my <code> </code> tags. Ideally I don’t want to mark up my code w/ tags. Just cut and paste inside of the <code> tags and have it look decent.

Final Comment: After reading this as suggested by mercator below, I finally went with this. I subclassed the <pre> tag and got want I needed. A nicely shaded boxes to offset my example code blocks.

 pre.code {
    color: black;
    border: solid 1px #eeeeee;
font-size: 1.1 em; 
margin: 7px; 
padding: 7px; 
background: #eeeeee
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:52:19+00:00Added an answer on May 13, 2026 at 1:52 am

    It appears to work fine for me, but then I don’t know what the contents of your <code> tags are.

    There’s a few oddities in your CSS in any case:

    • I probably wouldn’t use display: block, but wrap the tags in a <p> or <pre> instead. Changing it to a block like that still won’t allow you to nest block-level tags inside it, and it would still need to be inside a block-level tag itself. CSS doesn’t change the HTML syntax and semantics. Do you have any block-level tags within your code tags?
    • Why did you set white-space: normal? That’s a little unusual for a code block. How exactly are you formatting your code? Are you adding <p> or <br> tags in there? Why don’t you use white-space: pre, or perhaps white-space: pre-wrap?
    • Your font declaration is broken. There shouldn’t be a comma between the 1em and the font names. Browsers would now simply parse that as if 1em is the name of a font family, I think, and then fall back on Courier New, since 1em doesn’t exist.
    • I think you meant to say monospace instead of Fixed. Or is Fixed the actual name of a font face? You’d better add the generic monospace anyway.
    • More of a nitpick: you can collapse those 4 margins down to one value too.

    I’m not sure if any of these are really the cause of your problems. The first two are the most likely candidates. Nothing strange happened on the quick tests I did, but some of your other CSS might be creating the problems in combination with some of these points.

    Ah, wait a minute… I see now that you’re talking about making “some code look a little better on a blog”. The blog software is automatically adding paragraph tags around blocks of text separated by blank lines. Those are responsible for the white.

    I suppose that’s also why you added white-space: normal. The blog software is already adding line breaks and everything automatically (with <p> and <br> tags), so using pre added a whole bunch of extra space.

    Try using the <pre><code> tags combination like StackOverflow does. Using the <pre> tag will probably (hopefully) prevent the blog software from messing with your code.

    For WordPress, have a look at their article “Writing Code in Your Posts.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.