css - 我怎样才能做坡度

标签 css css-shapes

<分区>

如何使用 CSS3 制作这样的坡度? <强> FIDDLE

HTML

<div class="slope">
    Hello
</div>

CSS

.slope{
    width:500px;
    height:100px;
    background:#0093f7;
    text-align:center;
    font-size:26px;
    color:#fff;
    vertical-align:middle;
}

enter image description here

最佳答案

这样就无需知道主 DIV 的宽度。知道高度还是有必要的...

 .slope{
  width:500px;
  height:100px;
  background:#0093f7;
  text-align:center;
  font-size:26px;
  color:#fff;
  vertical-align:middle;
  overflow: visible;
  position: relative;     <--- this is important
}

.slope:after {
  content: "";
  position: absolute;     <--- works with the above, such that positioning is relative to the main DIV
  display: block;
  right: -100px;
  top: 0px;
  width: 0px;
  height: 0px;
  border-top: solid 100px #0093f7;
  border-right: solid 100px transparent;
}

fiddle : https://jsfiddle.net/vh1mk5yx/5/

关于css - 我怎样才能做坡度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31078763/

相关文章:

css - 图像上缩进的透明箭头/三 Angular 形

CSS六 Angular 里,怎么样?

css - IE 6-8 float :left does not seem to work

python - 通过 Flask 运行时 CSS 无法正常工作

html - div高度:100% and display:flex not working in Chrome

html - 给 `<span>` 负垂直边距

css - jquery live() 点击函数 : class not being removed

javascript - CSS/jQuery - 是否可以创建此形状(类似于倒圆)

twitter-bootstrap - 在 Bootstrap 中创建响应式功能区标题

html - 使用 CSS 创建形状后,如何将其中心用作另一个 CSS 形状的焦点?