如何使用 css 为 html 图像分配一个类?

这是html部分:

.bild{
  height:100px;
  width: 100px;
}
<div class = "wrapper">
    <img class = "bild" src="https://placeholder.com/wp-content/uploads/2018/10/placeholder.com-logo1.png" alt="the google logo" > 
</div>

他们似乎并不“理解”彼此,因为图像没有改变。

jiuyefuwu 回答:如何使用 css 为 html 图像分配一个类?

您提供的图片示例有效。可能是您没有注意到任何差异。这是我使用类为文本着色的另一个示例:

.color {
  color: red;
}

.colorHeader {
  color: red;
}
<p class="color">This text is red!</p>

<h1 class="colorHeader">This header is red!</h1>

你也可以改变这个:

.color {
  color: red;
}

.colorHeader {
  color: red;
}

为此:

.color,.colorHeader {
  color: red;
}
,

您的 HTML 中有一些额外的空格,但输出仍然按照您的 CSS 中的定义工作。在这种情况下,我建议指定所需的宽度或高度,并在另一个上使用 auto。

.bild {
  height: auto;
  width: 200px;
}
<div class="wrapper">
    <img class="bild" src="https://placeholder.com/wp-content/uploads/2018/10/placeholder.com-logo1.png" alt="the google logo"> 
</div>

本文链接:https://www.f2er.com/24683.html

大家都在问