Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 当父div为百分比时保持图像比率_Html_Css_Image - Fatal编程技术网

Html 当父div为百分比时保持图像比率

Html 当父div为百分比时保持图像比率,html,css,image,Html,Css,Image,我试图让图像跨越屏幕的宽度,同时保持它们的图像比例。基本上,有4个图像需要在屏幕宽度上均匀分布,并且需要同时保持图像比率,图像之间没有空间或填充 我对我所做的努力作了充分的评价 HTML: 我们应该做到这一点。演示:您可以控制HTML吗?第二个(隐藏的)图像的目的是什么?老实说,不要理解什么是错误的。请你澄清一下好吗? <div class="featured-products"> <ul> <li> <p>

我试图让图像跨越屏幕的宽度,同时保持它们的图像比例。基本上,有4个图像需要在屏幕宽度上均匀分布,并且需要同时保持图像比率,图像之间没有空间或填充

我对我所做的努力作了充分的评价

HTML:


我们应该做到这一点。演示:

您可以控制HTML吗?第二个(隐藏的)图像的目的是什么?老实说,不要理解什么是错误的。请你澄清一下好吗?
<div class="featured-products">
  <ul>
    <li>
       <p>
        <img src=" http://placehold.it/320x410" alt="" />
        <img src=" http://placehold.it/320x410" alt="" />
       </p>
   </li>
   <li>
       <p>
        <img src=" http://placehold.it/320x410" alt="" />
        <img src=" http://placehold.it/320x410" alt="" />
       </p>
   </li>
   <li>
       <p>
        <img src=" http://placehold.it/320x410" alt="" />
        <img src=" http://placehold.it/320x410" alt="" />
       </p>
   </li>
   <li>
       <p>
        <img src=" http://placehold.it/320x410" alt="" />
        <img src=" http://placehold.it/320x410" alt="" />
       </p>
   </li>
 </ul>
 </div>
.featured-products {
    width: 100%;
    position: relative;
    font-size: 0;
    display: block;
    ul {
        margin: 0;
        padding: 0;
        width: 100%;
        text-align: center;
        li {
            display: inline-block;
            width: 25%;
            p {
                width: 100%;
                height: auto;
                img:nth-child(1){
                    background-size: cover;
                    max-width: 100%;
                    max-height: 100%;
                }
                img:nth-child(2){
                    display: none;
                }
            }
        }
    }
}
img {
    width:100%;
    height:auto;
}