2013-08-29 29 views
0

我想让图像在悬停时略微增长。我知道这很简单,但我已经寻找了一个比其他例子好一个小时,似乎无法弄清楚我缺少的东西。我很感激帮助。这些图像保存到我的电脑。css悬停未执行

范围

<link type="text/css" rel="stylesheet" href="stylesheet.css"/> 
<embed src="73797^alarmclock.mp3"; autostart="true"; loop="true"; hidden="true";/> 

<body> 

    <img src ="alarm clock2.jpg"/> 

    <p> Pulling the sheets into my body, I begin to sink back into the bed... 
      uggh... my alarm clock... time to get up.. 

     <img style = "position:absolute; top:300px; right: 0px; z-index:1" 
      src="computer.jpg"/> 

     <IMG ID="grow" STYLE= "position:absolute; TOP:1157px; LEFT:599px; 
      WIDTH:47px; z-index:2; HEIGHT:47px" SRC="icon2.gif"/> 

</body> 

</html> 

这里是stylesheet.css中

#grow:hover { 
width: 100px; 
height: 150px; 
} 
+0

不要使用内联样式。你的问题是内联样式比CSS更优先。把它们放在'stylesheet.css'中,它就可以工作。 – Itay

+0

为什么你使用内联样式和混乱的CSS。 – Sir

+0

和不在引号中的所有内容都应该是小写。你用微软的话创造了这个吗? – PlantTheIdea

回答

2

内联样式这在HTML元素声明具有比其它CSS规则更高的优先级。因此,考虑制定规则!important或将内联样式移出。

无论如何,!important规则不建议定期使用。所以,你有更好去除您的内嵌样式,并把它们放在.css文件(或内<head>至少<style>元素)

+1

定期使用!非常不宜使用!尤其是当他可以通过停止使用内联样式来修复它时。 – Itay

+0

我同意你的意见,我只是给他所有可用的选项。我想我应该把它包括在我的回答:) –

+0

谢谢你们。我得到了它的工作。这个东西很新。没有更多的内联样式。 – user2719596

1

尝试这种风格

#grow:hover { 
width: 100px !important; 
height: 150px !important; 
} 

因为你已经写了内嵌样式。为了覆盖它,您需要将!important添加到样式中。也尝试以小写字母写入html,并避免不必要的空格。

你能做的最好的事情是避免内联样式和风格写如下:

#grow 
{ 
    position:absolute; 
    top:1157px; 
    left:599px; 
    width:47px; 
    z-index:2; 
    height:47px 
} 

#grow:hover 
{ 
    width: 100px; 
    height: 150px; 
} 
+2

这会起作用,但经常使用'!important'是非常不明智的,尤其是当他可以通过停止使用内联样式来修复它时。 – Itay

2

内联样式在CSS我相信有优先权。

更改您的CSS和HTML如下:

#grow { 
    position:absolute; 
    top:1157px; 
    left:599px; 
    width:47px; 
    z-index:2; 
    height:47px 
} 
#grow:hover { 
    width: 100px; 
    height: 150px; 
} 

HTML:

<IMG ID="grow" SRC="icon2.gif"/>