2013-04-08 102 views
1

之間建立合適的梯度有兩個街區 http://imageshack.us/a/img203/9351/555el.png我怎麼可以兩個div

我怎麼能這樣 http://imageshack.us/a/img521/1866/8585.png

創建這些塊之間gradiend這是我的CSS和HTML代碼

<style type="text/css"> 
    div.fx6p1 { 
    width: 580px; 
    height: 721px; 
    background: #EDEDED; 
    margin: 40px 0 0 40px; 
    padding: 9px; 
    } 
div.fx6Ra { 
    width: 200px; 
    background: #333333; 
    height: 560px; 
    margin: 170px 0 0 589px; 
} 
</style> 
<div class="fx6p1"> 
    <div class="fx6Ra"> 
    </div> 
</div> 

回答

0

容易,但並不完美的方式:box-shadow

http://jsfiddle.net/yA3CX/

div.fx6Ra { 
    box-shadow:-10px 0px 25px #404040; 
} 

硬方式:::beforeline-gradient

http://jsfiddle.net/yA3CX/2/

div.fx6Ra:before, 
div.fx6Ra::before { 
    content:' '; 
    display:inline-block; 
    position:absolute; 
    top:219px; 
    left:633px; 
    height:560px; 
    width:15px; 
    background-image:-webkit-linear-gradient(right,black,transparent); 
    background-image:-moz-linear-gradient(to left,black,transparent); 
    background-image:-ms-linear-gradient(to left,black,transparent); 
    background-image:-o-linear-gradient(to left,black,transparent); 
    background-image:linear-gradient(to left,black,transparent); 
} 

http://jsfiddle.net/yA3CX/3/

div.fx6Ra:before, 
div.fx6Ra::before { 
    content:' '; 
    display:inline-block; 
    position:relative; 
    top:0px; 
    left:-15px; 
    height:560px; 
    width:15px; 
    background-image:-webkit-linear-gradient(right,black,transparent); 
    background-image:-moz-linear-gradient(to left,black,transparent); 
    background-image:-ms-linear-gradient(to left,black,transparent); 
    background-image:-o-linear-gradient(to left,black,transparent); 
    background-image:linear-gradient(to left,black,transparent); 
} 
+0

正確地發現盒子陰影並不完美,因爲它超出了頂部和底部。無論如何,用其他div中的影子插入可能會更容易修復? – vals 2013-04-08 10:14:53

+0

@vals我不這麼認爲。你可以在小提琴上演示嗎? – Passerby 2013-04-08 10:18:38

0

您可以使用CSS陰影。

here這個meight幫助您

0

只需使用box-shadow

div.fx6Ra { 
    width: 200px; 
    background: #333333; 
    height: 560px; 
    margin: 170px 0 0 589px; 
    box-shadow: -8px 0px 8px 1px #888; 
} 

box-shadow具有以下值:

box-shadow: x y blur spread color; 

Working Demo

0

CSS3「box-shadow」樣式屬性將有助於您的需求。 的語法的box-shadow屬性是

box-shadow: h-shadow v-shadow blur spread color inset; 

請檢查tutorial。並嘗試在線使用的樣式box-shadow style generator

+0

'w3schools'不是一個可靠的資源。請檢查[w3fools.com](http://w3fools.com/) – Eli 2013-04-08 09:52:21

0

請嘗試此代碼。它在Firefox和Chrome中工作,我檢查過它。

<style type="text/css"> 
    div.fx6p1 { 
    width: 580px; 
    height: 721px; 
    background: #EDEDED; 
    margin: 40px 0 0 40px; 
    padding: 9px; 
    } 
div.fx6Ra { 
    width: 200px; 
    background: #333333; 
    height: 560px; 
    margin: 170px 0 0 589px; 
    box-shadow: -10px 0 4px 0 #888888; 
} 
</style> 
<div class="fx6p1"> 
    <div class="fx6Ra"> 
    </div> 
</div> 
0

從你在你的例子(http://imageshack.us/a/img521/1866/8585.png)中提到的亮點,我假設你實際上是在談論下拉陰影。

要獲得與圖像完全相同的下拉陰影,它只出現在方框的左側,一種方法是包含一個額外的div。

HTML:

<div class="fx6p1"> 
    <div class="fx6Ra"> 
     <div class="dropshadow-leftonly"></div> 
    </div> 
</div> 

CSS:

div.fx6p1 { 
    width: 580px; 
    height: 721px; 
    background: #EDEDED; 
    margin: 40px 0 0 40px; 
    padding: 9px; 
} 
div.fx6Ra { 
    position: relative; 
    margin: 170px 0 0 579px; 
    overflow: hidden; 
    display: block; 
    width: 210px; 
    height: 560px; 
} 
.dropshadow-leftonly { 
    display: block; 
    width: 200px; 
    height: 560px; 
    background: #333333; 
    box-shadow: 0px 0px 5px 5px #ababab; 
    float: right; 
} 

這裏有一個工作示例:http://jsfiddle.net/shodaburp/A4c4p/