2016-11-17 11 views
2

どのように対角線を描画しますか?常に11°の角度を持ち、両端に固定された角があります。CSSで曲線付きの固定角度の対角線

enter image description here

灰色の領域が上であるべきであり、青色画像のようになります。次の例のように画像のオーバーレイとして使用されます。

理想的には、単純なCSSまたはおそらくdata:image/svg + xmlのいずれかを背景としてスタイリングが可能です。

おそらく画像の上に::afterセレクタを使用するのと同様のものです。あるいは、それに追加されるコンテンツdiv上の::beforeセレクタのセレクタ。たとえば、次のようなものがあります。

<div class="card"> 
    <div class="header"> 
    <img src="#" /> 
    </div> 
    <div class="content"> 
    <h1>Title</h1> 
    <p>Body copy</p> 
    </div> 
</div> 

<style> 
    .content:before { 
    content: ''; 
    display: block; 
    width: 100%; 
    } 
</style> 
+0

提案されたソリューションにはどのような問題がありますか? – Turnip

+0

SVGを使用できるのであれば問題ありません。しかし、CSS + HTMLではスキュー変換が必要なのでこれを達成するのは難しく、テキストなどで問題が生じるでしょう。レイヤー上で画像を試していますか? –

答えて

4

あなたは::before::after擬似要素を展開することができます。

  • absolute positioning
  • border
  • border-radius
  • box-shadow
  • transform: skewY

各擬似要素は、の組み合わせを使用し

div { 
 
display:inline-block; 
 
position: relative; 
 
width: 256px; 
 
height: 140px; 
 
margin-right:32px; 
 
background: url('/my-image.jpg') no-repeat rgb(15,150,196); 
 
overflow: hidden; 
 
} 
 

 
div::before, div::after { 
 
content: ''; 
 
position: absolute; 
 
left: 0; 
 
display: block; 
 
width: calc(100% - 12px); 
 
height: 100%; 
 
border-width: 3px 6px; 
 
border-style: solid; 
 
border-color: rgb(178,178,178); 
 
border-radius: 9px; 
 
box-shadow: 36px -36px 0 36px rgb(178,178,178), -2px 2px 0 2px rgb(178,178,178); 
 
transform: skewY(11deg); 
 
} 
 

 
div::before { 
 
bottom: 50%; 
 
} 
 

 

 
div::after { 
 
top: 50%; 
 
box-shadow: -36px 36px 0 36px rgb(178,178,178), 2px -2px 0 2px rgb(178,178,178); 
 
} 
 

 
.with-image { 
 
background: url('https://images.pexels.com/photos/115045/pexels-photo-115045.jpeg?w=940&h=650&auto=compress&cs=tinysrgb') no-repeat 0 0/256px 140px rgb(15,150,196); 
 
} 
 

 
.with-image::before, .with-image::after { 
 
border-color: rgb(0,127,0); 
 
box-shadow: 36px -36px 0 36px rgb(0,127,0), -2px 2px 0 2px rgb(0,127,0); 
 
} 
 

 
.with-image::after { 
 
box-shadow: -36px 36px 0 36px rgb(0,127,0), 2px -2px 0 2px rgb(0,127,0); 
 
}
<div></div> 
 
<div class="with-image"></div>

+1

それはいいようです。よくやった –

1

このコードは、あなたがしようとしているものに到達するのに役立ちます。

.container{ 
 
    width:300px; 
 
    margin-top:30px; 
 
} 
 
.imagecontainer{ 
 
    width:100%; 
 
    height:200px; 
 
    background:blue; 
 
    transform: skew(0deg, 11deg); 
 
    border-radius:10px; 
 
    margin-bottom:4px; 
 
}
<div class="container"> 
 
    <div class="imagecontainer"></div> 
 
    <div class="imagecontainer"></div> 
 
    <div class="imagecontainer"></div> 
 
</div>

+0

それはまた、画像を斜めにします。私はこれがOPが望んでいるものではないと思います:https://jsfiddle.net/f5Lj3u8t/ – Turnip

+0

ああ、そうです!あなたが正しいです。その場合は、これを試してくださいhttps://jsfiddle.net/f5Lj3u8t/2/ –