美文网首页JavaScript
无高度li,背景图片自适应的解决方法

无高度li,背景图片自适应的解决方法

作者: LuckyS007 | 来源:发表于2017-04-21 18:24 被阅读422次

1...如果是纯图片展示img设置width:100%;height:auto;

1...如果是纯图片展示img设置width:100%;height:auto;
<li class="one">
<img src = '', >
</li>


2...如果作为背景,在父元素上设置position: relative;background-size:100% auto,高度由padding-top设置百分比撑开,然后子元素通过绝对定位来承载其它内容
>```
<li class='two'>
</li>
----------------------------
li {
  float: left;
  width: 20%;
  padding: 7% 0;
~~~
  font-size: 10px;
  font-weight: bolder;
  color: #a9a9a9;
  border-right: 1px solid #cacaca;
  box-sizing: border-box;
  cursor: pointer;
  position: relative;
  background-size: 100% auto;
~~~
}
li:after{
  display: block;
  content: ".";
~~~
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background: url('/images/APPicon/tab/fa_icon.png') center center no-repeat;
  background-size: 100% 100%;
~~~
}
tab

相关文章

网友评论

    本文标题:无高度li,背景图片自适应的解决方法

    本文链接:https://www.haomeiwen.com/subject/nouhzttx.html