设置<li>
标签的宽度不起作用。宽度根据<li>
标记的内容而变化,以下是html代码
不使用display:block / table / inline-block;
<!DOCTYPE html>
<html>
<head>
<style>
.menu {
padding: 0px;
}
.menu li {
display: inline;
}
.menu li {
background-color: black;
color: red;
padding: 10px 50px 0px 0px;
border-radius: 4px 4px 0 0;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul class="menu">
<li>Java Script</li>
<li>Java Script CSS</li>
</ul>
<ul class="menu">
<li style="width:80%">Script</li>
<li>width changed based on content </li>
</ul>
</body>
</html>
&#13;
如何将它作为li标签的固定长度?
这是上面代码的工作jsfiddle ... Above working code
答案 0 :(得分:0)
试试这个
<!DOCTYPE html>
<html>
<head>
<style>
ul {
width: 100%;
}
ul li {
display: table-cell;
width: auto;
text-align: center;
background-color: black;
color: red;
padding: 10px 50px 0px 0px;
border-radius: 4px 4px 0 0;
}
</style>
</head>
<body>
<h2>Horizontal List</h2>
<ul id="menu">
<li>Java Script</li>
<li>Java Script CSS</li>
</ul>
<ul id="menu">
<li style="width:80%">Script</li>
<li>width changed based on content </li>
</ul>
</body>
</html>