【问题标题】:Glossy Image with CSS带有 CSS 的光泽图像
【发布时间】:2014-11-26 01:09:56
【问题描述】:

我要申请this code:

/* Glossy overlay */

html {
  min-height: 100%;
  background: linear-gradient(#000, #445);
}
figure {
  width: 162px;
  height: 162px;
  margin: 24px auto;
  position: relative;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
  border-radius: 5px;
}
figure img {
  display: block;
  border-radius: 5px;
}
figure:after {
  position: absolute;
  pointer-events: none;
  content: '';
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
  background-image: linear-gradient(-45deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, 0) 50%);
  -webkit-mask-image: linear-gradient(#000, transparent);
  mask: url(http://daneden.me/labs/albums/images/mask.svg#mask);
}
<figure>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</figure>

但我不想将其应用于 div 元素,我想将其应用于每张照片(通过 a img 我该怎么做?

【问题讨论】:

  • 图像不接受伪元素,因此您需要将每个图像包装在 div/figure 中并将伪元素应用于该元素。
  • 把&lt;figure&gt;改成&lt;a&gt;,然后把CSS改成a { }/a img { }/a:after { }
  • 我假设在你的css中用a替换figure对于anchor中的每个img都会达到相同的效果

标签: html css image


【解决方案1】:

我想在每张照片上应用它(通过a img)

如果每个图像都在 &lt;a&gt; 内,您只需将 CSS 更改为目标 a、a img 和 a:after。确保&lt;a&gt; 是display: block 或display: inline-block;

示例

/* Glossy overlay */

html {
  min-height: 100%;
  background: linear-gradient(#000, #445);
}
a {
  display: inline-block;
  width: 162px;
  height: 162px;
  position: relative;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
  border-radius: 5px;
}
a img {
  display: block;
  border-radius: 5px;
}
a:after {
  position: absolute;
  pointer-events: none;
  content: '';
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
  background-image: linear-gradient(-45deg, rgba(255, 255, 255, .4), rgba(255, 255, 255, .2) 50%, rgba(255, 255, 255, 0) 50%);
  -webkit-mask-image: linear-gradient(#000, transparent);
  mask: url(http://daneden.me/labs/albums/images/mask.svg#mask);
}
<a>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>
<a>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>

<a>
  <img src="http://lorempixel.com/output/animals-q-c-162-162-10.jpg">
</a>

【讨论】:

猜你喜欢
  • 2018-02-08
  • 1970-01-01
  • 2019-01-31
  • 2014-03-22
  • 2012-01-02
  • 2016-03-31
  • 2011-11-04
  • 2021-02-07
  • 1970-01-01
相关资源
最近更新 更多