Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我通过JS上传了图片。如何在css中进行更改?_Javascript_Jquery_Css - Fatal编程技术网

Javascript 我通过JS上传了图片。如何在css中进行更改?

Javascript 我通过JS上传了图片。如何在css中进行更改?,javascript,jquery,css,Javascript,Jquery,Css,编辑:我意识到,因为我没有给出完整的代码(我写了很多,因为它是为一个最终的项目,但我只是有一个小问题),我的问题有点困惑。下面的答案非常好,但我意识到,当我从查询中编译图像数据时,我给它分配了一个类,所以我只是用它来编辑,从下面的答案中绘图来调整图像的大小。谢谢大家! 我正在做这个项目,我们正在解析来自查询的数据。我目前正在使用SoundCloud Stratus API创建一个非常基本的SoundCloud网页 $.each(data.slice(0,10), function(index,

编辑:我意识到,因为我没有给出完整的代码(我写了很多,因为它是为一个最终的项目,但我只是有一个小问题),我的问题有点困惑。下面的答案非常好,但我意识到,当我从查询中编译图像数据时,我给它分配了一个类,所以我只是用它来编辑,从下面的答案中绘图来调整图像的大小。谢谢大家!

我正在做这个项目,我们正在解析来自查询的数据。我目前正在使用SoundCloud Stratus API创建一个非常基本的SoundCloud网页

$.each(data.slice(0,10), function(index, value) {
    var icon = value.artwork_url;
    if (icon == null) {
        icon = 'assets/blacksoundcloud.png'
    }
};
有没有办法在CSS中编辑图像blacksoundcloud.png?具体来说,我只想编辑图标图像的大小


搜寻

你的问题有点难理解

如果您无法编辑过大的图像,使其大小不合适(这将是理想的),我将尝试以下方法之一:

header img {
  width: 100px !important; /* or the size you require */
  height: 100px; /* or the size you require */
}
或者,如果您必须实际删除原始图像:

header img {
  display: none;
}
header:before {
  content: '';
  display: block;
  height: 100px; /* or the size you require */
  width: 100px; /* or the size you require */
  background: url(assets/soundcloud.png) 0 0 no-repeat;
  background-size: cover;
}

根据我的理解,如果下面的代码没有任何图像,您将更改它的
src

<img id="main-logo" src="assets/soundcloud.png">
上面的代码将图像的宽度和高度固定为100px,即使您上传任何大小的图像。请看下面的片段,图像的原始大小约为336x224。你可以看看它现在的样子

img#主标志[src=”http://imaging.nikon.com/lineup/lens/zoom/normalzoom/af-s_dx_18-140mmf_35-56g_ed_vr/img/sample/img_01.jpg"] {
宽度:100px;
高度:100px;
}

在回答OP关于使用CSS编辑图像的问题时,虽然不能使用CSS更改实际图像,但您可以使用CSS通过影响图像的样式属性(如宽度和高度)来改变图像的显示方式

img#主标志{
宽度:239px;
高度:114px;
内容:url(“https://i.stack.imgur.com/Bw8h1.png");
}

搜寻

在CSS中编辑图像blacksoundcloud.png是什么意思?可以。如果您在DOM树中插入图像,并设法使用CSS、使用类还是id来选择它……我不知道@theAlexandrian是什么意思。@anResh,我想更改显示的图像的大小。它显示在哪里?这是正确的答案。目标图像“src”,因此只有当它是替换图像时,图像才会受到影响。
img#main-logo[src="assets/blacksoundcloud.png"] {
  width:100px;
  height:100px;
}