i cant get a shape with polygon transform

梦想的初衷 提交于 2020-05-15 19:42:08

问题


I have a problem making a shape for a li, I need it to have a diagonal line and a smooth border, but I can't get it. This its what i got for now.

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  list-style-position: inside;
  display:flex;
}
li {
  position: relative;
  height: 40px;
  width: 300px;
  margin: 10px;
  padding-right: 30px;
  line-height: 40px;
  text-align: right;
  text-transform: uppercase;
  border-radius: 8px;
  background: crimson;
  color: white;
  -webkit-clip-path: polygon(0% 0%, 0% 50%, 10% 100%, 100% 100%, 100% 50%, 90% 0%);
  clip-path: polygon(0% 0%, 0% 50%, 10% 100%, 100% 100%, 100% 50%, 90% 0%);
}
<ul>
  <li>Menu Text 1</li>
  <li>Menu Text 2</li>
  <li>Menu Text 3</li>
</ul>

i need something like this

shape


回答1:


You are looking for skew transformation and not clip-path:

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  list-style-position: inside;
  display: flex;
}

li {
  position: relative;
  z-index: 0;
  height: 40px;
  padding:0 20px;
  margin: 10px;
  line-height: 40px;
  text-align: right;
  text-transform: uppercase;
  color: white;
}

li::before {
  content: "";
  position: absolute;
  z-index:-1;
  top: 0;
  left: 50%;
  right: 0;
  bottom: 0;
  transform: skew(-15deg); /* you can try postive value */
  transform-origin:top; /* use bottom with positive value*/
  border-radius: 0 8px 8px 0;
  background: crimson;
}
li::after {
  content: "";
  position: absolute;
  z-index:-1;
  top: 0;
  left: 0;
  right: 50%;
  bottom: 0;
  border-radius: 8px 0 0 8px;
  background: crimson;
}
<ul>
  <li>Menu Text 1</li>
  <li>Menu Text 2</li>
  <li>Menu Text 3</li>
</ul>


来源:https://stackoverflow.com/questions/61376779/i-cant-get-a-shape-with-polygon-transform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!