HOME > > >

コンテンツの区切りを斜めにしたい

ランディングページでよくあるコンテンツの区切りを斜めにしたい場合、疑似要素::before、::afterを使うと便利。

HTML

  1. <div class="sample-1">
  2.     <section class="section section-1">
  3.         <p>section-1</p>    
  4.     </section>
  5.     <section class="section section-2">
  6.         <p>section-2</p>
  7.     </section>
  8.     <section class="section section-3">
  9.         <p>section-3</p>    
  10.     </section>
  11. </div>

CSS

  1. /* 枠をオーバーしたものは非表示 */
  2. .sample-1 {
  3.     overflow: hidden;
  4. }
  5.  
  6. .sample-1 .section {
  7.     background: #2aa198;
  8.     position: relative;
  9.     padding: 10rem 0;
  10. }
  11.  
  12. .sample-1 .section p {
  13.     text-align: center;
  14.     font-size: 4rem;
  15.     color: white;
  16. }
  17.  
  18. .sample-1 .section-1, .sample-1 .section-3 {
  19.     background: #6c71c4;
  20. }
  21.  
  22. /* 疑似要素をblockにして回転させる */
  23. .sample-1 .section-2::before {
  24.     content: "section-2 ::before";
  25.     display: block;
  26.     background: #2aa198;
  27.     height: 120px;
  28.     width: 120%;
  29.     transform: rotate(-4deg);
  30.     position: absolute;
  31.     top: -60px;
  32.     left: -10%;
  33.     text-align: center;
  34.     font-size: 4rem;
  35.     color: white;
  36. }
  37.  
  38. /* 疑似要素をblockにして回転させる */
  39. .sample-1 .section-3::before {
  40.     content: "section-3 ::before";
  41.     display: block;
  42.     background: #2aa198;
  43.     height: 120px;
  44.     width: 120%;
  45.     transform: rotate(-4deg);
  46.     position: absolute;
  47.     top: -60px;
  48.     left: -10%;
  49.     text-align: center;
  50.     font-size: 4rem;
  51.     color: white;
  52. }

実行結果

section-1

section-2

section-3