programing tip

속기 배경 속성의 배경 크기 (CSS3)

itbloger 2020. 8. 6. 08:03
반응형

속기 배경 속성의 배경 크기 (CSS3)


숏 핸디 드 속성 background-imagebackground-size속성 을 혼합하려고 background합니다. W3C 문서 에 따르면 슬래시 ( )로 구분 background-sizebackground-position속성 뒤에 와야 /합니다.

W3C 예 :

p { background: url("chess.png") 40% / 10em gray
       round fixed border-box; } 

다음과 같습니다.

p {
    background-color: gray;
    background-position: 40% 50%;
    background-size: 10em 10em;
    background-repeat: round round;
    background-clip: border-box;
    background-origin: border-box;
    background-attachment: fixed;
    background-image: url(chess.png) }

MDN도 마찬가지입니다. 나는 또한 발견 속기 CSS3 배경 속성이 설명에 대한 기사를.

그러나 이것은 작동하지 않습니다! 또한 약식 만드는 방법을 분명하지 않다 background속성을 때 background-sizebackground-position두 개의 서로 다른 값을 가질 수 background-position-xbackground-position-y또는 같은 일 background-size. 슬래시 ( /)가 어떻게 발생하는지 확실하지 않습니까? 이 예 는 Chrome 15에서 작동하지 않습니다.

간략한 설명이 CSS 코드는 다음과 같습니다.

div {  
    background: url(http://www.placedog.com/125/125) 
        0 0 /  150px 100px 
        repeat no-repeat 
        fixed border-box padding-box blue;      
    height: 300px;
    width:360px;    
    border: 10px dashed magenta;  
}

더 깨끗한 예

이것은 작동합니다 ( JSFiddle )

 body{
        background-image:url(http://www.google.com/intl/en_com/images/srpr/logo3w.png);
        background-position:200px 100px;
        background-size:600px 400px;
        background-repeat:no-repeat;
    }

이것은 작동하지 않습니다 ( jsfiddle )

body{
    background:url(http://www.google.com/intl/en_com/images/srpr/logo3w.png) 200px 100px/600px 400px no-repeat;
}

이것은 너무 작동하지 않습니다 ( jsfiddle )

body{
    background:url(http://www.google.com/intl/en_com/images/srpr/logo3w.png) 200px/400px 100px/600px no-repeat;
}

  1. 귀하의 jsfiddle background-image대신에background
  2. "아직이 브라우저에서 지원되지 않는"것 같습니다.

이것은 Opera에서 작동합니다 : http://jsfiddle.net/ZNsbU/5/
그러나 FF5 또는 IE8에서는 작동하지 않습니다. (구식 브라우저의 경우 : D)

코드 :

body {
  background:url(http://www.google.com/intl/en_com/images/srpr/logo3w.png) 400px 200px / 600px 400px no-repeat;
}

당신은 이렇게 할 수 있습니다 :

body {
    background:url(http://www.google.com/intl/en_com/images/srpr/logo3w.png) 400px 400px no-repeat;
    background-size:20px 20px
}

FF5 및 Opera에서는 작동하지만 IE8에서는 작동하지 않습니다.


당신은 할 수 있습니다

 body{
        background:url('equote.png'),url('equote.png');
        background-size:400px 100px,50px 50px;
    }

참고로 참고 사항 : 나는 이렇게 속기하려고했습니다.

background: url('../images/sprite.png') -312px -234px / 355px auto no-repeat;

but iPhone Safari browsers weren't showing the image properly with a fixed position element. I didn't check with a non-fixed, because I'm lazy. I had to switch the css to what's below, being careful to put background-size after the background property. If you do them in reverse, the background reverts the background-size to the original size of the image. So generally I would avoid using the shorthand to set background-size.

background: url('../images/sprite.png') -312px -234px no-repeat;
background-size: 355px auto;

try out like this

body {
   background: #fff url("!--MIZO-PRO--!") no-repeat center 15px top 15px/100px;
     }


/* 100px is the background size */

You will have to use vendor prefixes to support different browsers and therefore can't use it in shorthand.

body { 
        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;
}

참고URL : https://stackoverflow.com/questions/7864448/background-size-in-shorthand-background-property-css3

반응형