Computer >> 컴퓨터 >  >> 프로그램 작성 >> HTML

HTML 이미지 크기

HTML 이미지 크기는 이미지의 높이와 너비를 나타냅니다. 에 HTML 속성으로 나열됩니다. 요소. 설정 방법은 다음과 같습니다.

구문

<img>의 너비 및 높이 속성을 설정하는 구문 태그:

<img src="<name of website>" alt="<alt tag>" height="<in px>" width="<in px>" />

작동 방식을 보여주는 코드 스니펫은 다음과 같습니다.

<!DOCTYPE html>
<html>
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width">
   <title>repl.it</title>
   <link href="style.css" rel="stylesheet" type="text/css" />
 </head>
 <body>
   <h1>Image Size in HTML</h1>
   <h2>without attributes</h2>
   <img src="https://placekitten.com/500/500" />
   <h2>with attributes</h2>
   <img src="https://placekitten.com/500/500" width="300" height="300" />
   <script src="script.js"></script>
 </body>
</html>

<img>의 높이와 너비 요소는 픽셀 단위의 숫자입니다(따옴표 사이). 웹 페이지가 로드되기 전에 이미지에 공간이 할당되도록 높이와 너비 속성을 모두 표시하는 것이 좋습니다. 페이지 렌더링 전에 이미지의 크기가 표시되지 않으면 이미지가 로드될 때 페이지의 레이아웃이 조정됩니다.

브라우저 지원

<img>의 너비 및 높이 속성 요소는 모든 웹 브라우저에서 지원됩니다.