【问题标题】:CSS3 - divs one on each other, borders, trianglesCSS3 - 一个彼此的 div,边框,三角形
【发布时间】:2013-11-07 14:14:26
【问题描述】:

我在尝试这样做时遇到了麻烦:

我设法做到了这样的事情:

display: table-cell;
vertical-align: middle;

background: rgb(245,245,245); /* Old browsers */
background: -moz-linear-gradient(top, rgba(245,245,245,1) 0%, rgba(230,230,230,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(245,245,245,1)), color-stop(100%,rgba(230,230,230,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(245,245,245,1) 0%,rgba(230,230,230,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f5f5', endColorstr='#e6e6e6',GradientType=0 ); /* IE6-9 */

用于文本的主容器,并且:

width: 0;
height: 0;
border-top: 25px solid transparent;
border-bottom: 25px solid transparent;
border-left: 40px solid #FEEDDD;
display: inline-block;

做三角形。然后,我会将带有数字的圆圈放在其中的绝对位置。

但不知道如何让三角形“边框”像其他 div 一样渐变,也不给它一个白色的外边框...

先谢谢了!

【问题讨论】:

  • 试试这个链接,css3shapes.com 你可能需要使用一些 :before 和 :after 伪类来完成你想要的
  • 非常好的网站,谢谢,但据我所知,它使用了与我在其他地方看到的相同的技术,所以我想很难实现我想要做的事情(或者只是我'我没有足够的技能来管理它......)

标签: css border gradient


【解决方案1】:

绝对有可能。

不久前我创建了一个带有渐变箭头的后退按钮。见this fiddle 因此,只需更改方向、颜色并将其调整为您想要的大小,但我猜您已经明白了。

HTML:

<button>Rejoignez le groupe</button>

CSS:

button {
  position: relative;
  display: inline-block;
  border: 1px solid #555555;
  margin: 0;
  font-size: 12px;
  color: inherit;
  cursor: pointer;
  height: 30px;
  padding: 0 10px;
  margin-right: 10px;
  font-weight: bold;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #eeeeee), color-stop(100%, #888888));
  background: -webkit-linear-gradient(top, #eeeeee, #888888);
  background: -moz-linear-gradient(top, #eeeeee, #888888);
  background: -o-linear-gradient(top, #eeeeee, #888888);
  background: linear-gradient(top, #eeeeee, #888888);
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  -ms-border-radius: 4px;
  -o-border-radius: 4px;
  border-radius: 4px;
  text-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
  -webkit-box-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
  -moz-box-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
  box-shadow: rgba(255, 255, 255, 0.5) 0 1px 0;
}

button:after {
  clip: rect(14px, 14px, 28px, 1px);
  -webkit-transform: skewX(-35deg);
  -moz-transform: skewX(-35deg);
  -ms-transform: skewX(-35deg);
  -o-transform: skewX(-35deg);
  transform: skewX(-35deg);
  content: "";
  top: 0;
  position: absolute;
  height: 100%;
  width: 8%;
  right: -10px;
  border-right: inherit;
  background: inherit;
  -webkit-box-shadow: inherit;
  -moz-box-shadow: inherit;
  box-shadow: inherit;
}

button:before{
  clip: rect(1px, 14px, 14px, 1px);
  background: red;
  -webkit-transform: skewX(35deg);
  -moz-transform: skewX(35deg);
  -ms-transform: skewX(35deg);
  -o-transform: skewX(35deg);
  transform: skewX(35deg);
  content: "";
  top: 0;
  position: absolute;
  height: 100%;
  width: 8%;
  right: -10px;
  border-right: inherit;
  background: inherit;
  -webkit-box-shadow: inherit;
  -moz-box-shadow: inherit;
  box-shadow: inherit;
}

如果它太令人困惑,需要一些指导来改变方向、大小和颜色,请告诉我。

【讨论】:

  • 我更新了 css、html 和 fiddle,使它们具有正确的方向,并且文本是您屏幕截图中的文本
  • 我在这方面工作(我喜欢理解事物:))并设法做到了这一点:jsfiddle.net/DRNpT 太好了!我将设置白色圆圈绝对,以便它显示它需要的位置。我不明白的是,您如何使用它来获得我需要的结果:第一个 div 已完成,但是您如何将其设置为“在”他的邻居中,所以他的灰色出现在三角形的上下?
  • 看起来不错,干得好!要处理邻居问题,需要小 CSS 更改的最简单方法是使用留给邻居的边距,div 将彼此重叠。 z-index 将按照正确的顺序设置它们。像这样:jsfiddle.net/DRNpT/1
【解决方案2】:

虽然您可能可以设法做类似的事情,并且仍然在浏览器范围内保持不错的后备并取得成功的结果……我希望您在尝试时会拔出一大块头发。我的建议是在 Photoshop 中制作一些背景图片,然后将这些项目分成三个不同的元素

  1. 一个透明白色圆圈的元素,可以包含 步骤#

  2. 一个带有类的元素,用于完成应用橙色渐变背景的步骤

  3. 另一个具有单独灰度渐变类的元素

通过这种方式,您可以让所有元素保持“方形”,而不必担心对三角形或圆形元素的支持。并在适当的地方覆盖你的文字......

我知道这可能不是您所要求的 css3 方式来完成所有事情,但我相信以这种方式做事可以让您保持简单和精简

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    相关资源
    最近更新 更多