Vertically centering content of :before/:after pseudo-elements

前端 未结 6 1219
闹比i
闹比i 2020-11-29 17:51

I\'m trying to achieve something similar to this picture:

\"enter

I have an im

6条回答
  •  佛祖请我去吃肉
    2020-11-29 18:36

    Here is a way of creating next and previous controls, using :before and :after pseudo-elements. Along with border trick to create triangles for previous/next buttons. It does not give you an area 100% of height to click, but if you make the triangle (arrows) a big enough size it should make up for that.

    div {
      position: relative;
      width: 800px;
      max-width: 80%;
      border: 1px solid red;
      text-align: center;
      margin: 0 auto;
    }
    
    div:before, div:after {
      opacity: 0.5;
      display:block;
      content: "";
      position:absolute;
      width: 0; 
      height: 0;
      }
    
    div:before {
      top: 40%; left: 0;
      border-top: 25px solid transparent; 
      border-right: 50px solid blue; 
      border-bottom: 25px solid transparent;
    }
    
    div:after {
      top: 40%; right: 0;
      border-top: 25px solid transparent; 
      border-left: 50px solid blue; 
      border-bottom: 25px solid transparent;
    }
    

    Here is the code working: http://jsfiddle.net/fiddleriddler/rPPMf/

提交回复
热议问题