【问题标题】:How to draw cross background via css which is responsive如何通过响应式css绘制交叉背景
【发布时间】:2018-07-01 17:15:58
【问题描述】:

如何通过 css 在单个部分(div)中绘制这样的形状?

目前我使用了两个 div 检查我的代码

这个想法很简单,从水平中间,黑色首先需要下降 45 度直到下一个 100 像素,然后它应该下降 180 度,剩下的部分。所有这些都需要为单个容器/部分/div 完成。

.grad {
  height:100px;
  width:100%;
  background:linear-gradient(45deg, white 50%, black 0),
  linear-gradient(blue 20%, black 0);
}

.grad1 {
  height:100px;
  width:100%;
  background:linear-gradient(-130deg, orange 0%, black 0),
  linear-gradient(blue 20%, black 0);
}
<div class="grad1">

</div>
<div class="grad">

</div>

请指导我通过css在单个div中实现这样的背景

【问题讨论】:

  • @TemaniAfif,请您提供的解决方案对我没有用。请从重复中删除它并帮助我
  • 你确定吗?你检查了右翼的所有相关链接?你在谷歌上做了更多的搜索? ...您应该自己尝试一些事情,然后在您遇到问题的地方返回您的代码。我给你的链接是一个好的开始。如果您还使用“倾斜背景 div”进行搜索,您将获得越来越多的代码。
  • 这里是另一个副本:stackoverflow.com/questions/25958315/…
  • 是的,我确定我试过了,但无法达到我想要的效果

标签: css background linear-gradients


【解决方案1】:

你可以试试这样的:

.header {
  height:200px;
  background:
    /*Top part*/
    linear-gradient(#000,#000) top/100% 50%,
    /*Bottom part*/
    linear-gradient(to top right,transparent 49%,#000 50.5%) bottom center/100px 50%,
    linear-gradient(#000,#000) bottom right/calc(50% - 50px) 50%;
   background-repeat:no-repeat;
}
<div class="header">

</div>

为了更好的可视化,改变渐变的颜色来查看不同的形状:

.header {
  height:200px;
  background:
    /*Top part*/
   linear-gradient(blue,blue) top/100% 50%, /* Fill 100% width and 50% height at the top*/
   /*Bottom part*/
   linear-gradient(to top right,transparent 49%,red 50.5%) bottom center/100px 50%, /*Create a triangle inside a square to have the 45deg at the bottom center*/
   linear-gradient(green,green) bottom right/calc(50% - 50px) 50%; /*Fill half the width minus half the width of the square at the bottom right*/
   background-repeat:no-repeat;
}
<div class="header">

</div>

【讨论】:

  • 我明白你的意思了,我很困惑机制是怎样的,我需要学习这个
  • @NimeshDeo 检查最后一个代码,您将单独看到每个渐变,然后只需调整不同的值即可了解它们的工作原理;)
  • 你能帮我在一个 div 中画出这样的形状吗? imgur.com/bGF9gJH
  • @NimeshDeo 你不想提出问题吗?你想要直接的代码?
  • 当然,我会在一秒钟内创建它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多