添加CSS梯形形状:后按钮 [英] Adding CSS Trapezoid Shape :After Button

查看:292
本文介绍了添加CSS梯形形状:后按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为客户端创建一个按钮样式,似乎不能使用后伪类来工作。

I'm attempting to create a button style for a client, and cannot seem to get it working using the after pseudo-class.

<style>
$varBase: 40px;
$imsblue: #012169;
$imsgrey: #012169;

body {
  background:grey;
}

.btn {
  position: relative;
  float: left;
  height: $varBase;
  font-family: sans-serif;
  text-align: center;
  line-height: $varBase;
  color: white;
  white-space: nowrap;
  text-transform: uppercase;
  background: $imsblue;
  &:before {
    float: left;
    content:"";
    width: ($varBase/4);
    height: ($varBase/2);
  }
  &:after {
    position: absolute;
    content:"";
    height: ($varBase/2);
    border-left: ($varBase/2) solid $imsblue;
    border-bottom: ($varBase/2) solid transparent;
  }
  a {
    color: white;
    text-decoration:none;
    padding: ($varBase/4) ($varBase/2);
    margin-right: -10px;
  }
}
.btn3 {
  display: inline;
  color: white;
  background: linear-gradient(135deg, rgba(1,33,105,1) 0%, rgba(1,33,105,1) 93%, rgba(30, 87, 153, 0) 93%, rgba(30, 87, 153, 0) 100%);
  outline: 0;
  border: 0;
  padding: 10px 0px;
  a {
    color: inherit ;
    text-transform: uppercase;
    text-decoration:none;
    padding: ($varBase/4) $varBase;
  }
}
</style>
<div class="btn"><a href="#">Click to Submit</a></div>
<div class="btn3"><a href="#">Click to Submit</a></div>

我可以使用两个DIV来显示它,但是我只需要一个类。有人可以帮我看看我做错了什么?

I can get it to show using two DIVs, but I need this to work with just one class. Can someone help me see what I'm doing wrong?

它应该看起来像这样(禁止颜色和大小的课程):

It's supposed to look like this (barring color and size of course):

推荐答案

缺少的是你需要在你的:之后伪类中包含 content:请参阅下面的示例。

I believe the key element missing is that you need to include a content:"" in your :after pseudoclass. See the example below.

.btn {
  height: 40px;
  background: red;
  width: 128px;
  float:left;
}

.btn:after {
    width: 0px;
    height: 20px;
    border-left: 20px solid red;
    border-bottom: 20px solid white;
    float:right;
    content:"";
}

<div class="btn">Button</div>

这篇关于添加CSS梯形形状:后按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