4

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,265
  • 4
  • 29
  • 45
Yesse Engold
  • 51
  • 1
  • 2
  • 8
  • `.blackbox:hover {...}` in a external style sheet – ninty9notout Aug 27 '13 at 14:04
  • 1
    Use external style sheets. You cannot place pseudo-classes inline. – BenM Aug 27 '13 at 14:04
  • You cannot use hover in an inline style, you need to use it in a stylesheet. Further, if you've got inline styles in your document, if you want to "override" them with css in an external file, you'll have to use the !important declaration. – random_user_name Aug 27 '13 at 14:04

4 Answers4

9

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
  • 167,057
  • 51
  • 314
  • 358
  • 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
  • 53,079
  • 32
  • 129
  • 156
0

in the css write

#blackbox:hover {
    //write something
}
Tomzan
  • 2,738
  • 13
  • 24
0

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

majorhavoc
  • 2,265
  • 1
  • 23
  • 25