Can't separate 2 block's with padding. Float/Clearfix added, doesn't work

Viewed 18

After three weeks of learning, web development, for the first time I don't know how to fix my problem. Usually, I google a lot until I find the solution to my problem, but this time I don't understand why I can't add padding to serepate 2 blocks. The fact is that im trying to learn from tutorials etc, and I'm doing the same things as on the video. But I can't fix it. If I add padding to my right block or in the left one, it goes under it, even if it's 1px. These are my first steps to building the right website. Content #1 and Content #2 I want to separate.

How to fix that? Can't understand the logic to move on in studying. Thanks for your time, and for helping.

Regards, Apanha_

body {
    color: rgb(255, 255, 255);
    font-size: 30px;
    background-color: rgb(255, 255, 255);

}

.header {
    margin-bottom: 5px;
}

.inner-header {
    background-color: rgb(66, 41, 100);
    height: 200px;
}

.row:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
  }
  .row { display: inline-block; }
  /* start commented backslash hack \*/
  * html .row { height: 1%; }
  .row { display: block; }
  /* close commented backslash hack */

.content {
    width: 40%;
    float: left;
}

.content1 {
    width: 50%;
    float: left;
    background-color: rgb(128, 103, 163);

}

.inner-content1 {
    background-color: rgb(110, 83, 148);
}

.content2 {
    width: 50%;
    float: left;
    background-color: rgb(128, 103, 163);
}

.inner-content2 {
    background-color: rgb(110, 83, 148);
    padding-right: 5px;
}

.inner-content{
    min-height: 705px;
    background-color: rgb(66, 41, 100);
    padding: 5px;
}

.side-bars {
    width: 60%;
    float: left;
}

.sidebar-1 {
    width: 33.33%;
    float: left;
}

.inner-sidebar-1 {
    background-color: rgb(66, 41, 100);
    min-height: 500px;
    margin: 0 5px 0 5px;
}

.sidebar-2 {
    width: 33.33%;
    float: left;
}

.inner-sidebar-2 {
    background-color: rgb(66, 41, 100);
    min-height: 500px;
}

.sidebar-3 {
    width: 33.33%;
    float: left;
}

.inner-sidebar-3 {
    background-color: rgb(66, 41, 100);
    min-height: 500px;
    margin: 0 0 0 5px;
}

.footer {
    margin-top: 5px;
    padding-left: 5px;
}

.inner-footer {
    background-color: rgb(66, 41, 100);
    height: 200px;
    padding-bottom: 10px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vladislav</title>
<link rel="shortcut icon" href="images/fire.png" type="image/x-icon">
<link rel="stylesheet" href="styles/style.css" type="text/css">
<link href="https://fonts.googleapis.com/css2?family=Rubik+Moonrocks&display=swap" rel="stylesheet">
</head>
<body>

     <div class="wrapper"></div>

          <div class="header">
               <div class="inner-header">Header</div>
          </div>
          <div class="row">

               <div class="content">
                <div class="inner-content">

                 <div class="row">
                      <div class="content1">
                           <div class="inner-content1">Content #1</div>
                         </div>
                      <div class="content2">
                           <div class="inner-content2">Content #2</div>
                         </div>
                 </div>
                </div>
               </div>

                    <div class="side-bars">
                         <div class="row">
                              <div class="sidebar-1">
                                   <div class="inner-sidebar-1">Sidebar #1</div>
                              </div>
     
                              <div class="sidebar-2">
                                   <div class="inner-sidebar-2">Sidebar #2</div>
                              </div>
     
                              <div class="sidebar-3">
                                   <div class="inner-sidebar-3">Sidebar #3</div>
                              </div> 
                         </div>
                         <div class="footer">
                              <div class="inner-footer">Footer</div>
                         </div>
                    </div>
               </div>
</body>
</html> 

1 Answers

So, from what I understand from your question you want to separate the content 1 and 2, first you cannot separate them with padding as the padding will be a part of the content, a way to do this is to make the wrapper flex so you will have them in a row then add a margin to the box that you want, in this case Content #2.

Note: This layout is poorly made, you may want to use CSS grid, is much easier.

Maybe this will help you: enter image description here

body {
    color: rgb(255, 255, 255);
    font-size: 30px;
    background-color: rgb(255, 255, 255);

}

.header {
    margin-bottom: 5px;
}

.inner-header {
    background-color: rgb(66, 41, 100);
    height: 200px;
}

.row:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content: " ";
    clear: both;
    height: 0;
 }
 
  .row { display: inline-block; }
  /* start commented backslash hack \*/
  * html .row { height: 1%; }
  .row { display: block; }
  /* close commented backslash hack */

.content {
    width: 40%;
    float: left;
}

.additionalClass { /* added by me */
  display: flex;
}

.content1 {
    width: 50%;
    float: left;
}

.inner-content1 {
    background-color: rgb(110, 83, 148);
}

.content2 {
    width: 50%;
    float: left;
    background-color: rgb(128, 103, 163);
    margin-left: 10px; /* added by me */
}

.inner-content2 {
    background-color: rgb(110, 83, 148);
    padding-right: 5px;
}

.inner-content{
    min-height: 705px;
    background-color: rgb(66, 41, 100);
    padding: 5px;
}

.side-bars {
    width: 60%;
    float: left;
}

.sidebar-1 {
    width: 33.33%;
    float: left;
}

.inner-sidebar-1 {
    background-color: rgb(66, 41, 100);
    min-height: 500px;
    margin: 0 5px 0 5px;
}

.sidebar-2 {
    width: 33.33%;
    float: left;
}

.inner-sidebar-2 {
    background-color: rgb(66, 41, 100);
    min-height: 500px;
}

.sidebar-3 {
    width: 33.33%;
    float: left;
}

.inner-sidebar-3 {
    background-color: rgb(66, 41, 100);
    min-height: 500px;
    margin: 0 0 0 5px;
}

.footer {
    margin-top: 5px;
    padding-left: 5px;
}

.inner-footer {
    background-color: rgb(66, 41, 100);
    height: 200px;
    padding-bottom: 10px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vladislav</title>
<link rel="shortcut icon" href="images/fire.png" type="image/x-icon">
<link rel="stylesheet" href="styles/style.css" type="text/css">
<link href="https://fonts.googleapis.com/css2?family=Rubik+Moonrocks&display=swap" rel="stylesheet">
</head>
<body>

     <div class="wrapper"></div>

          <div class="header">
               <div class="inner-header">Header</div>
          </div>
          <div class="row">

               <div class="content">
                <div class="inner-content">

                 <div class="row additionalClass">
                      <div class="content1">
                           <div class="inner-content1">Content #1</div>
                       </div>
                      <div class="content2">
                           <div class="inner-content2">Content #2</div>
                      </div>
                 </div>
                </div>
               </div>

                    <div class="side-bars">
                         <div class="row">
                              <div class="sidebar-1">
                                   <div class="inner-sidebar-1">Sidebar #1</div>
                              </div>
     
                              <div class="sidebar-2">
                                   <div class="inner-sidebar-2">Sidebar #2</div>
                              </div>
     
                              <div class="sidebar-3">
                                   <div class="inner-sidebar-3">Sidebar #3</div>
                              </div> 
                         </div>
                         <div class="footer">
                              <div class="inner-footer">Footer</div>
                         </div>
                    </div>
               </div>
</body>
</html>

Related