我想创建一个div可以随着窗口宽度的变化而改变宽度/高度的东西.
是否有任何CSS3规则允许高度根据宽度改变,同时保持其宽高比?
我知道我可以通过JavaScript实现这一点,但我更喜欢只使用CSS.
带有列表标签的网格列,我需要每3列以正确的顺序显示,并为每个额外的HTML列表元素启用自动宽度.
这是我的例子:
 <style>
        ul {
            margin: 0;
            padding: 0;
            display: -webkit-flex;
            display: flex;
            -webkit-flex-wrap: wrap;
            -ms-flex-wrap: wrap;
            flex-wrap: wrap;
            -webkit-flex-direction: column;
            -ms-flex-direction: column;
            flex-direction: column;
            height: 150px;
            width:auto;
        }
    
        li {
            float: left;
            display: inline-block;
            list-style: none;
            position: relative;
            height: 50px;
            width: 50px;
        }
    </style><ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
    <li>10</li>
    <li>11</li>
    <li>12</li>
    </ul>display: -webkit-flex;.
我想像这样转换输出:
1 4 7 10
2 5 8 11
3 6 9 12
重要的是我到目前为止我的Safari浏览器工作,我似乎无法解决这个问题,我会适当的任何帮助:)
测试链接:
我正在尝试使用flexbox进行简单的设计,但我遇到了IE11的问题.基本上,我想要一个仅在内容不够高时才能粘在底部的页脚.我这样做对Chrome没有任何问题:
*,
*:after,
*:before {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  display: flex;
  flex-direction: column;
}
main {
  flex: 1;
}<header>
  Header
</header>
<main>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
  <p>Main</p>
</main>
<footer>
  Footer
</footer>只需<p>main</p>使用IE11来查看错误行为的数量即可.
有没有办法在没有JavaScript的情况下实现这一目标?
我想在flexbox中有一个方形div.所以我使用:
.outer {
  display: flex;
  width: 100%;
  background: blue;
}
.inner {
  width: 50%;
  background: yellow;
  padding-bottom: 50%;
}<div class="outer">
  <div class="inner">
    <a>hehe</a>
  </div>
</div>这在Chrome中运行良好.但在Firefox中,父母只挤到一行.
我如何在Firefox中解决这个问题?我使用的是44版.
I'm having trouble with <div> heights in IE (specifically IE11). Works fine in Chrome.
So I'm essentially loading in processed PHP results with jQuery.html() and in IE my page wrap doesn't seem to fit the fill length of the page. I believe I've narrowed this down to:
<main id="place_results_wrap">
The height of that seems to shrink as soon as the following section and contents within are loaded in with jQuery.html().
<section class="place_results">
As part of the jQuery load, I'm using …
我的网站在IE11中完全破碎了.问题来自于flex: 1 1 0%;,由于autoprefixer和postcss-flexbugs-fixes我到处使用.
当我将其flex: 1 1 auto;更改为时,该网站确实可以在IE上运行,但随后某些行为也会发生变化(例如,一个带有两个flex: 1 1 auto;孩子的弹性箱不会占用完全相同的空间).因此,这个解决方案在其他浏览器上破坏了我的设计(虽然在IE11上使它更好 - 而不是破坏).
人们如何设法使用Flexbox构建自己的网站在IE11上运行?
编辑:这是一支笔,突出了我面临的问题:https://codepen.io/Zephir77167/pen/GMjBrd(在Chrome和IE11上试试).
Edit2:这是代码:
HTML:
<div id="a" class="flex">
  <div id="b" class="item flex-1">
    Hey
  </div>
  <div id="c" class="item flex-0">
    Ho
  </div>
  <div id="d" class="item flex-1">
    Heyheyheyheyho
  </div>
</div>
<br />
<div id="a" class="flex">
  <div id="b" class="item flex-1-variation">
    Hey
  </div>
  <div id="c" class="item flex-0">
    Ho
  </div>
  <div id="d" class="item flex-1-variation">
    Heyheyheyheyho
  </div>
