If the src load fails or is not given, the browser will automatically img add a border.
Like this:
Products feel the impact of beautiful, must pass off.
The original code is this:
. ctn{PositionRelative;Width2.8rem;Height2.8rem;Border-radius:3px;OverflowHidden;Background#FFF;}. ctn. title{PositionAbsolute;Top0;Width2.8rem;Height2.8rem;BackgroundRgba0,0,0,.35);Color#FFF;Font-size:.52rem;Font-weight:Bold;Padding0.4rem;}. ctnImg{Width2.6remheight: 2.2remmargin: . 3rem autoobject-fit:coverbackground: url ( Images/120x120.jpg? 201608012) no-repeat center background-size: 2.2rem;}
<Div class="CTN"><Div class=< Span class= "hljs-string" > "title Sn-flex Center" > <p> Leisure suit </p> </div> <img src= "/></div>
Baidu, on the understanding of the solution found on the link in this https://www.zhihu.com/question/27426689
Based on the principles that can be used to css implement js , the following solutions are selected:
To img pack adiv
<Div class="CTN"><Div class="Title Sn-flex Center"><P> Waist Collection</p></div> <div class= "img-ctn" > <img< Span class= "OT" > src=< Span class= "hljs-string" > "temp/app_200x200.jpg" /> < Span class= "Hljs-tag" ></div></DIV>
. ctn. img-ctn{Width2.6rem;Height2.2rem;Margin.3remAuto;OverflowHidden;}. ctn. img-ctnImg{Width-webkit-calc (2.6rem +2PX);Height-webkit-calc (2.2rem +2PX);WidthCalc2.6rem +2PX)height: calc (2.2rem + 2px) background: url ( Images/120x120.jpg? 201608012) no-repeat center background-size: 1.8remmargin: -1px object-fit:cover /span>
But, there is a problem, no picture when the top and bottom border is hidden, about no matter how can not hide, temporarily did not find out the problem, so changed to this:
. ctn. img-ctn{Width2.6rem;Height2.2rem;Margin.3remAuto;OverflowHidden;BackgroundURL (images/120x120. jpg?201608012)No-repeatCenter;Background-size:1.8rem;}. ctn. img-ctnimg{width: inheritheight: inheritobject-fit:cover;} /* no src hidden */.ctn .img-ctn img[src=" ]{< Span class= "Hljs-attribute" >visibility: hidden;}
Later, in the console debugging, suddenly an epiphany,fuck, is reset the style of the problem.
Originally, Base.css
Yes img , I did this.
img { max-width: 100%;}
hehe, and changed it again:
. ctn. img-ctn{Width2.6rem;Height2.2rem;Margin.3remAuto;OverflowHidden;}. ctn. img-ctnImg{Width-webkit-calc (2.6rem +2PX);Height-webkit-calc (2.2rem +2PX);WidthCalc2.6rem +2PX);HeightCalc2.2rem +2PX)background: url ( Images/120x120.jpg? 201608012) no-repeat center background-size: 1.8remmargin: -1px /* is this goods */max-width: span class= "DT" >noneobject-fit:cover /span>
OK, submitted to the development, finally can be lazy for a while.
However, the change came too fast. The development sent a picture:
To debug on the development machine, instantly felt a deep malicious.
The background layer of the original picture is transparent, the rendering level of the box model is color>src>background-image>background-color that the blank area of the picture shows the background image naturally.
img{ background: red url(images/120X120.jpg?201608012) no-repeat center;}
<img src=".png">
I feel that my own power has run out ....
At the end, in order to avoid the appearance of this image, directly do not give the background image, directly through the template engine to judge it
<img src="{$src||‘images/120X120.png‘}"
IH5 the img tag src does not give the path will appear border ———— once two pen coding experience