html - 使用 CSS 创建多边形按钮

标签 html css

<分区>

enter image description here

我希望只用 css 创建上面的按钮 但是,按钮文本我无法向上移动与按钮对齐。 有什么想法吗?

body {
  padding: 100px;
}

a {
  border-top: 50px solid red !important;
  border-left: 25px solid transparent !important;
  border-right: 25px solid transparent !important;
  height: 0;
  width: 150px;
  font-size: 14px;
  letter-spacing: 1px;
  color: #000;
  text-transform: uppercase;
  text-decoration: none;
}
<a href="#">Read More</a>

https://codepen.io/w3nta1/pen/aRMEzK

最佳答案

那是因为边框在顶部。 这是一个工作示例:

body { padding:100px; }
a { 
    width: 200px;
	font-size: 14px; 
	letter-spacing: 1px; 
	color:#000; 
	text-transform: uppercase;
    text-decoration:none;
    position: relative;
    display: flex;
    align-items: center;
}

a:before {
  content: "";
  border-top: 50px solid red !important;
  border-left: 25px solid transparent !important;
  border-right: 25px solid transparent !important;
  width: 150px;
  position:absolute;
}

span {
  z-index: 10;
  margin: 0 auto;
  position: relative;
  display: table;
  color: white;
}
<a href="#"><span>Read More</span></a>

关于html - 使用 CSS 创建多边形按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53028690/

上一篇:css - 是否可以在切换关闭时更改转换速度?

下一篇:html - 如何创建响应式按钮?

相关文章:

html - 导航菜单的悬停文本颜色不起作用

css - 在 bootstrap 下拉菜单中添加平滑过渡

javascript - Bootstrap 视频超大屏幕

html - 修复了导致网页滚动滞后的背景附件

javascript - 表单不会显示结果

html - 如何以编程方式模拟禁用 chrome 样式面板中的背景颜色?

JQuery 脚本可能是语法错误

Javascript - 附加行相关的下拉列表

javascript - 使用 PHP 网络爬虫查找没有特定元素的特定单词

css - 文本奇怪的蓝色下划线?