代码之家  ›  专栏  ›  技术社区  ›  Rusletov

使元素与浮动元素的边界相邻

  •  2
  • Rusletov  · 技术社区  · 7 年前

    我想让一个白色指针从右侧浮动的段落中伸出。 以下是我迄今为止取得的成就。这远非完美,因为当我调整屏幕大小时,指针不想粘在边框上。 解决方案是什么?

    #batu {
      float: none;
      clear: both;
        position: relative;
        background: url(https://pp.userapi.com/c836431/v836431507/5a2cd/Zc9FsOzRLdY.jpg) no-repeat;
        max-width: 1170px;
        background-size: cover; /* Never used this before */
    }
    #batu::after {
      content: '';
      display: block;
      float: none;
      clear: both;
      overflow: nidden;
    }
    
    #batu .overlay-content {
        float: right;
        width: 40%;
        height: 100%;
        background-color: rgba(255, 255, 255, 0.8);
        min-height: 517px; /* the height of the background image*/
    }
    
    .pointer {
        position: absolute;
        top: 48%;
        left: 48%;
        width: 10px;
        height: 24px;
        background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
    }
    <div id="batu">
        <div class="pointer"></div>
        <div class="overlay-content">
            <h4>Batu</h4>
            <p>blablablablablablablablablablablabla
            blablablablablablablablablablablablablb
            blablablablablablablablablablablablabla
            blablablablablablablablablablablablablb
            </p>
         </div>
    </div>
    2 回复  |  直到 7 年前
        1
  •  2
  •   kukkuz    7 年前

    如果你能让你的 指针 after overlay-content

    1. 添加 position: relative

    2. psuedo公司 之后

      #batu .overlay-content::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 0;
        transform: translate(-100%, -50%);
        width: 10px;
        height: 24px;
        background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
      }
      

    #batu {
      float: none;
      clear: both;
      position: relative;
      background: url(https://pp.userapi.com/c836431/v836431507/5a2cd/Zc9FsOzRLdY.jpg) no-repeat;
      max-width: 1170px;
      background-size: cover;
      /* Never used this before */
    }
    
    #batu::after {
      content: '';
      display: block;
      float: none;
      clear: both;
      overflow: hidden;
    }
    
    #batu .overlay-content {
      float: right;
      width: 40%;
      height: 100%;
      background-color: rgba(255, 255, 255, 0.8);
      min-height: 517px;
      /* the height of the background image*/
      position: relative;
    }
    
    
    /*
    .pointer {
        position: relative;
        top: 48%;
        left: 48%;
        float: right;
        width: 10px;
        height: 24px;
        background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
    }
    */
    
    #batu .overlay-content::after {
      content: '';
      position: absolute;
      top: 50%;
      left: 0;
      transform: translate(-100%, -50%);
      width: 10px;
      height: 24px;
      background: url(https://s8.hostingkartinok.com/uploads/images/2017/08/96ad387742f9e8fce21c53f42fe45984.png) no-repeat;
    }
    <div id="batu">
      <!--<div class="pointer"></div>-->
      <div class="overlay-content">
        <h4>Batu</h4>
        <p>blablablablablablablablablablablabla blablablablablablablablablablablablablb blablablablablablablablablablablablabla blablablablablablablablablablablablablb
        </p>
      </div>
    </div>
        2
  •  0
  •   the_lorem_ipsum_guy    7 年前

    我修改了你的代码。检查这个 https://jsfiddle.net/osxo2vzL/ 你需要把 word-wrap: break-word;