CSS:防止2个元素破坏和重叠

时间:2017-05-19 08:22:51

标签: css css3 flexbox

我需要在IE10浏览器中完成这项工作。我认为IE10不支持Display flex。 我的要求是.line2和.line3

function contains {
    local string substring
    string=$1
    substring=$2
    [[ ${string#*$substring} != ${string} ]]
    return $?
}

if contains abc b; then echo ok; else echo KO; fi

if ! contains xyz c; then echo ok; else echo KO; fi

contains abc b && echo success
contains abc b || echo failed

应该始终在同一行。我试过使用display float。但我无法完成要求。当屏幕宽度减小而不是必须显示水平滚动条时,不应该发生中断。

下面是笔 codepen link

2 个答案:

答案 0 :(得分:1)

提及@ divine,您可以使用补间语法display: -ms-flexbox;

这篇关于CSSTricks的文章解释了它:Using Flexbox

.page-wrap {
  display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;      /* TWEENER - IE 10 */
  display: -webkit-flex;     /* NEW - Chrome */
  display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
 }

然后,控制col宽度:

.main-content {
  width: 60%;
}
.main-nav,
.main-sidebar {
  -webkit-box-flex: 1;      /* OLD - iOS 6-, Safari 3.1-6 */
  -moz-box-flex: 1;         /* OLD - Firefox 19- */
  width: 20%;               /* For old syntax, otherwise collapses. */
  -webkit-flex: 1;          /* Chrome */
  -ms-flex: 1;              /* IE 10 */
  flex: 1;                  /* NEW, Spec - Opera 12.1, Firefox 20+ */
}

答案 1 :(得分:1)

对于IE10,您可以尝试使用display: -ms-flexbox;但如果不起作用而不是width: 500px; .line2.line3尝试使用百分比。 在这种情况下,给他们两个width: 50%;。请参阅下面的代码示例:

.header {
  background-color: red;
}

.line1 {
  background-color: blue;
}

.line2 {
  background-color: orange;
  float: left;
  width: 50%;
}

.line3 {
  background-color: violet;
  float: left;
  width: 50%;
}

.footer {
  clear: both;
  background-color: green;
}
<div class="container">
  <div class="header">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
  </div>
  <div class="line1">
    It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.
  </div>
  <div class="line2">
    There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum,
    you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary
    of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
  </div>
  <div class="line3">
    The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions
    from the 1914 translation by H. Rackham.
  </div>
  <div class="footer">
    If you use this site regularly and would like to help keep the site on the Internet, please consider donating a small sum to help pay for the hosting and bandwidth bill. There is no minimum donation, any sum is appreciated - click here to donate using
    PayPal. Thank you for your support.
  </div>
</div>

希望这有帮助!