Clip Path is always overflow:hidden

情到浓时终转凉″ 提交于 2019-12-13 15:30:22

问题


I made this example:

div {
 -webkit-clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%);
 clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%);
 background-color: red;
 width: 150px;
 height: 150px;
 position: relative;
}
ul{
 position: absolute;
 background-color: green;
 left: 30px;
 top: 50px;
}
<div>
 <ul>
   <li>1</li>
   <li>2</li>
   <li>3</li>
   <li>4</li>
   <li>5</li>
   <li>6</li>
   <li>7</li>
   <li>8</li>
   <li>9</li>
   <li>10</li>
  </ul>
</div>

As you can see, there is a list with 10 numbers but due to clip path property, div behaviour is always as overflow: hidden.

How can I make all the <ul> visible?


回答1:


An idea would be to reproduce the same shape using background and avoid the effect of clip-path:

div {
  background:
  linear-gradient(to top left,transparent 50%,red 51%) right/15.5% 100% no-repeat,
  linear-gradient(red,red) left/85% 100% no-repeat;
  width: 150px;
  height: 150px;
  position: relative;
}
ul{
  position: absolute;
  background-color: green;
  left: 30px;
  top: 50px;
}
<div>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
  </ul>
</div>

UPDATE

If you want an image you can try this

div {
  background:
  linear-gradient(to bottom right,transparent 50%,#fff 51%) right/15.5% 100% no-repeat,
  url(https://picsum.photos/2000/1000?image=1069) center/cover no-repeat;
  width: 150px;
  height: 150px;
  position: relative;
}
ul{
  position: absolute;
  background-color: green;
  left: 30px;
  top: 50px;
}
<div>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
  </ul>
</div>



回答2:


You can do it with the :before or :after pseudo-element:

div {position: relative}
div * {margin: 0; box-sizing: border-box}

div:after {
  content: "";
  position: absolute;
  -webkit-clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%);
  clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%);
  background-color: red;
  width: 150px;
  height: 150px;
}

ul {
  position: absolute;
  background-color: green;
  left: 30px;
  top: 50px;
  z-index: 1;
}
<div>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
  </ul>
</div>


来源:https://stackoverflow.com/questions/50497694/clip-path-is-always-overflowhidden

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