javascript - 在没有 photoshop 的情况下为图像设置样式以使其看起来相同

标签 javascript html css wordpress image

我为标题道歉我不确定如何用一句话解释我想做的事情。我在 WordPress 网站上工作,我需要使一堆图像看起来像本页“整形外科”部分中的背景图像 https://rinklefreeps.wpengine.com/

我可以用 photoshop 浏览并编辑它们,但我觉得如果有一种方法可以将其编码出来,那会好很多,因为如果我需要更改其中任何一个,我需要做的就是把中的图像,它看起来已经正确了。我还需要能够在它们上放置 alt 标签。

所以我想我想说的是我需要重新创建“整形手术”部分,其中包含我可以放置 alt 标签的背景图像。我只是不太确定从哪里开始,任何帮助都会很棒。谢谢大家!

最佳答案

如果你将 img 包裹在一个元素中,你可以使用 ::before/::after 伪类来使用 制作一个半透明的覆盖层rgba() 和一个倾斜的实心叠加层,使用 background-color 定位和 transform: rotate() 来创建倾斜。

* {margin:0;padding:0;box-sizing:border-box;}
.imgContainer {
  width: 50%;
  margin: auto;
  overflow: hidden;
  position: relative;
}

.imgContainer::after, .imgContainer::before {
  content: '';
  position: absolute;
}

.imgContainer::after {
  top: 0; left: 0; bottom: 0; right: 0;
  background: rgba(255,255,255,0.5);
}

.imgContainer::before {
  height: 200%;
  width: 50%;
  background: #fff;
  left: 0;
  transform: translate(-40%,-50%) rotate(15deg);
}

img {
  max-width: 100%;
}

.text {
  position: absolute;
  top: 50%; left: 50%;
  width: 80%; height: 80%;
  transform: translate(-50%,-50%);
  background: rgba(255,255,255,.3);
  z-index: 1;
  padding: .5em;
}
<div class="imgContainer">
  <img src="http://cdn.thedailybeast.com/content/dailybeast/articles/2015/03/31/neil-degrasse-tyson-defends-scientology-and-the-bush-administration-s-science-record/jcr:content/image.img.2000.jpg/1432067001553.cached.jpg" alt="alt">
  <div class="text">
    text text text text text text text text text text text text text text text text text text text text text text text text text text text text 
  </div>
</div>

关于javascript - 在没有 photoshop 的情况下为图像设置样式以使其看起来相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44730452/

相关文章:

html - 内联 block 元素和定位/对齐

javascript - 如何共享 Swagger 文档

html - 与其容器和窗口相关的 div 位置

javascript - Angularjs 与 packery.js 可拖动

html - 将对象置于 2 个 float 对象下方

html - 为什么显示: flex push the following element onto a new line?

javascript - new Date() 中的日期参数错误?

javascript - 使用 javascript 单击时切换类

javascript - 强制 Ajax 获取缓存版本

html - 页脚悬浮在主要内容之上