可以在 CSS 中设置条件,以检查ul
的宽度是否大于X px,并应用不同的样式,或者是否有必要 js ?
谢谢!
答案 0 :(得分:0)
以下代码可以为您提供帮助
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css" media="screen">
body{font-family: helvetica;}
ul{margin: 0;padding: 0;}
</style>
</head>
<body>
<div class="wrapper">
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo hic, quis quasi consequatur laudantium voluptatibus. Illo soluta quam eum dolore esse inventore accusamus, amet ipsum at numquam, blanditiis enim! Ad!</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo hic, quis quasi consequatur laudantium voluptatibus. Illo soluta quam eum dolore esse inventore accusamus, amet ipsum at numquam, blanditiis enim! Ad!</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo hic, quis quasi consequatur laudantium voluptatibus. Illo soluta quam eum dolore esse inventore accusamus, amet ipsum at numquam, blanditiis enim! Ad!</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo hic, quis quasi consequatur laudantium voluptatibus. Illo soluta quam eum dolore esse inventore accusamus, amet ipsum at numquam, blanditiis enim! Ad!</li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.js"></script>
<script>
var ulwidth = $('ul').width();
console.log(ulwidth);
if (ulwidth > 500) {
alert('Width is greater than 500');
}
else {
alert('Width is less than 500');
}
</script>
</body>
</html>
这将帮助您加载页面。