在div下浮动文本

时间:2016-08-22 09:59:15

标签: html css flexbox

您好我有这段代码:

.wrapper {
  width: 100%;
  border: 3px solid black;
  display: flex;
}
.myText {
  width: 50%;
  background-color: yellow;
}
.box {
  width: 50%;
  height: 50px;
  background-color: orange;
}
<div class="wrapper">
  <div class="myText">
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
    sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
    Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </div>
  <div class="box"></div>
</div>

我的目标是,黄色框内的文字浮在橙色框下面(如果它在例子中太长了。这样的东西:

enter image description here

我不知道如何做到这一点,我没有在互联网上找到任何解决方案。有任何想法吗?感谢

3 个答案:

答案 0 :(得分:2)

尝试将.box置于顶部,float: right;

.wrapper {
  border: 3px solid black;
  text-align: justify;
}
.myText {
  background-color: yellow;
}
.box {
  width: 50%;
  height: 50px;
  background-color: orange;
  float: right;
}
<div class="wrapper">
  <div class="box"></div>
  <div class="myText">
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
    sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
    Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </div>
</div>

答案 1 :(得分:1)

.wrapper {
  width: 100%;
  border: 3px solid black;
  display: flex;
}
.myText {
  background-color: yellow;
  text-align: justify;
}
.box {
  background-color: orange;
  float: right;
  height: 60px;
  width: 50%;
}
<div class="wrapper">
  <div class="myText">
    <div class="box"></div>
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
    
    sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
    Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </div>
  
</div>

答案 2 :(得分:0)

我能想到的最简单的解决方案是你把橙色的盒子放在黄色的盒子里并且在写任何文字之前。像这样的东西

<div class="myText">
  <div class="box"></div>
     Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
  </div>

您还必须在CSS中进行更改。使用box class添加这个属性。

float:right;