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

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
JTB
JTB
웹/앱 개발 정보를 공유하고 있습니다.
  • JTB
    JTechBlog
    JTB
  • 전체
    오늘
    어제
    • All About Programming;) N
      • Computer Science
        • Terminology and Concepts
        • Network
        • Operating System
        • Database
        • Data Structure
      • Frontend
        • Javascript Essentials
        • Perfomance Optimization
        • JS Patterns
        • Next.js
        • Flutter
      • Backend
        • Node.js
      • DevOps
        • Docker & Kubernetes
      • Coding Test N
        • LeetCode N
        • 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
      • 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
  • 블로그 메뉴

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

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

  • 인기 글

  • 태그

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

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
JTB
배경이미지 브라우저에 꽉 채우기
상단으로

티스토리툴바