作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在制作主页的页脚,其中将包含我的三个个人资料的图标,并且我正在使用 javascript 代码段在光标放在图像上时增加图像的大小,并在光标放在图像上时减小图像的大小出去。图像将水平显示,并排显示(内联 block )。
虽然脚本工作正常,但我在 HTML 方面遇到问题:当我将鼠标悬停在行中的第一张图片上时,它的大小会增加,但其他图片会从它们的位置移位,即整行会被打乱.
我希望图像在发生鼠标事件时独立地改变它们的大小。
这是页脚代码:
<center><footer>
<div style="display:inline-block; height:40px; width:40px;">
<img style="vertical-align:center;" src="https://i.imgur.com/e9l6jhU.png"
id="0" height="30" width="30" onmouseover="footerimg2(0)"
onmouseout="footerimg1(0)" ></img>
</div>
<div style="display:inline-block; height:40px; width:40px;">
<img style="vertical-align:center;" src="https://i.imgur.com/RvAl3ob.png"
id="1" height="30" width="30" onmouseover="footerimg2(1)"
onmouseout="footerimg1(1)" ></img>
</div>
<div style="display:inline-block; height:40px; width:40px;">
<img style="vertical-align:center;" src="https://i.imgur.com/vYUYQw9.png"
id="2" height="30" width="30" onmouseover="footerimg2(2)"
onmouseout="footerimg1(2)" ></img>
</div>
</footer></center>
JavaScript,如果它是相关的:
<script>
function footerimg2(id){
var x = document.getElementById(id);
x.width = 40;
x.height = 40;
}
function footerimg1(id){
var x = document.getElementById(id);
x.width = 30;
x.height = 30;
}
</script>
如何在不移动其他图像的情况下独立调整图像大小?
最佳答案
尝试添加position:absolute;
img {
position: absolute;
}
<div style="display:inline-block; height:40px; width:40px;">
<img style="vertical-align:middle;" src="https://i.imgur.com/e9l6jhU.png" id="0" height="30" width="30" onmouseover="footerimg2(0)" onmouseout="footerimg1(0)" />
</div>
<div style="display:inline-block; height:40px; width:40px;">
<img style="vertical-align:middle;" src="https://i.imgur.com/RvAl3ob.png" id="1" height="30" width="30" onmouseover="footerimg2(1)" onmouseout="footerimg1(1)" />
</div>
<div style="display:inline-block; height:40px; width:40px;">
<img style="vertical-align:middle;" src="https://i.imgur.com/vYUYQw9.png" id="2" height="30" width="30" onmouseover="footerimg2(2)" onmouseout="footerimg1(2)" />
</div>
<script>
function footerimg2(id) {
var x = document.getElementById(id);
x.width = 40;
x.height = 40;
}
function footerimg1(id) {
var x = document.getElementById(id);
x.width = 30;
x.height = 30;
}
</script>
这是 Updated Fiddle .
关于javascript - 更改页脚图像大小会取代相邻图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46520682/
我是一名优秀的程序员,十分优秀!