Make a CSS triangle with transparent background on a div with white bg image?

前端 未结 5 1581
时光说笑
时光说笑 2020-12-10 08:12

Ok so, I\'m trying to replicate the effect you see here at the bottom of the page, with the back to top button: http://www.ppp-templates.de/tilability/ - After the content a

相关标签:
5条回答
  • 2020-12-10 08:53

    You can use vector path. For instance, transparent triangle with green border:

    <svg height="151" width="150">
        <path d="m0 150 h150 l -75 -150 z" fill="transparent" stroke="green" />
    </svg>
    

    See it here.

    0 讨论(0)
  • 2020-12-10 08:56

    Here you go, http://jsfiddle.net/pkUx7/1/

    HTML

    <body>
        <div id = "footer"></div>
        <div id = "bottom-line-left"></div>
        <div id = "triangle"></div>
        <div id = "bottom-line-right"></div>
    </body>
    

    CSS

    body {
        background-color: purple;
    }   
    
    div {
        margin:0;
        padding:0;
        background-color: violet;
    }
    
    #footer {
        height: 100px;
    }
    
    #bottom-line-left, #bottom-line-right {
        display: inline-block;
        height: 20px;
    }
    
    #bottom-line-left {
        width: 61%;
    }
    
    #bottom-line-right {
        float: right;
        width: 37%;
    }
    
    #triangle {
        margin-left:-6px;
        margin-right: -4px;
        padding:0;
        display: inline-block;
        width: 0;
        height: 0;
        border-left: 10px solid transparent;
        border-right: 10px solid transparent;
        border-bottom: 20px solid purple;
    }
    
    0 讨论(0)
  • 2020-12-10 09:04

    The Fiddle:

    http://jsfiddle.net/JaMH9/2/

    The HTML:

    <div class="bar">
        <span class="home">^<br>Home, sweet home!</span>
    </div>​
    

    The CSS:

    .bar {
        position: relative;
        width: 90%;
        height: 30px;
        margin: 0 auto;
    }
    
    .home {
        position: absolute;
        top: 0px;
        left: 60%;
        width: 20%;
        text-align: center;
    }
    
    .bar:before, .bar:after {
        content:'';
        position: absolute;
        top: 0;
        height: 0;
        border-top: 30px solid white;
      -webkit-box-sizing: border-box;
         -moz-box-sizing: border-box;
          -ms-box-sizing: border-box;
              box-sizing: border-box;
    }
    
    .bar:before {
        left: 0;
        width: 70%;
        border-right: 30px solid transparent;
    }
    
    .bar:after {
        right:0;
        width: 30%;
        border-left: 30px solid transparent;
    }
    ​
    
    0 讨论(0)
  • 2020-12-10 09:08

    Here's one way to make a triangle with fairly minimal markup and css:

    HTML:

    <div class="triangle"></div>
    

    CSS:

    .triangle {
        width: 0; 
        height: 0; 
        border-left: 35px solid transparent;
        border-right: 35px solid transparent;
        border-bottom: 35px solid gray;
    }
    

    http://jsbin.com/iribib/21

    0 讨论(0)
  • 2020-12-10 09:08

    I just threw this together, there's probably a better way to achieve this effect.

    HTML

    <div class="div1">Lorem Ipsum</div>
    <div class="div2"></div>
    <div class="div3"></div>
    <div class="div4"></div>
    

    CSS

    body {
        background-color: gray;
        border: 20px solid gray;
    }
    .div1 {
        background-color: white;
        border: 20px solid white;
    }
    .div2 {
        float: right;
        border-top: 20px solid white;
        border-right: 20px solid white;
        border-left: 20px solid transparent;
    }
    .div3 {
        float: right;
        margin: 10px -20px;
        border-bottom: 20px solid white;
        border-right: 20px solid transparent;
        border-left: 20px solid transparent;
    }
    .div4 {
        border-top: 20px solid white;
        border-right: 20px solid transparent;
        margin-right: 40px;
    }
    

    See it here.

    0 讨论(0)
提交回复
热议问题