html - 将 div 调整为 div %

标签 html css

我的问题是我正在尝试制作响应式模板。我现在正在制作标题。

首先,我将在此处发布一段代码,让您了解一下。

<div id="header_box">
  <div class="box">
  Content of box / Img
  </div>
  <div class="box">
  Content of box / Img
  </div>
  <div class="box">
  Content of box / Img
  </div>
</div>

“header_box”的宽度为 100%,“box”的宽度为 40%。

这意味着因为有 3 个“盒子”,它会变成 120%,有没有办法让“盒子”宽度自动调整大小,大约 30%,如果我添加另一个“盒子”,它会变成 20% ,或类似的东西?

谢谢。

最佳答案

首先你的 ID 应该是唯一的,所以在你给出的例子中你最好使用类来代替(即 class="box")

您可以在 CSS 中使用 flex 和 inline-flex 来根据屏幕宽度调整 DIV 的大小。我在这里附上了一个基本示例:http://jsfiddle.net/18e3cxd1/

.box {
    display:inline-flex;
    width:30%;
    border:solid 1px red;
}

此链接为使用 flexbox 提供了一些非常好的指导:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

关于html - 将 div 调整为 div %,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30280841/

相关文章:

html - 突出显示内容可编辑输入中的 div 元素,就好像它是文本一样

javascript - 无法使用 jQuery 更改主体上的 'animation-duration' CSS

html - 如何在css中设置动画?

html - 当我之间有空间时,如何让 div 在悬停时保持可见?

javascript - 在 Windows 8 平板电脑上处理虚拟键盘

html - 没有初始 src 的图像不显示 css 背景图像 : url ("image.png");

css - 单个博客文章的 WordPress 样式

javascript - 根据当前连接的 HTTP 或 HTTPS

html - Link_to 方法不适用于 CSS

javascript - 如何在wordpress小部件中将表格宽度设置为父div宽度