0

Can someone please tell me what i'm doing wrong here, the css works when i replace the .1{} with img{}. Shouldn't I also be able to use img.1{} or .1 img{}

Here's the UPDATED HTML

<!DOCTYPE html>
<html>
<head>
<title>Test Webpage</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="clouds">
<img id="cheese" src="cloud.png">
</div>
</body>
</html>  

And the UPDATED CSS

  body{
    margin:0;
    padding:0;
    background:#0088ff;
    font-family:helvetica;
}
#clouds{
    overflow:hidden;
    width:100vw;
    height:100vh;
}
#cheese img{
    display:none;
}
Matt Komarnicki
  • 4,370
  • 4
  • 31
  • 67
user2072017
  • 81
  • 1
  • 4
  • 12

3 Answers3

6

Change the class name from 1 to something that starts with a letter and try again.

After all read this.

EDIT:

I see you have some problems with basic things.

If your image has an ID like <img id="foo" src="" /> then you reference in CSS using img#foo { } (tag + hash + identifier) or just using id without providing type of the tag: #foo { }.

Community
  • 1
  • 1
Matt Komarnicki
  • 4,370
  • 4
  • 31
  • 67
  • Classes have to start with letters. It's a thing. If you rename .1 to .class-1, it'll work. – Tejas Jul 30 '15 at 06:41
1

Numbers at the beginning of a class name are not illegal in the CSS grammar.

"The name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, Unicode characters 161-255, as well as any Unicode character as a numeric code, however, they cannot start with a dash or a digit."

You are just specifying the name the wrong way.

See http://www.w3.org/TR/CSS21/grammar.html

Try to this way according to updated your question

img#cheese {
    display:none;
}

or

#clouds>img{
    display:none;
}
Rohit Azad Malik
  • 29,262
  • 15
  • 57
  • 87
0

if you have multiple images then you can use like this:you can use like this:

<style>
#clouds{
overflow:hidden;
width:100vw;
height:100vh;
}
.1{
display:none;
}
.2{
display:block;
}
</style>

<div id="clouds">
<img class="1" src="cloud.png">
<img class="2" src="cloud.png">
</div>
Manindra Singh
  • 759
  • 3
  • 10
  • 35
  • It will but with that solution he won't know what was the issue (class naming). – Matt Komarnicki Jul 30 '15 at 06:43
  • yeah but i want multiple images with individual parameters, without making a div for each one. Shouldn't i be able to give and id to an image though? – user2072017 Jul 30 '15 at 06:44
  • Give it an id or a class or refer using data attributes - what suits your needs. It doesn't matter. What matters is using a valid name for classes and ids. :) – Matt Komarnicki Jul 30 '15 at 06:45