html - 使用网格使每个 <li> 占用相同数量的浏览器宽度

标签 html css

无论窗口的宽度如何,如何让这个 ul 占据网页的整个宽度?

http://jsfiddle.net/32hp1w5p/

ul {
  grid-column: 1/13;
  list-style-type: none;
  display: table;
  margin: 0 auto;
}

li {
  float: left;
  border: 1px solid red;
}

li a {
  font-family: 'Montserrat', sans-serif;
  font-size: 20px;
  color: black;
  text-align: center;
  padding: 14px 14px;
  text-decoration: none;
  display: inline-block;
}
<ul>
  <li><a>ONE</a></li>
  <li><a>TWO</a></li>
  <li><a>THREE</a></li>
</ul>

在这个 jsfiddle 中有三个 li。我希望在这种情况下每个 li 占总宽度的 33%,并且它们一起填满 Web 浏览器窗口的整个宽度

最佳答案

除了错误的显示选择之外,你打错了字并添加了边距(使元素缩小并居中):

有很多错误和错误的方法......欢迎体验 CSS 的乐趣,添加了一些评论。

body {
  /* added the parent grid CSS system */
  display: grid;
  grid-template-columns: repeat(13, 1fr);
}

ul {
  grid-column: 1 / span 13;
  /* span is: the typo / missing */
  list-style-type: none;
  display: flex;
  /* lets make it a flexbox, 
  a grid will do too , 
  so would a table at width:100% 
  if table-layout is set to fixed 
  and li displayed as table-cell */
  margin: 0;/* none or 0, but not auto */
  padding: 0;/* might be usefull here ;) */
}

li {
  flex: 1;
  /* share evenly avalaible space */
  border: 1px solid red;
}

li a {
  font-family: 'Montserrat', sans-serif;
  font-size: 20px;
  color: black;
  text-align: center;
  padding: 14px 14px;
  text-decoration: none;
  display: /*inline-*/block;/* to fill parent's width */
}
<ul>
  <li><a>ONE</a></li>
  <li><a>TWO</a></li>
  <li><a>THREE</a></li>
</ul>

关于html - 使用网格使每个 <li> 占用相同数量的浏览器宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47189859/

相关文章:

html - 具有操作 =""的表单

html - CSS float 问题,在 IE 中有效,在 Chrome/FF 中无效。我可能做错了什么

html - 聊天框总是在底部

css 问题 w/ie 8 及以下

html - 正方形 500x500 像素图像的所有边都有大约 125 像素的透明背景。有什么方法可以使用 CSS 裁剪它吗?

javascript - 类型错误 : Failed to execute 'play' on 'HTMLMediaElement' : Illegal invocation

javascript - 从另一个页面调用 Javascript 函数?

html - CSS::after with::selection?

jquery - 按钮上的标签剥离效果

html - 具有滚动中心的类似框架的行为