html - Accordion HTML + CSS

标签 html css

尝试练习使用 HTML 和 CSS 创建 Accordion 。

下面是代码和 jsfiddle 链接。

我的问题是,当你点击“关于”时,如何让“Hoho”向左移动。我想如果我添加更多选项卡,它们各自的内容将出现在它们的正下方。我怎样才能让所有内容从左边开始显示?

提前致谢!

https://jsfiddle.net/g2r7jLe0/

HTML

<ul>
  <li>
    <a href="#link">Home</a>
    <p id="link">Shopify’s Theme Design Team recently released a pretty sweet template for Shopify Merchants called Venture. The layout is optimized for the best shopping experience and provides clear focus on the products. While the layout was developed to accommodate several business cases, for this tutorial example we will focus on the core of the layout and recreate it with flexbox. In the following steps, we’ll learn how to center align elements, set perfect sticky footers, provide priority to certain products dependent on viewport and device, target flexbox elements with media queries, and learn the basics about Flexbox so you can start implementing flexbox layouts in your next web project.Shopify’s Theme Design Team recently released a pretty sweet template for Shopify Merchants called Venture. The layout is optimized for the best shopping experience and provides clear focus on the products. While the layout was developed to accommodate several business cases, for this tutorial example we will focus on the core of the layout and recreate it with flexbox. In the following steps, we’ll learn how to center align elements, set perfect sticky footers, provide priority to certain products dependent on viewport and device, target flexbox elements with media queries, and learn the basics about Flexbox so you can start implementing flexbox layouts in your next web project.
    Shopify’s Theme Design Team recently released a pretty sweet template for Shopify Merchants called Venture. The layout is optimized for the best shopping experience and provides clear focus on the products. While the layout was developed to accommodate several business cases, for this tutorial example we will focus on the core of the layout and recreate it with flexbox. In the following steps, we’ll learn how to center align elements, set perfect sticky footers, provide priority to certain products dependent on viewport and device, target flexbox elements with media queries, and learn the basics about Flexbox so you can start implementing flexbox layouts in your next web project.Shopify’s Theme Design Team recently released a pretty sweet template for Shopify Merchants called Venture. The layout is optimized for the best shopping experience and provides clear focus on the products. While the layout was developed to accommodate several business cases, for this tutorial example we will focus on the core of the layout and recreate it with flexbox. In the following steps, we’ll learn how to center align elements, set perfect sticky footers, provide priority to certain products dependent on viewport and device, target flexbox elements with media queries, and learn the basics about Flexbox so you can start implementing flexbox layouts in your next web project.</p>
  </li>
  <li>
    <a href="#link2">About</a>
    <p id="link2">Hoho</p>
  </li>
</ul>

CSS

body, html {
  width: 100%;
  height: 100%;
}

ul {
  list-style-type: none;
  width: 100%;
  height: 100%;
  border: 1px solid black;
  padding: 0;
  display: block;
}

li {
  display: inline-block;
}

p {
  position: absolute;
  opacity: 0;
  transition: all 2s;
  width: 100%;
  padding: 0;
}

li p:target {
  opacity: 1;
}

最佳答案

您确实将内容放入了列表项(li)。所以你的内容会从它们的parents(item)左边的位置开始。

但是,您的段落元素(p) 具有绝对位置,您可以设置绝对左侧位置。

p {
  position: absolute;
  left: 10px; /* set left position to 10px */
  opacity: 0;
  transition: all 2s;
  width: 100%;
  padding: 0;
}

Fiddle

关于html - Accordion HTML + CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35121453/

相关文章:

html - 如何使按钮在滚动时固定在底部

html - 如何为外部div内的div提供自动宽度?

jquery - 循环图像

Jquery,获取元素在溢出内的位置:hidden

html - 如何使用纯 CSS 交换表格单元格

css - Fullcalendar 的 fc-highlight 不适用于自定义日历中的日期更改

html - 如何将嵌入的图像放在文本 block 的宽度内

javascript - 对特定列数据应用条件 - jquery DataTable

css - 在移动设备和 iPad 上使用 Bootstrap 导航栏

javascript - 覆盖 CSS 样式