배경이미지 브라우저에 꽉 채우기

2021. 5. 21. 12:17·Computer Science/Terminology and Concepts

출처: https://knulab.com/archives/1185

 

배경이미지 브라우저에 꽉 채우기 – KNULAB

브라우저 뷰포트에 배경이미지가 꽉 차게 보여지려면 아래와 같이 min-height 값을 설정한다.   Full Background Cover body, html { margin: 0; padding: 0; height: 100%; } .bgimg { border: 0; padding: 0; background-image: url('ima

knulab.com

 

브라우저 뷰포트에 배경이미지가 꽉 차게 보여지려면 아래와 같이 min-height 값을 설정한다.

<!DOCTYPE html>
<html>
  <title>Full Background Cover</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
  body, html { 
      margin: 0;
      padding: 0;
      height: 100%;
  }
  .bgimg {
      border: 0;
      padding: 0; 
      background-image: url('image.jpg');
      min-height: 100%;
      background-position: center;
      background-size: cover;
  }
  </style>
  <body>


  <div class="bgimg"></div>


  </body>
</html>

 

첫번째 방법

html { 
  background: url(images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

두번째 방법

img.bg {
  /* Set rules to fill background */
  min-height: 100%;
  min-width: 1024px;
    
  /* Set up proportionate scaling */
  width: 100%;
  height: auto;
    
  /* Set up positioning */
  position: fixed;
  top: 0;
  left: 0;
}

@media screen and (max-width: 1024px) { /* Specific to this particular image */
  img.bg {
    left: 50%;
    margin-left: -512px;   /* 50% */
  }
}

세번째 방법

<img src="images/bg.jpg" id="bg" alt="">
#bg {
  position: fixed; 
  top: 0; 
  left: 0; 
    
  /* Preserve aspet ratio */
  min-width: 100%;
  min-height: 100%;
}

네번째 방법

<div id="bg">
  <img src="images/bg.jpg" alt="">
</div>
#bg {
  position: fixed; 
  top: -50%; 
  left: -50%; 
  width: 200%; 
  height: 200%;
}
#bg img {
  position: absolute; 
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0; 
  margin: auto; 
  min-width: 50%;
  min-height: 50%;
}

 

 

 

'Computer Science > Terminology and Concepts' 카테고리의 다른 글

SPA - CSR/SSR/SSG  (0) 2021.08.01
DOM/CSSOM/BOM/Virtual DOM  (0) 2021.07.31
How to improve an E-Commerce Checkout Experience: UI/UX Case study  (0) 2021.05.11
How to use Real-time DB of Firebase  (0) 2021.04.20
React Convenient Tools - Prettier, ESLint, Snippet  (0) 2021.04.19
'Computer Science/Terminology and Concepts' 카테고리의 다른 글
  • SPA - CSR/SSR/SSG
  • DOM/CSSOM/BOM/Virtual DOM
  • How to improve an E-Commerce Checkout Experience: UI/UX Case study
  • How to use Real-time DB of Firebase
히어운트예츠트
히어운트예츠트
건축학 -> 경제학 -> 호주 워홀 -> 해외영업 -> 개발자 -> ?
  • 히어운트예츠트
    기술블로그
    히어운트예츠트
  • 전체
    오늘
    어제
    • All About Programming;)
      • Other than Tech
        • 잡생각
      • Computer Science
        • Terminology and Concepts
        • Network
        • Operating System
        • Database
        • Data Structure
        • Web Development
        • Interview Prep
      • Frontend
        • Javascript Essentials
        • Perfomance Optimization
        • JS Patterns
        • React
        • Next.js
        • Flutter
        • Testing
      • Backend
        • Node.js
      • DevOps
        • Docker & Kubernetes
      • Coding Test
        • LeetCode
        • Programmers
      • Tech Books & Lectures
        • Javascript_Modern JS Deep d..
        • Network_IT 엔지니어를 위한 네트워크 입문
      • Projects
        • PolyLingo_2025
        • Build Your Body_2024
        • JStargram_2021
        • Covid19 Tracker_2021
        • JPortfolio_2021
        • Nativ_2026
      • BootCamp_Codestates
        • TIL
        • TILookCloser
        • Pre Tech Blog
        • IM Tech Blog
        • Daily Issues and DeBugging
        • First Project
        • Final Project
        • Sprint Review
        • Good to Know
        • Socrative Review
        • HTML &amp; CSS
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 글쓰기
    • 관리
  • 공지사항

  • 인기 글

  • 태그

    자바스크립트
    How memory manage data
    프론트엔드 성능 최적화 가이드
    Binary Tree BFS
    Network
    자바스크립트 딥다이브
    스코프
    Threads and Multithreading
    딥다이브
    Time complexity and Space complexity
    mobile app
    Data Structure
    indie hacker
    커리어
    모던 자바스크립트 Deep Dive
    이벤트
    polylingo
    Operating System
    js pattern
    leetcode
    database
    testing
    CPU scheduling algorithm
    structure of os
    DOM
    TCP/IP
    Shared resources
    개인의무한한능력이요구되는세상
    VoiceJournal
    Javascript Essentials
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
히어운트예츠트
배경이미지 브라우저에 꽉 채우기
상단으로

티스토리툴바