javascript - 我如何让盒子始终具有相同的宽度

标签 javascript jquery html css

这里我有盒子,它看起来像这样

<div class="dataViewBox">
  <div class="dataViewBox-Download">
    <div class="dataViewBox-DownloadLink">
      <span class="dataViewBox-Hashes"></span>
    </div>

    <div id="testblock0h" class="dataViewBox-HideShowButton" onclick="magicmushrooms('testblock0')">Show</div>

    <div class="dataViewBox-Name">SomeName</div>
  </div>

  <div id="testblock0" class="dataViewBox-BottomBorder">
    <div id="test0" class="dataViewBox-Data toggleable Text">
        <span>this is just a test to show the the box can expand and be alot more bigger then it first was</span>
    </div>
  </div>
</div>


<div class="infoViewExpirein">
  <div id="infoViewExpireinTime">Build this up to be bigger then the box................................</div>
</div>

<div class="dataViewBox">
  <div class="dataViewBox-Download">
    <div class="dataViewBox-DownloadLink">
      <span class="dataViewBox-Hashes"></span>
    </div>

    <div id="testblock1h" class="dataViewBox-HideShowButton" onclick="magicmushrooms('testblock1')">Show</div>

    <div class="dataViewBox-Name">SomeName</div>
  </div>

  <div id="testblock1" class="dataViewBox-BottomBorder">
    <div id="test1" class="dataViewBox-Data toggleable Text">
        <span>See how this box fallows the other one when you open it, and same when you close it, it always has equal width</span>
    </div>
  </div>
</div>


<div class="infoViewExpirein">
  <div id="infoViewExpireinTime">Build this up to be bigger then the box................................</div>
</div>

所有的代码都太多了,无法在这里发布,但我有两个盒子,代码现在可以正常工作,但问题是我不喜欢我解决这个问题的方式,如果你打开一个盒子,你'会看到另一个免费提供且大小相同,这是应该如此的想法。所以页面上的所有元素总是对称的。它只是只有当你在 body 中有“显示:表格”时它才有效。我试图找到另一种方法来实现同样的结果,当你试图在所有东西上获得相等的宽度时它总是很难,但是实现它的 CSS/JavaScript 并不重要

链接:JsFiddle

/斯拉克塔恩

最佳答案

您需要做的就是向您想要限制大小的任何元素添加一个 max-width 参数。

body {
   ...
   display: block;
   max-width: 450px;
}

关于javascript - 我如何让盒子始终具有相同的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23403782/

相关文章:

javascript - 将图像放在 google maps API 标记中的图像上

javascript - 处理二维数组中的 json 响应

javascript - 如何使文本字段中的所有内容都是大写字母/大写字母?

javascript - PHP:条件 'if link is clicked' 则页面不刷新

javascript - 为什么不能使用 JavaScript 改变 CSS 动画的速度

html - 立即播放 HTML5 音频而不等待整个缓冲完成?

javascript - 使用显示模式将 ES6 类属性设为私有(private)

javascript - ES6 类 : Wrap method implementation in another function

jquery - fadeIn 和 fadeOut 在无限循环中

javascript - Ajax 有 5% 的时间失败,响应为 "error"