在CSS中使用倾斜边缘加下划线

时间:2015-12-02 17:13:17

标签: html css html5 css3

如何在CSS中使用倾斜边缘加下划线,如下图所示?

enter image description here

感谢您提供任何帮助。

2 个答案:

答案 0 :(得分:3)

你的意思是http://jsfiddle.net/060Lgxk8/吗?

h1 {
  font-size: 24px;
  text-transform: uppercase;
  font-weight: bold;
  font-family: Arial;
  display: inline-block;
  padding: 0 5px 3px 0;
  border-bottom: 3px solid #000;
  margin: 0;
  position: relative;
}
h1:after {
  content: "";
  width: 15px;
  height: 3px;
  display: block;
  background-color: #000;
  position: absolute;
  right: -13px;
  bottom: 1px;
  transform: rotate(-35deg);
}

尝试阅读此代码,以便了解其工作原理。不过,这很简单。

答案 1 :(得分:1)

您可以将:pseudo元素与borderskewx一起使用



* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
ul {
  margin: 15px;
}
ul li {
  display: inline-block;
  padding: 10px;
  margin: 5px;
  position: relative;
  text-align: center;
  font-size: 18px;
}
ul li:before {
  content: '';
  width: 100%;
  height: 12px;
  border-width: 2px;
  border-style: solid;
  border-color: transparent black black transparent;
  position: absolute;
  bottom: 0;
  left: 0;
  transform: skewX(-25deg);
}

<ul>
  <li>Home</li>
  <li>Contact</li>
</ul>
&#13;
&#13;
&#13;