图片的左上角显示 【推荐】、【热销】标签的效果,使用Css 如何实现呢?

图片描述

请问使用纯Css 如何实现这一效果呢(如上图中图片的左上角)?
注: 图片的border-radius:5px;
非常感谢!

阅读 9.2k
2 个回答

一般使用绝对定位来解决

    <div class="parent">
        <span class="text">推荐</span>
        <div class="triangle-topleft">
        </div>
    </div>

   .parent{
        position: relative;
        width: 200px;
        height: 200px;
    }
    .parent .text{
        display: inline-block;
        transform: rotate(-45deg);
        padding: 20px;
        color: #fff;
    }
   .triangle-topleft{
        width: 0;
        height: 0;
        border-top: 100px solid red;
        border-right: 100px solid transparent;
        position: absolute;
        top: 0;
        z-index: -1;
    }
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<style type="text/css">
     .main_img{ display: block;
  width: 90%;
  height: 4.954em;
  position: relative;
  overflow: hidden;
  margin-left: 0.742em;
  margin-top: 0.8em;
}
.main_img .new{
    width: 3.25em;
  height: 3.25em;
  position: absolute;
  top: 0;
  left: 0;
  background-size: 3.25em 3.25em;
  background: url(http://m.lobo666.com/Public/image/main/new.png) no-repeat center;
}
</style>
<div class="main_img">
         <!--  <a href="/index.php/Home/Detail/index/id/364.html"> -->
         <a href="/index.php/Home/Detail/index/id/364/aid/100004.html">
            <img src="http://lobo.lobo666.com/Uploads/Building/61772d6d46.jpg">
               
          </a>
          <!--                    <div></div>   -->
                  <div class="new"></div>           
        </div>
</body>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题