</div>
CSS:
* { …下面的小提琴有三个街区.
块1包含三列.中间列中有两行,每行设置为flex:1.
块2包含三列.中间列中有两行,每行设置为flex:1.第二行包含一张狗的图像.图像不会缩小到包含它的行的高度.
块3仅包含中间列,其中包含两行,每列设置为flex:1.第二行包含一张狗的图像.图像会缩小到包含它的行的高度.
问题是为什么第2块中间栏第二行的图像没有缩小到包含它的行的高度?我可以添加什么CSS规则来实现这一目标?
.block{
    height:100px;
}
.wrapper{
    border:5px solid purple;
    display:flex;
    flex-direction:row;
}
.column{
    flex:1;
    border:3px solid yellow;
}
.middle{
    display:flex;
    flex-direction:column;
}
.first{
    background:red;
}
.second{
    background:orange;
}
.third{
    background:purple;
}
.row{
    flex:1;
    border:1px solid black;
    display:flex;
    align-items:stretch;
}
img{
    flex:1;
}<div class="wrapper block">
<div class="left column"></div>
<div class="middle column">
  <div class="row first"></div>
  <div class="row second"></div>
      	
</div>
<div class="right column"></div>
</div>
<div class="wrapper block">
<div class="left column"></div>
<div class="middle column">
  <div class="row first"></div> …我正在使用flexbox创建一个简单而优雅的基于Flexbox的响应式布局.这是HTML示例:
<div class="box">
  <section class="box concise">
    <div class="box">
      this is just for test
    </div>
  </section>
  <!-- I can add more sections here,
      to serve as "cards", for example -->
</div>
以下是款式:
.box {
  display: flex;
  flex-wrap: wrap;
}
.box>* {
  flex-basis: 0;
  flex-grow: 1;
  max-width: 100%;
}
.box>.concise {
  flex-basis: auto;
  flex-grow: 0;
}
flex-basis: 0; flex-grow: 1; max-width: 100%;我的样式表的目的是默认在所有flex子项上,这样每个flex子项只会增长内容所需的数量,但仍然填充宽度,如果需要包装.它工作得很好.
可选项flex-basis: auto; flex-grow: 0;是使flex子项像以前一样根据需要增长,但不会比这更大,主要是围绕内容收缩包装flex项目.
<section>除非需要,我将用它来区分不会增长的"卡片".
section {
  background-color: white;
  border: 1px solid black;
}
这在Firefox和Chrome上看起来很漂亮.但它完全打破了Microsoft Edge …
我flex-basis: 0%;遇到的问题以及当用户减小窗口的宽度时IE11如何处理它。可能与box-sizing的错误有关。
我有可变数量的flex-children,每个孩子的宽度都未知。每个孩子都有任意动态生成的内容。但是,其中某些内容必须具有包装文字的功能。
伸缩式容器本身必须具有100%的宽度,并且必须能够包装其子级(即flex-wrap: wrap)。
假设存在三个flex-children,最后一个需要文本包装:
<div class="flex-container">
  <div class="flex-child">
    <div>This text should not overlay other flex-children.</div>
  </div>
  <div class="flex-child">
    <div>This text should not overlay other flex-children.</div>
  </div>
  <div class="flex-child">
    <div class="text-break">This text should break on new lines when the container shrinks down</div>
  </div>
</div>
CSS可以定义如下:
.flex-container {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}
.flex-child {
  flex-grow: 1;
  flex-shrink: 0;
  flex-basis: 0%;
  white-space: nowrap;
  padding: 5px;
}
.text-break {
  white-space: pre-wrap;
}
当窗口足够宽时,每个flex-child应该并排放置,并且文本不会折叠: …
使用或样式规则时,具有特定display类型的容器元素内的图像的行为有所不同。img { width: 0; }img { width: 0%; }
width增加使用除给出相同预期结果之外的任何单位 的值(仅占据显示的部分)。%img
我尝试更改display容器img所在的类型。结果如下所示。
显示不符合预期的容器display类型:img
不确定它们之间的关系,可能我错过了一些东西。
button:first-of-type img {
  width: 0;
}
button:last-of-type img {
  width: 0%;
}<h3>The image width: 0 (hides it)</h3>
<button>
      <img src="https://picsum.photos/id/1012/200/100">
      <p>Add playlist</p>
</button>
<h3>The image width: 0% (occupies the space (natural img width) and …在mdn
flex:1与...相同
flex-grow:1。但是,实际上它在浏览器中有不同的显示。
您可以通过更改CSS中的注释在jsFiddle中进行尝试。
当我使用flex: 1元素时,其类test-container名将是,height:100%但使用时不会发生flex-grow: 1。
我不明白为什么。寻求帮助。非常感谢。
.flex-1 {
  display: flex;
  flex-direction: column;
  height: 500px;
  background: red;
}
.child-1 {
  height: 50px;
  background: blue;
}
.child-2 {
  flex-grow: 1;
  /* flex:1; */
  background: green;
}
.test-container {
  display: flex;
  flex-direction: row;
  background: white;
  height: 100%;
}<div class="flex-1">
  <div class="child-1"></div>
  <div class="child-2">
    <div class="test-container"></div>
  </div>
</div>我有一个相当独特的情况,它似乎适用于除Internet Explorer 11之外的所有浏览器,因此这是我试图解决的主要用例。
我工作的一个想法,对于涉及利用网站布局display: flex;上<body>,以适应各种各样的布局情况。具体来说,一个是在一侧有一个“导航栏”,在左侧有一个站点的内容。flex-grow: 1;在内容上使用允许我填充导航栏后面的剩余空间,以及当我必须在某个断点隐藏导航栏时自动填充浏览器窗口的整个宽度。
但是,如果我将 a 添加max-width到内容并尝试使用 将其在剩余空间内居中margin: 0 auto;,它会在Internet Explorer 11 中失败。
/* Code to Troubleshoot
// ----------------- */
body {
  display: -webkit-flex;
  display: flex;
}
nav {
  -webkit-flex-basis: 160px;
  flex-basis: 160px;
  z-index: 2;
}
main {
  -webkit-flex: 1;
  flex: 1;
  position: relative;
  min-width: 1px;
  max-width: 400px;
  margin: 0 auto;
  z-index: 1;
}
/* Presentational Styles
// ------------------ */
* {
  box-sizing: …我有两个div:
min-height和flex-grow: 1当我减少窗口出现滚动时,然后在chrome中一切都正确显示.但在IE11中,顶部div减少到一行,其文本位于底部div的顶部.
我可以修复它只为顶部div的内容设置一些宽度(它适用于固定宽度,或钙宽度,但无法使用百分比宽度)如何在不设置宽度或宽度百分比(width:100%)的情况下修复它?
body,
html {
  height: 99%;
  padding: 0;
  margin: 0;
}
.flexcontainer {
  width: 25%;
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid lime;
}
.allspace {
  flex-grow: 1;
  min-height: 300px;
  background-color: yellow;
}
.longtext {
  background-color: red;
}
.textcontainer {
  border: 1px solid magenta;
  /*IE work correctly only when specified width. by example: width:calc(25vw - 2px);*/
}<div class="flexcontainer">
  <div class="longtext">
    section 1 with long name section …