【问题标题】:circular crop to circular border on hover悬停时圆形裁剪到圆形边框
【发布时间】:2018-11-28 22:27:36
【问题描述】:

我有一个显示为表格的无序列表。每个列表元素都包含一个图像和一个名称/标题。图像被裁剪成圆形。悬停时,我希望圆形裁剪成为图像周围的圆形边框,这样我们就可以看到脸部周围有一个圆圈的完整图像。我的灵感来自this site

我已成功将图像裁剪为圆形,但我在悬停时遇到了边框问题。 你可以查看我的JSFiddle here

section.team {
  margin: auto;
  background: #FEFEFE;
  display: inline-block;
}

.team-listing {
  position: relative;
  margin-top: 40px;
  margin-right: auto;
  margin-left: auto;
}

.team-listing li {
  display: inline-block;
  width: 300px;
  overflow: hidden;
  float: left;
  height: 340px;
  list-style-position: inside;
  margin: 1px 1px 1px 1px;
  background-color: #fff;
}

.team-listing ul {
  display: table;
  list-style: none;
  filter: drop-shadow(5px 5px 5px rgba(2, 2, 22, 0.1));
  white-space: nowrap;
  width: 80%;
  margin: auto;
}

.circle-image-crop {
  background-color: transparent;
  width: 220px;
  height: 220px;
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 50%;
  margin-left: auto;
  margin-right: auto;
  margin-top: 20px;
}

.circle-image-crop::after {
  position: absolute;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  display: none;
  content: ' ';
  background: -moz-radial-gradient(center, ellipse cover, rgba(190, 232, 114, 0.15) 0%, rgba(66, 147, 33, 1) 100%);
  /* ff3.6+ */
  background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(190, 232, 114, 0.15)), color-stop(100%, rgba(66, 147, 33, 1)));
  /* safari4+,chrome */
  background: -webkit-radial-gradient(center, ellipse cover, rgba(190, 232, 114, 0.15) 0%, rgba(66, 147, 33, 1) 100%);
  /* safari5.1+,chrome10+ */
  background: -o-radial-gradient(center, ellipse cover, rgba(190, 232, 114, 0.15) 0%, rgba(66, 147, 33, 1) 100%);
  /* opera 11.10+ */
  background: -ms-radial-gradient(center, ellipse cover, rgba(190, 232, 114, 0.15) 0%, rgba(66, 147, 33, 1) 100%);
  /* ie10+ */
  background: radial-gradient(ellipse at center, rgba(190, 232, 114, 0.15) 0%, rgba(66, 147, 33, 1) 100%);
  /* w3c */
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#BEE872', endColorstr='#429321', GradientType=1);
  /* ie6-9 */
  border-radius: 50%;
  border: 1px #fff;
  background-color: transparent;
}

.circle-image-crop:hover::after {
  display: block;
}


/* this is where I tried to create the circular border*/

.circle-image-crop:hover {
  border-radius: 50%;
  border: 1px #fff;
  background-color: transparent;
}

.circle-image-crop img {
  display: inline;
  margin: 0 auto;
  height: 100%;
  width: auto;
}
<section class="content-wrapper team">
  <h3>Columbia</h3>
  <div class="team-listing">
    <ul>
      <section class="content-wrapper team">
        <h3>Columbia</h3>
        <div class="team-listing">
          <ul>
            <li>
              <div class="team-member-listing-wrapper">
                <div class="circle-image-crop">
                  <img class="team-member-photo" src="http://api.leafsnap.com/v1/team/images/columbia/Peter.jpg">
                </div>
                Jane Jam
                <br>
                <span class="bio">lead the design and development of early tablet PC, UMPC, and mobile phone prototypes and helped with the initial design of the current iPhone app.</span>
              </div>
            </li>
            <li>
              <div class="team-member-listing-wrapper">
                <div class="circle-image-crop">
                  <img class="team-member-photo" src="http://api.leafsnap.com/v1/team/images/columbia/Peter.jpg">
                </div>
                Jane Jam
                <br>
                <span class="bio">lead the design and development of early tablet PC, UMPC, and mobile phone prototypes and helped with the initial design of the current iPhone app.</span>
              </div>
            </li>
            <li>
              <div class="team-member-listing-wrapper">
                <div class="circle-image-crop">
                  <img class="team-member-photo" src="http://api.leafsnap.com/v1/team/images/columbia/Peter.jpg">
                </div>
                Jane Jam
                <br>
                <span class="bio">lead the design and development of early tablet PC, UMPC, and mobile phone prototypes and helped with the initial design of the current iPhone app.</span>
              </div>
            </li>
            <li>
              <div class="team-member-listing-wrapper">
                <div class="circle-image-crop">
                  <img class="team-member-photo" src="http://api.leafsnap.com/v1/team/images/columbia/Peter.jpg">
                </div>
                Jane Jam
                <br>
                <span class="bio">lead the design and development of early tablet PC, UMPC, and mobile phone prototypes and helped with the initial design of the current iPhone app.</span>
              </div>
            </li>
            <li>
              <div class="team-member-listing-wrapper">
                <div class="circle-image-crop">
                  <img class="team-member-photo" src="http://api.leafsnap.com/v1/team/images/columbia/Peter.jpg">
                </div>
                Jane Jam
                <br>
                <span class="bio">lead the design and development of early tablet PC, UMPC, and mobile phone prototypes and helped with the initial design of the current iPhone app.</span>
              </div>
            </li>
            <li>
              <div class="team-member-listing-wrapper">
                <div class="circle-image-crop">
                  <img class="team-member-photo" src="http://api.leafsnap.com/v1/team/images/columbia/Peter.jpg">
                </div>
                Jane Jam
                <br>
                <span class="bio">lead the design and development of early tablet PC, UMPC, and mobile phone prototypes and helped with the initial design of the current iPhone app.</span>
              </div>
            </li>
          </ul>

        </div>
      </section>

