Search code examples
htmlcsscss-floatfooter

Prevent footer from overlapping combining with float


I have created a bubble conversation html. Now I am trying to add a footer to it. (Footer similar code in https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_fixed_footer)

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul li {
  display: inline-block;
  clear: both;
  padding: 5px;
  border-radius: 20px;
  margin-bottom: 2px;
  width: 80%;
  background: #eee;
}

.him {
  float: left;
  border: 1px solid #000000;
}

.me {
  float: right;
}

#footer {
  height: 30px;
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: red;
  color: white;
  text-align: center;
}

body {
  padding-bottom: 30px;
}
<div>
  <div>
    <ul>
      <li class="me">N-19</li>
      <li class="me">N-18</li>
      <li class="him">N-17</li>
      <li class="me">N-16</li>
      <li class="me">N-15</li>
      <li class="me">N-14</li>
      <li class="him">N-13</li>
      <li class="me">N-12</li>
      <li class="me">N-11</li>
      <li class="me">N-10</li>
      <li class="me">N-9</li>
      <li class="me">N-8</li>
      <li class="him">N-7</li>
      <li class="me">N-6</li>
      <li class="me">N-5</li>
      <li class="me">N-4</li>
      <li class="me">N-3</li>
      <li class="me">N-2</li>
      <li class="me">N-1</li>
      <li class="him">N</li>
    </ul>
  </div>
  <div id="footer">
    Footer
  </div>
</div>

But I am not seeing the last lines of the conversation. The problem is that the footer is overlaping them because of the float property of the < li > elements.

enter image description here

How can I avoid it?


Solution

  • check this out: css grid is a very good property of css.
    we can divide screen into number of columns and rows . i used here css-grid.

    for more info on css-grid read
    https://css-tricks.com/snippets/css/complete-guide-grid/

    ul {
          list-style: none;
          margin: 0;
          padding: 0;
          display:grid;
          grid-template-columns:33% 33% 34%;
      
        }
    
        ul li {
          display: block;
          clear: both;
          padding: 5px;
          border-radius: 20px;
          margin-bottom: 2px;
          
          background: #eee;
        }
    
        .him {
          grid-column:1/3;
          border: 1px solid #000000;
        }
    
        .me {
        grid-column:2/4
          
        }
    
        #footer {
          height: 30px;
          position: fixed;
          bottom:0;
          
          width: 100%;
          background-color: red;
          color: white;
          text-align: center;
        }
    
        body {
          padding-bottom: 30px;
        }
    <div>
          <div>
            <ul>
              <li class="me">N-19</li>
              <li class="me">N-18</li>
              <li class="him">N-17</li>
              <li class="me">N-16</li>
              <li class="me">N-15</li>
              <li class="me">N-14</li>
              <li class="him">N-13</li>
              <li class="me">N-12</li>
              <li class="me">N-11</li>
              <li class="me">N-10</li>
              <li class="me">N-9</li>
              <li class="me">N-8</li>
              <li class="him">N-7</li>
              <li class="me">N-6</li>
              <li class="me">N-5</li>
              <li class="me">N-4</li>
              <li class="me">N-3</li>
              <li class="me">N-2</li>
              <li class="me">N-1</li>
              <li class="him">N</li>
            </ul>
          </div>
          <div id="footer">
            Footer
          </div>
        </div>