按钮后添加箭头内容的问题

Beh*_*ini 0 css css3

你能看一下这个演示,让我知道为什么我无法在按钮后添加箭头内容

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css');
.btn-warning:after{
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  margin-top: -13px;
  border-left: 0;
  border-bottom: 13px solid transparent;
  border-top: 13px solid transparent;
  border-left: 10px solid #5A55A3;
}
Run Code Online (Sandbox Code Playgroud)
   <div class="container">
<button class="btn btn-warning">Button With Arraow out<br /> This is Test</button>
</div>
Run Code Online (Sandbox Code Playgroud)

sho*_*dev 6

箭头就在页面右侧(注意水平滚动条).它绝对相对于文档定位,left:100%并将其放置在页面的右边缘.您似乎希望箭头相对于按钮元素本身绝对定位.

绝对定位将元素"放置在相对于其最近位置的祖先或包含块的指定位置".(参见绝对位置@ MDN.)因此按钮本身需要"定位".

在我的示例中,下面,我已添加position:relative到按钮元素,以便它成为"定位的祖先".

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css');

.btn-warning {
  position: relative;
}

.btn-warning:after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  margin-top: -13px;
  border-left: 0;
  border-bottom: 13px solid transparent;
  border-top: 13px solid transparent;
  border-left: 10px solid #5A55A3;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
  <button class="btn btn-warning">Button With Arraow out<br />This is Test</button>
</div>
Run Code Online (Sandbox Code Playgroud)