【问题标题】:45 degree angle split background colour for website网站的 45 度角分割背景颜色
【发布时间】:2015-03-28 05:14:55
【问题描述】:

谁能告诉我为响应式网站获得像这样的缩放分割背景效果的最佳方法。在 HTML5 和 CSS3 中使用:

我尝试了渐变,但边缘呈锯齿状,在我深入研究另一种方法之前,我会很感激任何想法。理想情况下必须回到 IE9。

谢谢

【问题讨论】:

  • 查看css-tricks' tutorial on how to create triangles。我相信这在某些情况下是一个有效的解决方案,因为您可以创建多个三角形并更改它们的颜色。您还可以创建一个具有一种颜色的容器,并在其上方放置一个具有另一种颜色的三角形。这样你实际上只创建了一个三角形,但应该会得到想要的效果。
  • @Shahar:是的,我尝试过类似的方法,但是随着屏幕变小,无法让三角形与其余内容一起缩放。我会再看看它。

标签: html css background responsive-design angle


【解决方案1】:

希望这会有所帮助:http://codepen.io/ZsharE/pen/VYRPwW!

HTML

<div class="shape">
  <div class="top"></div>
  <div class="shape-content">
      <h1>Diagonal background</h1>
  </div>
</div>

CSS

html, body {
    margin: 0px;
    padding: 0px;
}

.shape {
    width: 100%;
    margin:0 auto;
    position: relative;
    background: #468d91;
}

.shape-content {
    max-width: 1170px;
    margin:0 auto;
  padding: 200px 15px 200px 15px;
}

.shape-content h1 {
    margin: 0px;
    padding: 0px 15px;
    z-index: 9;
    position: relative;
    color: #ffffff;
    font-size: 50px;
    font-family: 'Open Sans', sans-serif;
    text-align: center;
    text-shadow: 0px 2px 4px #444444;
    font-weight: 300;
}

.top {
  position: absolute;
    top: 0;
    left: 0;
  border-style:solid;
  border-color:transparent transparent #3c888b #3c888b;
  z-index: 1;
}

JS

function angle() {
    var w = $(window).width();
    var h = $(".shape").height();
    $('.top').css('border-right-width', w - 3);
    $('.top').css('border-bottom-width', h - 3);
}

$(document).ready(function(){

    $(window).bind("load", function(){
        angle();
    });

    $(window).resize(function(){
        angle();
    });

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    • 2021-09-15
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多