html - CSS 自定义标签形状 - 额外的行

标签 html css

请引用此链接。 https://codepen.io/wbeeftink/pen/dIaDH .如果你缩小或放大,你会看到标签底部有一条额外的线伸出来。请引用屏幕截图。 enter image description here

enter image description here

谁能告诉我如何解决这个问题。或者是否有不同的方法来创建此类标签? 这是我使用的代码

HTML

<span class="tag">HTML</span>

CSS

.tag {
  background: #eee;
  border-radius: 3px 0 0 3px;
  color: #999;
  display: inline-block;
  height: 26px;
  line-height: 26px;
  padding: 0 20px 0 23px;
  position: relative;
  margin: 0 10px 10px 0;
  text-decoration: none;
  -webkit-transition: color 0.2s;
}

.tag::before {
  background: #fff;
  border-radius: 10px;
  box-shadow: inset 0 1px rgba(0, 0, 0, 0.25);
  content: '';
  height: 6px;
  left: 10px;
  position: absolute;
  width: 6px;
  top: 10px;
}

.tag::after {
  background: #fff;
  border-bottom: 13px solid transparent;
  border-left: 10px solid #eee;
  border-top: 13px solid transparent;
  content: '';
  position: absolute;
  right: 0;
  top: 0;
}

最佳答案

.tag::after 的样式从 right: 0 更改为 left: 100%

body {
  font: 12px/1.5 'PT Sans', serif;
  margin: 25px;
}

.tags {
  list-style: none;
  margin: 0;
  overflow: hidden; 
  padding: 0;
}

.tags li {
  float: left; 
}

.tag {
  background: #eee;
  border-radius: 3px 0 0 3px;
  color: #999;
  display: inline-block;
  height: 26px;
  line-height: 26px;
  padding: 0 20px 0 23px;
  position: relative;
  margin: 0 10px 10px 0;
  text-decoration: none;
  -webkit-transition: color 0.2s;
}

.tag::before {
  background: #fff;
  border-radius: 10px;
  box-shadow: inset 0 1px rgba(0, 0, 0, 0.25);
  content: '';
  height: 6px;
  left: 10px;
  position: absolute;
  width: 6px;
  top: 10px;
}

.tag::after {
  background: #fff;
  border-bottom: 13px solid transparent;
  border-left: 10px solid #eee;
  border-top: 13px solid transparent;
  content: '';
  position: absolute;
  left: 100%;
  top: 0;
}

.tag:hover {
  background-color: crimson;
  color: white;
}

.tag:hover::after {
   border-left-color: crimson; 
}
<h1>Tags</h1>

<h2>Example 1</h2>
<a href="#" class="tag">Front-end development</a>

<h2>Example 2</h2>
<ul class="tags">
  <li><a href="#" class="tag">HTML</a></li>
  <li><a href="#" class="tag">CSS</a></li>
  <li><a href="#" class="tag">JavaScript</a></li>
</ul>

关于html - CSS 自定义标签形状 - 额外的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38181146/

相关文章:

php - 表单在导航菜单内提交

javascript - 调整 div 大小以填充 100% 的屏幕而不制作滚动条

javascript - 使用 jquery animate 时停止换行

css - 为什么在父项上应用 CSS-Filter 会破坏子项定位?

css - 在 CSS 中有多个媒体查询是不是很好,因为这种浏览器渲染会受到影响?

javascript - 如何允许网页安全地修改用户的 svg 文件?

javascript - 使用数组创建多项选择测验

html - 内联 block 内的绝对 div,相对父 div 占用兄弟的宽度

html - 最重要的可用性、可访问性和 SEO 指南是什么?

html - 添加类开始于动态创建的单选按钮