본문 바로가기
HTML/HTML

HTML) 이미지 관련 태그 (절대주소, 상대주소, 절대크기, 상대크기)

by 박채니 2022. 5. 11.

안녕하세요, 코린이의 코딩 학습기 채니 입니다.

 

개인 포스팅용으로 내용에 오류 및 잘못된 정보가 있을 수 있습니다.


이미지 관련

- img 시작/종료 태그 구분 없이 하나의 태그만 작성

<img src="" alt="" />

- src : 이미지 경로 (절대경로, 상대경로)

- alt : 대체 텍스트 (이미지를 못 찾거나, 시각적 확인이 불가능한 경우 사용할 텍스트)

 

절대 주소

- 프로토콜 또는 / 로 시작

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>이미지관련</title>
    <style> 
    img {
        width: 300px;
    }
    </style>
</head>
<body>
    <h1>이미지관련</h1>
    <!-- 절대주소 -->
    <!-- 절대 주소는 / 또는 프로토콜로 시작 -->
    <img src="http://192.168.0.46:5500/sample/image/flower1.PNG" alt="꽃1" title="꽃1">
    <img src="/sample/image/flower2.PNG" alt="꽃2" title="꽃2">
    <!-- 파일프로토콜 절대 주소는 서버 환경에서는 보안 상의 이유로 사용 불가 -->
    <img src="C:\Workspaces\web_client_workspace\sample\image\flower3.PNG" alt="꽃3" title="꽃3">
</body>

프로토콜과 /로 시작하였기 때문에 절대 주소라는 것을 알 수 있으며, 꽃3은 파일프로토콜 (File Path)로 접근하려고 하였지만 불가합니다.

서버 환경에서는 보안 상의 이유로 인하여 접근이 불가하기 때문입니다.

(폴더에서 드래그 + 드랍하면 보여지긴 함)

 

상대주소

- 프로토콜 또는 /로 시작하지 않는 주소 (현재 페이지 기준으로 검색)

 <!-- 상대 주소 -->
<img src="./sample/image/flower1.PNG" alt="꽃1" title="꽃1">
<!-- 현재 디렉토리에서 sample을 찾음 -->
<img src="../../sample/image/flower2.PNG" alt="꽃2" title="꽃2"> 
<!-- 부모의 부모의 디렉토리에서 sample을 찾음 -->

현재 파일 구조

꽃1은 ./ 현재 디렉토리에서 sample폴더를 찾으므로, 해당 폴더가 없어서 이미지 render가 불가

꽃2는 ../../ 부모 디렉토리의 부모 디렉토리에서 sample폴더를 찾으므로, 이미지 render 가능

현재 파일 구조 상에서 보았을 때도 study → 01_html → web_client_workspace (sample) 이기 때문에 부모의 부모 디렉토리에서 찾아야겠죠.

./ 현재 디렉토리
../ 부모 디렉토리

 

이진데이터를 base64로 인코딩 : File API 사용 시 유용

 <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBIVFRUVFRUYEhgSEhgYGBEVEhESERESGBgZGRgUGBgcIS4lHB4rIRkYJjgmKy8xNTU1GiQ7QDszPy40NTEBDAwMEA8QHxISHjQrISs0NDQxNDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQxNDQ0NDQ0NDQ0NDQ0NP/AABEIALcBEwMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAEBQIDBgABB//EADcQAAIBAwMCBAUCBQMFAQAAAAECAAMEERIhMQVBBlFhcRMiMoGRocEUQlKx8Acj0RVicuHxM//EABkBAAMBAQEAAAAAAAAAAAAAAAABAwIEBf/EACMRAAMBAAMBAAICAwEAAAAAAAABAhEDEiExMkEiYUJRgRP/2gAMAwEAAhEDEQA/AArkRPcx3cLFdxTzGITNzJrCWt95NKEMGDLLE5hS0JdRtsmLAPKWZdvDUtvSXC2mcDRScyOD5R0LHbOJWbSJzo1WCc5l9GmWPEMNrD7e2xiNTgqrQRLXbiG2nTNe5EKRI26WBwYVOocVlaKqnRFxxEN14cqMHZV2QfdsnGB5z6NcuiIXIz2UeZmQubmrq1gnnnJ29py0+rw9GLdSYMqUYqQR6HtPXczV+Irb4q06wUA7o5G2ptirfjMT/wACccTU14DWiT4m8b9NrmA3VrpMJsBH+w3zGPg+0FuWly8QW4MtvhyUv5ArSBljSszA8Ixx00xRG3T4qEPrY7iaGwmbtzuJo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D95L6ic9sfpOnTD/IsvxPSDgem49vKW25GZ06Un6Sr4X1qn9v34mbr1CxZuN/0zOnR0Rv8Rc77weo86dOY5D2nLsgTydADxnkGnToGgdhKXE9nTUjKtMrcz2dGBU7mUsTOnTQz0Ezxp06A0eTp06MD//Z" alt="">


절대 크기 px

- 고정된 크기

<h2>절대크기 px</h2>
    <!-- div>img[src=../../sample/image/flower$.PNG]*5 -->
    <div>
        <img src="../../sample/image/flower2.PNG" alt="" style="width:200px">
        <img src="../../sample/image/flower3.PNG" alt="" style="width:200px">
        <img src="../../sample/image/flower1.PNG" alt="" style="width:200px">
        <img src="../../sample/image/flower4.PNG" alt="" style="width:200px">
        <img src="../../sample/image/flower5.PNG" alt="" style="width:200px">
    </div>

이렇게 절대크기 px로 지정하게 되면, 고정된 크기이므로 화면이 작아지거나 커져도 해당 사이즈를 그대로 유지합니다.

 

상대크기 %, em, rem, vh, vw

<h2>상대크기 $ em rem vh vw</h2>
    <div>
        <img src="../../sample/image/flower1.PNG" alt="" style="width:18%">
        <img src="../../sample/image/flower2.PNG" alt="" style="width:18%">
        <img src="../../sample/image/flower3.PNG" alt="" style="width:18%">
        <img src="../../sample/image/flower4.PNG" alt="" style="width:18%">
        <img src="../../sample/image/flower5.PNG" alt="" style="width:18%">
    </div>

 

절대 크기와는 달리 화면에 따라 사진이 커지거나 작아지는 것을 확인할 수 있습니다.

 

 

'HTML > HTML' 카테고리의 다른 글

HTML) 멀티 미디어 관련 태그  (0) 2022.05.11
HTML) 링크 관련 태그 (a 태그의 href 속성, target 속성)  (0) 2022.05.11
HTML) block / inline 요소  (0) 2022.05.11
HTML) table 관련 태그  (0) 2022.05.11
HTML) 목록 관련 태그  (0) 2022.05.11