html设计完后页面比率,html – 在一个页面中填入一个列表并保持项目比率

我不认为只有CSS才有可能. JS解决方案如下所示:

document.addEventListener("DOMContentLoaded", setLiHeight);

window.addEventListener("resize", setLiHeight);

function setLiHeight() {

let ul = document.querySelector("ul");

let lis = ul.querySelectorAll("li");

let title = ul.querySelector("div");

let images = ul.querySelectorAll("img");

// Set height for lis

Array.from(lis, function(li) {

li.style.height = ul.offsetHeight / lis.length - 1 + "px";

});

// Set height for images according to height title

Array.from(images, function(img) {

img.style.height = ul.offsetHeight / lis.length - title.offsetHeight + "px";

});

}

html,

body {

margin: 0;

}

ul {

height: 100vh;

margin: 0;

}

li img {

width: auto;

}

  • title1

    googlelogo_color_272x92dp.png

  • title2

    googlelogo_color_272x92dp.png

  • title3

    googlelogo_color_272x92dp.png

  • title4

    googlelogo_color_272x92dp.png

  • title5

    googlelogo_color_272x92dp.png

  • title6

    googlelogo_color_272x92dp.png

  • title7

    googlelogo_color_272x92dp.png

  • title8

    googlelogo_color_272x92dp.png

这里唯一的假设是列表的高度是固定的.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值