2017-05-07 88 views
0
<div class="profile"> 
    <img src="image/JaeHeadShot.jpg" alt="Head Shot"/> 
    <h1> Jae Hong </h1> 
</div> 

.profile{ 
    border: 2px solid rgba(0,0,0,0.3); 
    text-align:center; 
    padding: 30px; 
} 
img.profile{ 
    width:423; 
    height:281; 
} 

这是我的HTML和CSS。我不确定我做错了什么,但图像不会变小。但是,如果我这样做我无法更改HTML和CSS上的图像大小

<img src="image/JaeHeadShot.jpg" alt="headshot" width="423" height="281"/> 

图像似乎改变。我只想知道为什么当我在CSS上工作时它不工作。

感谢您的帮助!

回答

-1

图像在您的代码中没有类属性。因此,使用类配置文件访问它不会获取图像。 所以,只有图像,你可以给 img { width:423; height:281; }

2

img.profile不会选择图像,因为图像没有配置文件类,这一数字正在丢失的单位。

做这样的:

img { 
    width : 423px; 
    height : 281px; 
} 
+0

那么我怎样才能选择div class“profile”中的图片呢?我也试过给它一个id =“headshot”,并在CSS中使用了img#headshot。它不起作用。感谢您的帮助! –

+1

不可以。要将该类用作选择器,您必须编写'.profile img'来选择任何'img',它是具有类'profile'的元素的后代。 – Pharaoh

+0

要使用该类名称,您应该像div.profile img {width:423px; height:281px;}。 – gaganshera

0

曲线是对于div元素类,而不是针对图像。

img.profile{ 
    width:423; 
    height:281; 
} 

如果你想使用特殊的css的图像,你可以为它定义一个类。

.myImage{ width: 423px; height: 281px} 

并在图像标签中使用它。

<img src="image/JaeHeadShot.jpg" alt="headshot" class=".myImage"/>