2017-08-30 8 views
0

私はこのようになりますCSSの背景を作成しようとしています:角度の付いたCSSの背景に下の境界線があります。

enter image description here

私は形状を作成することができましたが、下の境界を追加する方法を見つけ出すことはできません、としています私のアプローチが問題になるかもしれないと考え始めた。

#top-background-flag { 
    border-top: 2px solid #C2C2C2; 
    background: linear-gradient(
    to bottom right, 
    #5DCAD3 50%, 
    transparent 50.5% 
) 
    no-repeat bottom, /* bottom part */ 
    linear-gradient(100deg, #5DCAD3, #5DCAD3) no-repeat top; 
    /* top portion */ 
    padding-bottom: 3.5rem; 
    border-bottom: 2px solid #C2C2C2; 
    background-size: 100% 3rem, 100% calc(100% - 3rem) 
} 

とHTML::

<div id=top-background-flag> 
    A fun title 
</div> 

とコードペン:

は、これまでのところ私は、次のCSSを持ってhttps://codepen.io/arel/pen/PKXGmd

私の問題は今、下の境界線があるということです私はそれがボックスの角度に従う方法を理解できません。ここで

は、私がこれまで持っているものです。

enter image description here

+1

と遊ぶworking exampleです。あなたが最初に来たことに気付かなかった。あなたにチェックマークを付けました。 – Arel

+0

彼はここでクレジットを求めるためにコメントして、彼は要求しているコメントを削除しました...あなたはそれが意味するものを自分で決定します – McHat

+0

@McHat私は単に受け入れられた答えが私の答えからコピーされたものである理由を尋ねました。確かに彼は彼が好きな答えを選択するOPの決定、私はちょうど私が私からコピーされた答えを選択することを決めた理由を知りたいと思った。それで全部です。 – Dekel

答えて

3

は、ここでは最善の解決策ではないかもしれません。

多少のCSS変換でオブジェクトを追加すると、賢明なレイヤリングが必要なものを実現し、あとで角度を変更したい場合は調整するプロパティが少なくなります。ここで

#top-background-flag { 
    border-top: 2px solid #C2C2C2; /* top border on the parent */ 
    position: relative; 
    padding-bottom: 3.5rem; 
    overflow: hidden; 
} 

#top-background-flag:before { 
    background-color: #5DCAD3; 
    transform: skewy(-4deg); /* angle you want */ 
    transform-origin: bottom left; 
    border-bottom: 2px solid #C2C2C2; /* bottom border skews with the object */ 
    content: ' '; 
    display: block; 
    height: 100%; 
    width: 100%; 
    position: absolute; 
    z-index: -1; 
    bottom: 0; 
} 

申し訳@Dekel

0

私は、これはあなたが探しているものであることをわからないんだけど、あなたはcontentトリックで:after疑似クラスを使用することができます。

body { 
 
    max-width: 500px; 
 
} 
 

 
#top-background-flag { 
 
    border-top: 2px solid #C2C2C2; 
 
    background: linear-gradient(
 
    to bottom right, 
 
    #5DCAD3 50%, 
 
    transparent 50.5% 
 
) 
 
    no-repeat bottom, /* bottom part */ 
 
    linear-gradient(100deg, #5DCAD3, #5DCAD3) no-repeat top; 
 
    /* top portion */ 
 
    padding-bottom: 3.5rem; 
 
    border-bottom: 2px solid #C2C2C2; 
 
    background-size: 100% 3rem, 100% calc(100% - 3rem); 
 
    position: relative; 
 
} 
 

 
#top-background-flag:after { 
 
    content: ''; 
 
    border-bottom: 1px solid red; 
 
    border-top: 1px solid red; 
 
    position: absolute; 
 
    width: 100%; 
 
    bottom: 22px; 
 
    left: 0; 
 
    transform: rotate(-5.5deg); 
 
}
<div id=top-background-flag> 
 
    A fun title 
 
</div>

1

偽にこのCSSを追加下の境界:

#top-background-flag:after { 
    content: ""; 
    background-color: red; 
    height: 2px; 
    width: 100%; 
    position: absolute; 
    left: 0; 
    bottom: 23px; 
    transform: rotate(-5.5deg); 
} 

ここでは、あなたのcodepenの作業フォークです:線形グラデーションを使用しようとhttps://codepen.io/anon/pen/XaojPp

関連する問題