CSS: How to attach an arrow to a div and make it overlap the border

后端 未结 3 1928
情话喂你
情话喂你 2020-12-31 10:14

I am trying to make a popover with an error, but I am having trouble making the arrow appear above the border of the div I am attaching it to. I would appreciate any help.

相关标签:
3条回答
  • 2020-12-31 10:32

    Easiest way:

    HTML:

    <div class="meow">
    </div>
    

    CSS:

    .meow { 
      height: 100px;
      width: 300px;
      margin: 30px;
      background: linear-gradient(#333, #222);
      -o-border-radius: 4px;
      -ms-border-radius: 4px;
      -moz-border-radius: 4px;
      -webkit-border-radius: 4px;
      border-radius: 4px;
    }
    
    .meow:after {
      content: " ";
      border-top: 11px solid #222;
      border-left: 8px solid transparent;
      border-right: 8px solid transparent;
      position: relative;
      top: 111px;
      right: -140px;
    }
    

    Live preview: CodePen.io

    Just do some few edits.

    0 讨论(0)
  • 2020-12-31 10:41

    CSS solution:

    http://jsfiddle.net/wn7JN/

    .bubble 
    {
    position: relative;
    width: 400px;
    height: 250px;
    padding: 0px;
    background: #FFFFFF;
    border: #000 solid 1px;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    }
    
    .bubble:after 
    {
    content: "";
    position: absolute;
    bottom: -25px;
    left: 175px;
    border-style: solid;
    border-width: 25px 25px 0;
    border-color: #FFFFFF transparent;
    display: block;
    width: 0;
    z-index: 1;
    }
    
    .bubble:before 
    {
    content: "";
    position: absolute;
    top: 250px;
    left: 174px;
    border-style: solid;
    border-width: 26px 26px 0;
    border-color: #000 transparent;
    display: block;
    width: 0;
    z-index: 0;
    }
    
    0 讨论(0)
  • 2020-12-31 10:56

    Try this:

    HTML

    <div class="info-popover">
        <div class="inner"></div>
        <p class="arrow"></p>
    </div>
    

    CSS

    .info-popover {
        position: relative;
        /* any other CSS */
    }
    
    .arrow {
        background: url("/images/dock/popover-arrow.png") no-repeat 0 0;
        height: 15px;
        width: 20px; /* width of arrow image? */
        display: block;
        position: absolute;
        bottom: -15px;
        left: 0; margin: 0 auto; right: 0; /* to center the arrow */
    }
    
    0 讨论(0)
提交回复
热议问题