如何在网页中调整图片大小?

时间:2018-04-01 20:38:42

标签: html css firebase

我从firebase数据库检索了图片网址但是当我试图显示在网页上检索到的图片时,图片的大小没有根据我在标签中提供的规格进行调整。获得的图像覆盖整个网页背景。

JS

var myParam=location.search.split('itemKey=')[1];
alert(myParam);
firebase.database().ref('/Sell_Products/'+myParam).once('value').then(function(snapshot)
{var name=snapshot.child('name').val();
alert(name);
var image=snapshot.child('image').val();
var category=snapshot.child('category').val();
var description=snapshot.child('description').val();
var price=snapshot.child('price').val();
document.querySelector('img').src = image;
});

HTML

<img height="125" width="125"/>

2 个答案:

答案 0 :(得分:0)

让我们试一试:<img style="height: 125px; width: 125px;"/>

答案 1 :(得分:0)

您可以在javascript中修改高度和宽度。

  1. 在您的html文件中,将id添加到您的图片代码中,例如<img id="my_image"/>
  2. 在您的javascript文件中,添加
    var image = document.getElementById('my_image');
    image.height = '125';
    image.width = '125';