【问题标题】:How to resize an image in web page?如何调整网页中的图像大小?
【发布时间】:2018-04-01 20:38:41
【问题描述】:

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

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"/>

【问题讨论】:

  • 图片的 html 是什么?
  • html for image is 我已经在stackoverflow上检查了其他答案并尝试了相同的方法,但对我来说没有成功。

标签: html css firebase


【解决方案1】:

让我们试试这个:&lt;img style="height: 125px; width: 125px;"/&gt;

【讨论】:

  • 感谢您的快速回复。但没有成功
【解决方案2】:

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

  1. 在您的 html 文件中,将 id 添加到您的图像标签中,如下所示 &lt;img id="my_image"/&gt;
  2. 在您的 javascript 文件中,添加
    var image = document.getElementById('my_image');
    image.height = '125';
    image.width = '125';

【讨论】:

    猜你喜欢
    • 2019-06-13
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多