如何使我的删除按钮响应并在我的缩略图上保持绝对

时间:2014-08-04 20:33:22

标签: html css image button responsive-design

我有一个应用程序,用户可以上传图像并通过单击缩略图右上角的按钮将其删除,如下所示

图片(1)

enter image description here

但是,目前我的按钮看起来像这样

图片(2)

enter image description here

我希望我的按钮不会位于图片旁边,如图(2)所示,但是看起来像图片(1)并保持这种状态,即使我改变了窗口的大小。

我目前的css

 @media (max-width: 768px) {
  .delete {
    cursor: pointer !important; 
   font-size: 30px;
   position: absolute;
   color: white;
   border: none;
   background: none;
   right: 18px;
   top: -9px;
   line-height: 1;
  }
  .delete span {
    height: 30px;
    width:30px;
    background-color: black;
    border-radius: 50%;
    display: block;
  }
 }

 .model-thumbs img {
   margin-left: auto;
   margin-right: auto;
   cursor: pointer;
   box-shadow: 0 0 5px 2px rgba(0,0,0,.15);
 }

我当前的HTML

<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 model-thumbs" ng-repeat="model in models track by $index" ng-animate="'animate'">
 <button type="button" class="delete" ng-click="deleteModel(model)">
      <span>&times;</span>
      <span class="sr-only">Delete</span>
 </button>

 <img ng-click="selectModel(model)" src="{{model.thumbSrc}}" class="img-responsive" data-toggle="modal" data-target="#detailModal">
</div>

正如您目前所看到的,我正在尝试使用@media标签,但是当我调整窗口大小时,它会从图片(2)移动到下面的图片

enter image description here

到图片(1)中的流动,意味着它不会保持在缩略图的右上角。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Demo ... Source

HTML

<div class="box">
    <button type="button" class="delete" ng-click="deleteModel(model)">
        <span>&times;</span>
    </button>
    <div class="image">
        <img ng-click="selectModel(model)" src="http://nemo-crack.org/uploads/posts/2014-04/1398165049_adobe-410x400.png" />
    </div>
</div>

CSS

.delete {
    cursor: pointer !important;
    font-size: 30px;
    position: absolute;
    color: white;
    border: none;
    background: none;
    right: -15px;
    top: -15px;
    line-height: 1;
    z-index: 99;
    padding: 0;
}
.delete span {
    height: 30px;
    width: 30px;
    background-color: black;
    border-radius: 50%;
    display: block;
}

.box{
    width: calc((100% - 30px) * 0.333);
    margin: 5px;
    height: 250px;
    background: #CCCCCC;
    float: left;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 0 5px 2px rgba(0,0,0,.15);
}

.box:hover{
    box-shadow: 0 0 15px 3px rgba(0, 0, 0, 0.5);
}

.box .image{
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.box .image img{
    width: 100%;
    min-height: 100%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    -ms-transform: translate(-50%,-50%);
    -webkit-transform: translate(-50%,-50%);
}

@media (max-width: 600px) {
    .box{
        width: calc((100% - 20px) * 0.5);
        height: 200px;
    }
}

希望这会对你有帮助..