如何使用HTML设置图片的高度和宽度

下载PDF文件下载PDF文件

本指南介绍如何在HTML(超文本标记语言)中设置图片的高度和宽度。

  • 宽度属性指定图片的宽度,单位是像素。
  • 高度属性指定图片的高度,单位是像素。
  • 在HTML 4.01中,可以用像素或包含元素的百分比来定义高度。在HTML5中,只能用像素来定义高度。
  1. How.com.vn 中文: Step 1 编辑要显示图片的文件。
    比如,default.html。
  2. How.com.vn 中文: Step 2 在脚本中添加以下内容:
    • <img src="imagefile.jpg" alt="How.com.vn 中文: Image" height="42" width="42">
    • src是图片的文件路径。
    • alt是图片的标记。
  3. How.com.vn 中文: Step 3 将height和width替换成所需的高度和宽度。
    比如,height="19" width="20"。
  4. How.com.vn 中文: Step 4 保存文件,然后在任意浏览器中打开,以查看效果。
    所有主流浏览器都支持宽度属性,比如Google Chrome、Safari、Mozilla Firefox、Opera、Internet Explorer等。
    广告

小提示

  • 一定要指定图片的高度和宽度。指定后,页面在加载时就可以为图片预留空间。如果没有这些属性,浏览器就不知道图片的大小,也就无法预留空间,从而导致页面布局在加载图片时发生变化。
  • 如果缩小大图片的高度和宽度,虽然在页面上看起来很小,但用户仍需要加载原图。为避免这种情况,先用工具缩小图片,然后再放到网页上。
广告

参考

  1. http://www.w3schools.com/ —— 此网站提供HTML的所有教程。

关于本How.com.vn

How.com.vn是一个“多人协作写作系统”,因此我们的很多文章都是由多位作者共同创作的。 为了创作这篇文章,志愿作者多次对文章进行了编辑和改进。 这篇文章已经被读过9,983次。
本页面已经被访问过9,983次。

这篇文章对你有帮助吗?

⚠️ Disclaimer:

Content from Wiki How 中文 language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

Notices:
  • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
  • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
  • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
  • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

广告