Search code examples
htmlcsslayoutcss-float

Floater container goes under floater img


Trying to make a brick-like layout. It worked at fist, but now it seeps i can either place an image (and the box will render under) or the box (and the image will render under) wrong place

code:

* {
    -moz-box-sizing: border-box;
    -webkkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
  background: white;
  color: black;
  font-family: verdana;
  font-size: 14;
  }
  
center {
  text-align: center;
  }

.containerinvis {
  width: 1150px;
  margin: auto;
  margin-top: 40px;
  margin-bottom: 20px;  
  position: relative;
  }

.filenamebar {
 background-color: #FFCDD9;
 padding: 5px;
 border:solid 2px #EAA2B3
}
 
.filename {
vertical-align: middle;
color: #341D22;
text-size: 12;
float:left;
}

.windowedclosed {
 float:right;
 width: 100px;
 box-sizing: border-box;
 text-align: right;
}

.clear:after {
  clear: both;
  content: "";
  display: table;
}

.wrapper {
  background-color: #FFE1E7;
  padding: 20px;
  padding-top: 0px;
  border-style:solid;
  border-width: 0px 2px 2px 2px;
  border-color: #FFBFCE;
  position:relative;
}

.inside-header {
 text-align:center;
 padding:20px;
}

.box1 {
  background-color: white;
  margin: 10px;
  margin-bottom: 5px;
  padding: 10px;
  border-radius: 5px;
  height:145px;
  width:760px;
  display: inline-block;
  float: left;
}

.box2 {
  background-color: white;
  margin: 10px;
  margin-top:5px;
  margin-left:10px;
  margin-right:5px;
  padding: 10px;
  border-radius: 5px;
  height:145px;
  width:375px;
  display: inline-block;
  float: left;
}

.img-float-left {
  width: 300px;
  height: 300px;
  border-radius: 5px; 
  overflow: hidden; 
  float: left;
  margin: 10px;
  display: inline-block;
}

.img-float-right {
  width: 375px;
  height: 300px;
  border-radius: 5px; 
  overflow: hidden; 
  float: left;
  margin: 10px;
  margin-top:5px;
  display: inline-block;
}

.box-header1 {
  text-color:#FF7192;
  text-align:left;
}

.box-text1 {
  text-color:#FF7192;
  text-align:left;
  margin-top: 5px;
}
  
.butt-container {
  background-color: red;
  width: 600px;
  height: 150px;
  display: inline-block;
  float: left;
}
<body>
   <!-- FILENAME BAR  -->
   <div class=containerinvis>
      <div class=filenamebar>
         <div class=filename>
            <p> hello-world!.mpreg</p>
         </div>
         <!-- you're now in filenamebar  -->
         <div class=windowedclosed>
            <p> - ☐ X </p>
         </div>
         <!-- you're now in filenamebar  -->
         <div style="clear: both;"></div>
         <!-- you're now in filenamebar  -->
      </div>
      <!-- you're now in containerinvis  -->
      <!-- THE MAIN WINDOW  -->
      <div class=wrapper>
         <div class=inside-header>
            <h3> [future header] </h3>
         </div>
         <div class=img-float-left>
            <img src="https://i.pinimg.com/564x/9e/71/d2/9e71d22b450cc722dca87ac4c3729536.jpg" alt="dangerous" width="300" height="300">
         </div>
         <!-- you're now in wrapper  -->
         <div class=box1>
            <div class=box-header1>
               <h2> [lil header] </h2>
            </div>
            <div class=box-text1>
               <p> text </p>
            </div>
         </div>
         <div class=box2></div>
         <div class=img-float-right>
            <img src="https://i.pinimg.com/564x/9e/71/d2/9e71d22b450cc722dca87ac4c3729536.jpg" alt="be afraid" width="400" height="400">
         </div>
         <div class=butt-container>
            <p> not in the right place</p>
         </div>
         <!-- you're now in wrapper  -->
         <div style="clear: both;"></div>
         <!-- you're still in wrapper  -->
      </div>
      <!-- you're now in containerinvis  -->
   </div>
   <!-- you're now in outer space  -->
</body>
</html>

I tried to make the box and the img switch places but now the image is not in the right place wrong place please excuse the mspaint, i don't know how else to discribe this.


