【发布时间】:2014-06-19 04:47:37
【问题描述】:
这是我的代码。我正在尝试在用户单击链接时在 div 标签中显示背景图像。但是我的背景图像不适合屏幕(如下所示在 css 中放置高度和宽度至少可以让我显示整个图像,但它会超出屏幕)。如果我从 css 中删除 height 和 width 属性,则根本不会显示图像。
html->
<body>
<div>
<ul>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2012'">IT Spend</a></li>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2012'">Assessments</a></li>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2012'">Information</a></li>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2012'">2012</a></li>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2013'">2013</a></li>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2014'">2014</a></li>
<li><a href="#none" onclick="document.getElementById('wrapper').className ='IT_Spend_2015'">2015</a></li>
</div>
<div id="wrapper" class="IT_Spend_2012"'></div>
</body>
css->
#wrapper { background-repeat: no-repeat; width:1500px; height:1100px;}
.IT_Spend_2012 { background-image: url('./img/IT_Spend2012.jpg'); }
.IT_Spend_2013 { background-image: url('./img/IT_Spend2013.jpg'); }
.IT_Spend_2014 { background-image: url('./img/IT_Spend2014.jpg'); }
.IT_Spend_2015 { background-image: url('./img/IT_Spend2015.jpg'); }
【问题讨论】:
-
背景位置:左上角;背景重复:不重复;背景尺寸:自动;或者你可以手动给它一个大小。 (我愿意)
标签: javascript html css image background