到目前为止我有这个代码。但这并没有达到我的预期。我希望整个 ul 块都用 li 的宽度填充。如果你有 3 里,那将是 100/3。如果你有 4 里,那将是 100/4,依此类推。
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script language = "javascript" type="text/javascript">
$(function(){
var width = $("#menu").width();
var res = Math(width / $("#menu li"));
$("#menu li").width()= res;
});
</script>
</head>
<ul id = "menu">
<li><img src="img/mooo.jpg" /></li>
<li><a href ="#">Home</a>
<ul class = "sub1">
<li><a href ="#">News</a></li>
</ul>
</li>
<li><a href ="#">soccer</a>
<ul class = "sub1">
<li><a href ="#">goal</a></li>
<li><a href ="#">ball</a></li>
</ul>
</li>
<li><a href ="#">Contacts</a></li>
</ul>
<div id "main">
<h2> Goal </h2>
</div>