0

I'm a newbie to html and CSS, and I've been trying to style my paragraph to have 5px of padding on each side of the text, but whenever I add "padding: 5px;" it gets rid of the background colour (of the paragraph), and the padding makes no effect. I've tried with just the padding and that doesn't work either. Thank you in advance!

HTML and CSS for reference:

body {
    background-color: #000000;
    font-family: arial;
    color: white;
}
a {
    color: orange;
}
p {
    background-color: #393939
    padding: 5px;
}
<!doctype html>
<html>
    <head>
         <title>spam</title> 
    </head>
    <body>
        <link rel = "stylesheet" href="main.css">
        <a href = ""><img src = ""></a>
        <h1><strong>Website name</strong></h1>
        
        <ul>
            <a href = "index.html">Home</a>
            <a href = "news.html">News</a>
        </ul>
        
        <p>
            Man stabbed in ...
        </p>
        
    </body>
</html>
  • Might not be enough padding, as paragraph tags come with their own built-in padding. You may just be matching the padding it already has. https://stackoverflow.com/questions/819161/what-is-the-default-padding-and-or-margin-for-a-p-element-reset-css – Andrew Ice Jan 20 '17 at 17:28
  • @AndrewIce It's just a missing semicolon. CSS doesn't assume that a line break ends a property's value. – Chris Forrence Jan 20 '17 at 17:29
  • That's an obvious problem that other people have already answered. I'm simply providing more information as to what another issue could be with styling a specific element. – Andrew Ice Jan 20 '17 at 18:02

2 Answers2

1

In CSS you need to end each property you add with a ; so simply change the code to:

p {
    background-color: #393939;
    padding: 5px;
}

Not having the ; to show that a property ended meant the browser read the CSS as one big property that doesn't exist, which is why it seemed like your CSS did nothing.

Callum
  • 845
  • 11
  • 22
0

You are missing the ; after background-color: #393939

shipshape
  • 1,682
  • 2
  • 17
  • 33