【发布时间】:2018-05-26 17:43:31
【问题描述】:
我真的不知道这有什么问题......哈哈
我正在尝试这样做,它非常重要...你能帮帮我吗?
会很好:D
谢谢
<script>
var img = document.getElementById("img");
var height = img.height;
var width = img.width;
alert(height);
</script>
<div>
<img id="img" src="https://www.w3schools.com/css/trolltunga.jpg">
</div>
<style>
#img {
position: absolute;
top: 50%;
left: 50%;
width: 400px;
height: auto;
margin-left: -200px;
}
</style>
【问题讨论】:
-
有更简单的方法使用 css flex 使图像居中
-
你想做什么,你想把它放在哪里?你不需要 js 来做这个
标签: javascript html css image