2014-10-06 75 views
2

我想要這個:http://gyazo.com/0fe69e349ed5cd4e72a08ed8e60af5d4
但我無法實現它。我可以不是更改圖像。 我已經使用了一個圖像作爲面具,但是這給了我這個:http://gyazo.com/b69e840d095212bce422252cec081fe9
有沒有辦法讓側面部件是白色的?'圖層'在HTML,透明部分

我的代碼:

#section1{ 
    height:275px; 
    width:100%; 
    background-image: url('/img/paral1.jpg'); 
    background-position: center top; 
    background-repeat:no-repeat; 
    background-size: 100% 916px; 
} 
.overlay{ 
    position: absolute; 
    margin-top:180px; 
    height:100px; 
    width:100%; 
    overflow: hidden; 

} 
.mask{ 
    margin: 0 auto; 
    background-image: url('/img/section1.png'); 
    height:100px; 
    width:1080px; 
    background-size:100% 100%; 
} 

編輯:的jsfiddle:http://jsfiddle.net/31kxqmLt/
的jsfiddle在全屏:http://jsfiddle.net/31kxqmLt/embedded/result/
編輯編輯:面具必須有1080px的寬度和空間的其餘部分應該是白色的。

+0

提供您的HTML以及 – Danield 2014-10-06 10:45:58

+0

或撥弄會好 – 2014-10-06 10:46:50

+1

東西[就像這個例子](http://jsbin.com/felah/1/edit)?在較小的寬度上有一個錯覺,它看起來偏離中心,但它不是! – misterManSam 2014-10-06 10:55:45

回答

1

Js fiddle

全屏

Js fiddle

編輯的掩模圖像

設定屏蔽width100%,使其適合於所有決議案

.mask{ 
    margin: 0 auto; 
    background: url('http://s29.postimg.org/5g7z03ypz/image.png') no-repeat bottom; 
    height:100px; 
    width:100%; 
    background-size:100% auto; 
} 

爲較小的分辨率min-width 300

#section1{ 
    max-height:200px; 
    min-height:30%; 
    overflow:hidden; 
    position:relative; 
} 

JS Fiddle

+0

面具的寬度必須爲1080px,其餘空間應爲白色。 – robert 2014-10-06 11:01:45

+0

根據需要進行的更改 – 2014-10-06 11:26:40

+1

如何使它響應,減少標記和SEO的img標籤? http://jsfiddle.net/webtiki/31kxqmLt/6/ – 2014-10-06 11:37:06

3

我讓你正試圖使形狀的這個HTML/CSS的例子。

它使用背景圖像,僞元素和skewX給左下角和右下角的透明切出效果。它也響應:

DEMO

輸出:

image with transparent mask

.wrap { 
 
    width:100%; 
 
    padding-bottom:30%; 
 
    position:relative; 
 
} 
 
.wrap:before { 
 
    content:''; 
 
    background-image: url(http://i.imgur.com/ug3M32a.jpg); 
 
    background-size:100% auto; 
 
    position:absolute; 
 
    width:100%; 
 
    left:0; 
 
    height:50%; 
 
} 
 
.b{ 
 
    position:absolute; 
 
    bottom:0; 
 
    width:50%; height:50%; 
 
} 
 
.l{ 
 
    left:5%; 
 
    transform-origin: 0 0; 
 
    transform: skewX(45deg); 
 
    overflow:hidden; 
 
    border-bottom-left-radius:3%; 
 
} 
 
.r{ 
 
    right:5%; 
 
    transform-origin: 100% 0; 
 
    transform: skewX(-45deg); 
 
    overflow:hidden; 
 
    border-bottom-right-radius:3%; 
 
} 
 
.l:before, .r:before{ 
 
    content:''; 
 
    display:block; 
 
    width:100%; height:100%; 
 
    background-size: 200%; 
 
    background-image: url(http://i.imgur.com/ug3M32a.jpg); 
 
} 
 
.l:before{ 
 
    background-position: 10% -100%; 
 
    transform-origin: 0 0; 
 
    transform: skewX(-45deg); 
 
} 
 
.r:before{ 
 
    background-position: 90% -100%; 
 
    transform-origin: 100% 0; 
 
    transform: skewX(45deg); 
 
} 
 
body { 
 
    padding:20px 10%; 
 
    background-image : url(http://i.imgur.com/k8BtMvj.jpg); 
 
    background-size:cover; 
 
}
<div class="wrap"> 
 
    <div class="b l"></div> 
 
    <div class="b r"></div> 
 
</div>

+1

很好地完成了,相當多的工作,很好的使用了僞元素。 – 2014-10-06 11:44:34

+0

@misterManSam我不能用它作爲答案,因爲無法在灰色背景中顯示圖像(圖像會像僞元素一樣傾斜),這就是爲什麼我需要使用更多div。 – 2014-10-06 12:52:35

+0

@ web-tiki - 哦耶!哦,還是很整潔。 – misterManSam 2014-10-06 13:39:02