javascript - 具有可扩展图像背景的列表

标签 javascript jquery html css html-lists

我是 html 和 css 的新开发者,我在尝试使用背景图像来适应列表所具有的元素数量并更改其相对于列表项的高度时遇到问题。 我在这里分享一个例子,想法是将列表设置在“菜单”下方,然后 图像的其余部分更改遵循列表中的元素。 谢谢。

<ul>
  <img src="https://st.depositphotos.com/1695098/1207/i/950/depositphotos_12070017-stock-photo-menu-background.jpg">
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

最佳答案

您的 html 标记无效,ul 只能包含 li 元素作为直接子元素。

然后为了实现你想要的,你需要在 ul 中设置 background-image

ul {
  background-image: url(https://st.depositphotos.com/1695098/1207/i/950/depositphotos_12070017-stock-photo-menu-background.jpg)
}
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

关于javascript - 具有可扩展图像背景的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49131856/

相关文章:

html - 为什么 div 不延伸到元素填充?

javascript - 我似乎无法让 Bootstrap Carousel 在本地工作,但它可以在 codepen 上工作

javascript - 使用输入时未终止的 JSX 内容

javascript - 为什么我的 javascript 函数不按写入方式交换 pi id html 内容?

javascript - 当gridview设置为true时jqgrid在IE9中显示 'Loading'

javascript - 加载新站点时关闭选项卡

javascript - 仅使用 javascript 而不是 jquery 循环浏览 div 内容的上一个和下一个按钮

javascript - 将资源文件中的值与 KO 可观察值连接起来

php - 在 PHP 中使用服务器代理的 HTTP POST 请求

javascript - 使用 jQuery 反转日期的显示