Create a complex CSS shape (speaking bubble)

2019-04-10 12:58发布

问题:

What would be your best option or method to create a shape as seen in the attachment link full CSS and is that possible anyway??

I did research and testing with CSS parallelogram e.g. but not with any good succes yet.

See the shape here -->> http://tinypic.com/r/352ge3b/6

回答1:

I had this thing that it could be done with just one element - and it can be done, I just don't think it's exactly the best solution to do it like this.

DEMO

HTML:

<div class='speech-bubble'>Hello!</div>

CSS:

.speech-bubble {
  position: relative;
  margin: .5em auto;
  padding: 1em;
  width: 10em; height: 4em;
  border-radius: .25em;
  transform: rotate(-4deg) rotateY(15deg);
  background: #629bdd;
  font: 2em/4 Century Gothic, Verdana, sans-serif;
  text-align: center;
}
.speech-bubble:before, .speech-bubble:after {
  position: absolute;
  z-index: -1;
  content: '';
}
.speech-bubble:after {
  top: 0; right: 0; bottom: 0; left: 0;
  border-radius: inherit;
  transform: rotate(2deg) translate(.35em, -.15em) scale(1.02);
  background: #f4fbfe;
}
.speech-bubble:before {
  border: solid 0 transparent;
  border-right: solid 3.5em #f4fbfe;
  border-bottom: solid .25em #629bdd;
  bottom: .25em; left: 1.25em;
  width: 0; height: 1em;
  transform: rotate(45deg) skewX(75deg);
}


回答2:

Not exactly, what you're looking for, but I was playing around with CSS3's perspective and rotate and made this:

body {
    color: #FFF;
    font-family: sans-serif;
}

.outer {
    position: relative;
    height: 120px;
    width: 120px;
    margin: 50px;
    padding:10px;
    perspective:150;
    -webkit-perspective:150;
}

.inner {
    border-radius: 15px;
    padding:50px;
    position: absolute;
    background-color: #80BFFF;
    transform: rotateY(10deg);
    -webkit-transform: rotateY(10deg);
    box-shadow: -4px -4px 0px #3399FF;
}

.inner:after {
    content: ' ';
    position: absolute;
    width: 0;
    height: 0;
    left: 20px;
    top: 115px;
    border: 15px solid;
    border-color: #80BFFF transparent transparent #80BFFF;
}

That's my HTML stuff

<div class="outer">
    <div class="inner">Yay!</div>
</div>