【问题标题】:HTML / CSS - Cross Shape with picture in itHTML / CSS - 带有图片的十字形
【发布时间】:2015-05-06 17:38:48
【问题描述】:

我用 css 创建了一个十字形。现在我想在里面放一张图片,问题是,十字架包含之前:和之后:div,所以不可能在里面放一张图片。

这是我的 jsbin: http://jsbin.com/iYogaCE/1/edit

我怎么能做到这一点?还是有其他解决方案来创建这样的形状?

提前致谢!

【问题讨论】:

  • 您没有在此处为十字形设置背景图像。你只是用 2 条带背景图像的十字形。

标签: html css shape css-shapes


【解决方案1】:

#cross:before, #cross:after中添加background-position:center;

#cross {
   width: 100px;
   height: 100px;
   position: relative;
}

#cross:before, #cross:after {
  content: "";
  position: absolute;
  z-index: -1;
  background-size:100px 100px;
  background-image:url('http://www.gm-consult.de/uploads/pics/homer-simpson_20.jpg');
  background-position:center;
}

#cross:before {
  left: 50%;
  width: 30%;
  margin-left: -15%;
  height: 100%;
  -webkit-transform: rotate(45deg); 
  -moz-transform: rotate(45deg);
}

#cross:after {
  top: 50%;
  height: 30%;
  margin-top: -15%;
  width: 100%;
  -webkit-transform: rotate(45deg); 
  -moz-transform: rotate(45deg);
}

【讨论】:

  • 谢谢,效果很好!现在我得到了另一个令人困惑的部分。我希望背景图片不旋转,当我向 :before, :after (我放置图片的位置)添加旋转时,它不会改变任何东西。问题是我不能改变其他属性的旋转(否则它不会保持交叉)-> jsbin.com/iYogaCE/7/edit
猜你喜欢
  • 2011-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多