【问题讨论】:

    标签: html css border crop


    【解决方案1】:

    您可以使用 SVG 蒙版来创建初始圆形图像。悬停时,在其上放置一个标准图像。

    对于动画圆环,您也可以使用 SVG。

    jsfiddle

    示例,使用 cmets:

    a {
      display: inline-block;
    }
    
    article {
      position: relative;
      border: 1px solid lightgrey;
      width: 300px;
      height: 350px;
      /* prevent scaled circle ring from triggering hover */
      overflow: hidden;
    }
    
    
    /* create the colour overlay */
    article:after {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      display: none;
      background: -moz-radial-gradient(center, ellipse cover, rgba(0,   255, 255, 0.15) 0%, rgba(0, 255, 255, 1) 100%);
      z-index: 3;
    }
    
    
    /* place full image above SVG */
    .img-full {
      position: absolute;
      top: 0;
      z-index: 2;
      /* hide the full image initially */
      display: none;
    }
    
    .circle-ring {
      position: absolute;
      top: 0;
      z-index: 3;
      /* initially hidden with opacity so it can be animated */
      opacity: 0;
      transform-origin: 50% 50%;
      transform: scale(1.8);
      transition: transform .3s ease, opacity .4s ease;
    }
    
    a:hover .img-full,
    a:hover article:after {
      display: block;
    }
    
    a:hover .circle-ring {
      opacity: 1;
      transform: scale(1);
    }
    
    .text {
      position: absolute;
      bottom: 0;
      padding: 1rem 2rem;
      color: #000;
      /* keep text above SVG, full image and overlay */
      z-index: 4;
    }
    
    a:hover .text {
      color: #FFF;
    }
    
    
    /* general */
    h2,
    h4 {
      margin: 0;
      font-family: sans-serif;
    }
    
    h4 {
      font-weight: 300;
    }
    <a href="#">
      <article>
        <div>
        
          <!-- The masked image -->
          <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100">
    			<defs>
    				<clipPath id="circle">
    					<circle cx="50" cy="50" r="35"/>
    				</clipPath>
    			</defs>
    			<image width="100%" height="100%" preserveAspectRatio="xMinYMin slice" xlink:href="https://source.unsplash.com/Nxy-6QwGMzA/300x350" clip-path="url(#circle)"/>
    		</svg>
        </div>
        
        <!-- The full revealed image -->
        <img class="img-full" src="https://source.unsplash.com/Nxy-6QwGMzA/300x350" alt="">
        
        <!-- The circle ring -->
        <svg viewBox="0 0 100 100" class="circle-ring">
            <circle cx="50" cy="50" r="35" stroke="white" stroke-width=".5" fill="transparent" />
        </svg>
        
        <div class="text">
          <h2>Article Title</h2>
          <h4>Article Subtitle</h4>
        </div>
      </article>
    </a>

    【讨论】:

    • 如果我希望颜色叠加也有渐变(类似于示例),我是否只需将其添加到article:after(类似于background: -moz-radial-gradient(center, ellipse cover, rgba(190, 232, 114, 0.15) 0%, rgba(66, 147, 33, 1) 100%);
    • @Matt 没错,我已经更新了答案以包含渐变
    【解决方案2】:

    http://jsfiddle.net/vemwjp2o/28/

    如果您想从字面上重新创建参考代码,您可以尝试将图像的宽度设置为 300 像素(容器的宽度)并将其绝对定位到左侧。 (See CloudApp Gif)

    .circle-image-crop img{
        display: inline;
        position: absolute;
        margin: 0 auto;
        width: 300px;
        top: -20px;
        left: -40px;
    }
    

    另外,不要忘记将边框样式设置为纯色(或任何您想要的样式);-)

    【讨论】:

      【解决方案3】:

      这是一个使用径向渐变的简单想法:

      .box {
        width:200px;
        height:200px;
        margin:50px;
        border:1px solid;
        background-image:
        radial-gradient(circle at 100px 80px,transparent 38%,#fff 41%),
        url(https://picsum.photos/200/200?image=1069);
        background-size:100% 100%,cover;
        position:relative;
        transition:all 1s;
      }
      /*The border */
      .box:before {
        content:"";
        position:absolute;
        top:16px;
        width:62%;
        height:62%;
        left:50%;
        transform:translateX(-50%);
        border:2px solid #fff;
        border-radius:50%;
      }
      .box:hover {
        background-size:300% 300%,cover;
      }
      <div class="box">
      
      </div>

      这是另一个使用box-shadow 制作不同动画的想法:

      .box {
        width:200px;
        height:200px;
        margin:50px;
        border:1px solid;
        background-image: url(https://picsum.photos/200/200?image=1069);
        position:relative;
        overflow:hidden;
      }
      /*The border */
      .box:before {
        content:"";
        position:absolute;
        top:16px;
        width:62%;
        height:62%;
        left:50%;
        transform:translateX(-50%);
        border:2px solid #fff;
        box-shadow:0px 0px 200px 200px #fff;
        border-radius:50%;
        transition:all 1s;
      }
      .box:hover::before{
        box-shadow:0px 0px 0px 0px #fff;
      }
      <div class="box">
      
      </div>

      【讨论】:

        猜你喜欢
        • 2016-04-27
        • 1970-01-01
        • 2013-10-05
        • 1970-01-01
        • 1970-01-01
        • 2018-07-17
        • 1970-01-01
        • 2021-03-10
        • 2011-09-25
        相关资源
        最近更新 更多