2013-01-14 10 views
7

Czy można użyć CSS, aby lewy i prawy brzeg kontenera treści wyglądał jak ten obraz? Próbowałem znaleźć sposób, aby to zrobić bez użycia obrazu, jeśli to możliwe.CSS zakrzywione gradienty i box-shadow

image of left and right borders

Oto jsFiddle że pracuję dalej. CSS dla "najwyższej" klasy nigdy nie zostanie zastosowany. Wygląda na to, że CSS dla klasy "bottom" działa dobrze.

http://jsfiddle.net/kXuQY/

HTML:

<div class="drop-shadow top bottom"> 
    Content here. 
</div> 

CSS:

.drop-shadow { 
/** Create container. Box-shadow here is to color the inside of the container **/ 
position:relative; 
width:50%; 
background: none repeat scroll 0 0 #FFFFFF; 
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset; 
padding:3em; 
margin: 2em 20px 4em; 
text-align:center 
} 

.top:before, 
.top:after { 
    /** Generate pseudo-elements ('before' and 'after') and push them behind the container box. Position pseudo-elements ('before', and 'after') and give them dimensions **/ 
content:""; 
position:absolute; 
z-index:-1; 
top:20px; 
left:0; 
width:40%; 
height:1em; 
max-width:150px; 
-webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); 
-moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); 
box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); 
-webkit-transform:rotate(70deg); 
-moz-transform:rotate(70deg); 
-o-transform:rotate(70deg); 
transform:rotate(70deg); 
} 

.top:after{ 
    /**One of the pseudo-elements then needs to be positioned on the other side of the element and rotated in the opposite direction. This is easily done by overriding only the properties that need to differ **/ 
right:0; 
left:auto; 
-webkit-transform:rotate(-70deg); 
-moz-transform:rotate(-70deg); 
-o-transform:rotate(-70deg); 
transform:rotate(-70deg); 
} 

.bottom:before, 
.bottom:after { 
    /** Generate pseudo-elements ('before' and 'after') and push them behind the container box. Position pseudo-elements ('before', and 'after') and give them dimensions **/ 
content:""; 
position:absolute; 
z-index:-2; 
top:90px; 
left:0; 
width:10%; 
max-width:150px; 
-webkit-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); 
-moz-box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); 
box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); 
-webkit-transform:rotate(99deg); 
-moz-transform:rotate(99deg); 
-o-transform:rotate(99deg); 
transform:rotate(99deg); 
} 

.bottom:after{ 
    /**One of the pseudo-elements then needs to be positioned on the other side of the element and rotated in the opposite direction. This is easily done by overriding only the properties that need to differ **/ 
right:0; 
left:auto; 
-webkit-transform:rotate(-99deg); 
-moz-transform:rotate(-99deg); 
-o-transform:rotate(-99deg); 
transform:rotate(-99deg); 
} 
+4

Spójrz na to [link] (http://www.sitepoint.com/pure-css3-paper-curl/) Dodaje wygląd dolnej lokówki, ale może pomóc Ci dowiedzieć się, jak to działa po lewej i prawej stronie. –

+0

Dzięki, zaktualizowałem pytanie z jsfiddle i css, które dotychczas miałem. Myślę, że jest blisko, ale nadal ma pewne problemy. – Mdd

Odpowiedz

6

można użyć przed i po właściwości CSS, aby to osiągnąć. to check out: http://nicolasgallagher.com/css-drop-shadows-without-images/demo/

Innym sposobem:

HTML:

<div id="box"> 
<h1>css-3-box-shadow</h1> 
<p>some text</p> 
</div> 

CSS:

#box:after { 
    left: auto; 
    right: 10px; 
    transform: rotate(3deg); 
} 
#box:before, #box:after { 
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0.7); 
    bottom: 15px; 
    box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7); 
    content: ""; 
    left: 10px; 
    max-width: 300px; 
    position: absolute; 
    top: 80%; 
    transform: rotate(-3deg); 
    width: 50%; 
    z-index: -1; 
} 
#box:before, #box:after { 
    background: none repeat scroll 0 0 rgba(0, 0, 0, 0.7); 
    bottom: 15px; 
    box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7); 
    content: ""; 
    left: 10px; 
    max-width: 300px; 
    position: absolute; 
    top: 80%; 
    transform: rotate(-3deg); 
    width: 50%; 
    z-index: -1; 
} 
#box { 
    background: none repeat scroll 0 0 #DDDDDD; 
    border-radius: 4px 4px 4px 4px; 
    color: rgba(0, 0, 0, 0.8); 
    line-height: 1.5; 
    margin: 60px auto; 
    padding: 2em 1.5em; 
    position: relative; 
    text-shadow: 0 1px 0 #FFFFFF; 
    width: 60%; 
} 

Ref: http://www.red-team-design.com/wp-content/uploads/2011/04/css3-box-shadow.html

Nadzieję, że pomaga.

+0

Dzięki za porady! Zaktualizowałem to pytanie za pomocą jsfiddle i CSS, które dotychczas miałem. Tutaj znowu jest skrzypce: http://jsfiddle.net/kXuQY/ Wydaje mi się, że CSS dla mojej "najwyższej" klasy jest nadpisany lub coś go powoduje, że nie zostanie zastosowane. – Mdd

+1

@Mdd - Można utworzyć 3 oddzielne elementy DIV, a następnie zastosować cienie (używając powyższego kodu) do górnego i dolnego elementu div (górny cień pierwszego elementu i dolny cień trzeciego elementu div). Pozostaw środkową dla zawartości. I na koniec ustaw wszystkie DIV, aby całość wyglądała jak zunifikowane pudełko. – Learner

+0

Dzięki! Zaktualizowałem skrzypce i wiem, co teraz zrobić. Dzięki jeszcze raz! http://jsfiddle.net/kLhP8/ – Mdd