Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
977 views
in Technique[技术] by (71.8m points)

html - How can I create div with a pointed top with CSS

I've see a lot of threads remotely related that basically suggest CSS triangles in the ::after or ::before pseudos, but none have really panned out. I'm throwing this out to see if anyone has any ideas.

I'm looking to create a div with a pointed or pitched top that still maintains a uniform border and box-shadow with the rest of the div.

See link for an image of what I'm trying to create:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you dont want to use a image you could do something like this. But working with an image is lot easier in this case.

body {
    background-color: #CCC;
}

.wrapper {
    
}

.outer {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 205px 32px 205px;
    border-color: transparent transparent #ffffff transparent;
    position: absolute;
}

.inner {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 200px 32px 200px;
    border-color: transparent transparent #ea2225 transparent;
    margin-left: -200px;
    margin-top: 5px;
    position: absolute;
}

.fix {
    background-color: #FFF;
    height: 10px;
    width: 410px;
    position: absolute;
    margin-top: 32px;
}

.red {
    width: 396px;
    height: 300px;
    background-color: #ea2225;
    margin-top: 37px;
    position: absolute;
    border-left: 7px solid #FFF;
    border-right: 7px solid #FFF;
    border-bottom: 6px solid #FFF;
-webkit-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
-moz-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
}
<div class="wrapper">
     <div class="fix"></div>
<div class="outer">
   
  <div class="inner"> 
    
  </div>
    
</div>
  
</div>
   <div class="red"></div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...