:之后没有按预期工作 - CSS

时间:2015-05-20 06:49:22

标签: html css

以下是我想要的按钮

enter image description here

JSFIddle

HTML

<div>
    <h5 style="margin: 0;position: relative;" class="right-arrow">LEARN MORE</h5>
</div>

CSS

div {
    background-color: red;
    border-radius: 10px;
    padding: 0.5em;
    float: left;
    position: relative;
}

.right-arrow:after {
    content: '';
    content: '';
    vertical-align: middle;
    border: 20px solid transparent;
    border-left-color: white;
    border-width: 8px 20px;
    position: absolute;
    padding-left: 10px;
}

问题

不知道为什么右箭头在外面......

我不想要的可能解决方案

我不希望我的div修正宽度!!因此需要float: left; div。欢迎其他解决方案。感谢

4 个答案:

答案 0 :(得分:1)

试试这样:

div {
background-color: red;
border-radius: 10px;
padding: 0.5em 30px .5em .5em; /* added right padding */
float: left;
position: relative;
}

.right-arrow:after {
  content: '';
  content: '';
  vertical-align: middle;
  border: 20px solid transparent;
  border-left-color: white;
  border-width: 8px 15px;
  position: absolute;
  margin-left: 8px; /* newly added */
}

您需要为背景div设置正确的填充,如 demo

答案 1 :(得分:0)

进行以下 css 更改

http://jsfiddle.net/vasanthanvas/x4knsgcj/

.right-arrow{padding:0 25px 0 0 }
.right-arrow:after {
content: '';
  vertical-align: middle;
  border: 20px solid transparent;
  border-left-color: white;
  border-width: 8px 15px;
  position: absolute;
  padding-left: 10px;
  right: -27px;
}

答案 2 :(得分:0)

试试这个

.right-arrow:after {
 content: '';
 vertical-align: middle;
 border: 1px solid transparent;
 border-left-color: white;
 border-width: 8px 0 8px 10px;
 margin-left: 10px;
 display:inline-block;
}

答案 3 :(得分:0)

你可以试试这个

fiddle

div {
    background-color: red;
    border-radius: 10px;
    padding: 0.5em 1.5em 0.5em 0.5em;
    float: left;
    position: relative;
}

.right-arrow:after {
  /* content: ''; */
  content: '';
  vertical-align: middle;
  border: 0 solid transparent;
  border-left-color: white;
  border-width: 8px 0 8px 16px;
  position: absolute;
  /* padding-left: 10px; */
  right: -20px;
  top: 0;
}