Solution

  • When you want a right-float, use float: right; on that element ;-) (you had it left-floated)

    * {
        -moz-box-sizing: border-box;
        -webkkit-box-sizing: border-box;
        box-sizing: border-box;
        margin: 0;
        padding: 0;
    }
    
    body {
      background: white;
      color: black;
      font-family: verdana;
      font-size: 14;
      }
      
    center {
      text-align: center;
      }
    
    .containerinvis {
      width: 1150px;
      margin: auto;
      margin-top: 40px;
      margin-bottom: 20px;  
      position: relative;
      }
    
    .filenamebar {
     background-color: #FFCDD9;
     padding: 5px;
     border:solid 2px #EAA2B3
    }
     
    .filename {
    vertical-align: middle;
    color: #341D22;
    text-size: 12;
    float:left;
    }
    
    .windowedclosed {
     float:right;
     width: 100px;
     box-sizing: border-box;
     text-align: right;
    }
    
    .clear:after {
      clear: both;
      content: "";
      display: table;
    }
    
    .wrapper {
      background-color: #FFE1E7;
      padding: 20px;
      padding-top: 0px;
      border-style:solid;
      border-width: 0px 2px 2px 2px;
      border-color: #FFBFCE;
      position:relative;
    }
    
    .inside-header {
     text-align:center;
     padding:20px;
    }
    
    .box1 {
      background-color: white;
      margin: 10px;
      margin-bottom: 5px;
      padding: 10px;
      border-radius: 5px;
      height:145px;
      width:760px;
      display: inline-block;
      float: left;
    }
    
    .box2 {
      background-color: white;
      margin: 10px;
      margin-top:5px;
      margin-left:10px;
      margin-right:5px;
      padding: 10px;
      border-radius: 5px;
      height:145px;
      width:375px;
      display: inline-block;
      float: left;
    }
    
    .img-float-left {
      width: 300px;
      height: 300px;
      border-radius: 5px; 
      overflow: hidden; 
      float: left;
      margin: 10px;
      display: inline-block;
    }
    
    .img-float-right {
      width: 375px;
      height: 300px;
      border-radius: 5px; 
      overflow: hidden; 
      float: right;
      margin: 10px;
      margin-top:5px;
      display: inline-block;
    }
    
    .box-header1 {
      text-color:#FF7192;
      text-align:left;
    }
    
    .box-text1 {
      text-color:#FF7192;
      text-align:left;
      margin-top: 5px;
    }
      
    .butt-container {
      background-color: red;
      width: 600px;
      height: 150px;
      display: inline-block;
      float: left;
    }
    <body>
       <!-- FILENAME BAR  -->
       <div class=containerinvis>
          <div class=filenamebar>
             <div class=filename>
                <p> hello-world!.mpreg</p>
             </div>
             <!-- you're now in filenamebar  -->
             <div class=windowedclosed>
                <p> - ☐ X </p>
             </div>
             <!-- you're now in filenamebar  -->
             <div style="clear: both;"></div>
             <!-- you're now in filenamebar  -->
          </div>
          <!-- you're now in containerinvis  -->
          <!-- THE MAIN WINDOW  -->
          <div class=wrapper>
             <div class=inside-header>
                <h3> [future header] </h3>
             </div>
             <div class=img-float-left>
                <img src="https://i.pinimg.com/564x/9e/71/d2/9e71d22b450cc722dca87ac4c3729536.jpg" alt="dangerous" width="300" height="300">
             </div>
             <!-- you're now in wrapper  -->
             <div class=box1>
                <div class=box-header1>
                   <h2> [lil header] </h2>
                </div>
                <div class=box-text1>
                   <p> text </p>
                </div>
             </div>
             <div class=box2></div>
             <div class=img-float-right>
                <img src="https://i.pinimg.com/564x/9e/71/d2/9e71d22b450cc722dca87ac4c3729536.jpg" alt="be afraid" width="400" height="400">
             </div>
             <div class=butt-container>
                <p> not in the right place</p>
             </div>
             <!-- you're now in wrapper  -->
             <div style="clear: both;"></div>
             <!-- you're still in wrapper  -->
          </div>
          <!-- you're now in containerinvis  -->
       </div>
       <!-- you're now in outer space  -->
    </body>
    </html>