5

So my code looks like this:

<div id="blackbox">style="background: black; 
width: 90px; 
height: 80px; 
color: white; 
text-align: center; 
font-family: Times; 
font-size: 20px;
position: fixed;
left: 0px;
bottom: 150px   

Now it somehow doesn't work at the inline CSS, this is the only thing I can get it done. If you got a solution for that, I'd be greatful. But so, I want to make the :hover property but how because this won't work:

<div style="background: black; 
width: 90px; 
height: 80px; 
color: white; 
text-align: center; 
font-family: Times; 
font-size: 20px;
position: fixed;
left: 0px;
bottom: 150px}

blackbox:hover {background: white;}

or

:hover {background: white;}

or

hover {background: white;}
mavili
  • 3,385
  • 4
  • 30
  • 46
Yesse Engold
  • 61
  • 1
  • 2
  • 8

4 Answers4

10

You can't have pseudo selectors within inline styles.

You'll need to use CSS in an external stylesheet (<link rel="stylesheet" href="style.css" />) or use a <style> element.

zzzzBov
  • 174,988
  • 54
  • 320
  • 367
  • Well now here's the problem, my blackbox div won't read the CSS from elsewhere than inline. Not between – Yesse Engold Aug 27 '13 at 15:44
  • @CladeeLintunen, if you're setting a style inline, it will have a higher specificity than the styles set from CSS, and will therefore ignore the CSS rules. – zzzzBov Aug 27 '13 at 15:46
  • How can I fix it? I can't have pseudo code if I can't get it read from seperate file or style element. – Yesse Engold Aug 27 '13 at 15:47
  • @CladeeLintunen, keep your CSS in `.css` files. – zzzzBov Aug 27 '13 at 15:47
  • Not helping. Here's my code: SuomiWiki
    – Yesse Engold Aug 27 '13 at 15:51
  • CSS: blackbox { background: black; width: 90px; height: 80px; color: white; text-align: center; font-family: Times; font-size: 20px; position: fixed; left: 0px; bottom: 150px; opacity: 0.5 transition: opacity 5s, background 5s; } blackbox:hover { opacity: 1; background: darkgray; } – Yesse Engold Aug 27 '13 at 15:52
  • @CladeeLintunen, comments are not the place for code examples. If you need to write up code examples, create a reduced test case in a service such as [jsfiddle](http://jsfiddle.net) – zzzzBov Aug 27 '13 at 16:00
  • @CladeeLintunen, also, you forgot to prefix your classes with `.`. – zzzzBov Aug 27 '13 at 16:00
  • Yeah, sorry. Well I got it fixed with # prefix. Is there a difference? – Yesse Engold Aug 27 '13 at 17:46
  • @CladeeLintunen, the code you posted in this comment thread uses `
    `, while the code in your question shows `
    `. [there is a significant difference between classes and IDs](http://css-tricks.com/the-difference-between-id-and-class/).
    – zzzzBov Aug 27 '13 at 17:48
0

Inline pseudo code! Not possible. Try it in embedded or external stylesheet.

Praveen
  • 55,303
  • 33
  • 133
  • 164
0

in the css write

#blackbox:hover {
    //write something
}
Tomzan
  • 2,808
  • 14
  • 25
0

Pseudo selectors cannot be used inline. :) You have to specify it separately it in css.

majorhavoc
  • 2,385
  • 1
  • 24
  • 26