Padding changing the size on an image [duplicate]












0
















This question already has an answer here:




  • width: 100%-padding?

    14 answers




So im trying to create some padding for my profile_pic div.



This is the html:



  <body>
<div id="content" class="content">
<div id="profile_pic" class="profile_pic">
</div>
<div id="overview" class="overview">
asdasdasdasdasd
</div>
<div id="buttons" class="buttons">
<!-- Sport, Academic, Other -->
</div>
</div>
</body>


and this the css



.profile_pic {
height: 30%;
width: 15%;
margin-left: auto;
margin-right: auto;
background-image: url("./images/profile_pic.jpg");
border-radius: 8px;
background-repeat:no-repeat;
background-size:cover;
}


and this is what the page looks like



when i add the lines



padding-top: 10%;
padding-bottom: 10%;


this is what happens to the image



could someone please explain why this is happen










share|improve this question













marked as duplicate by Temani Afif css
Users with the  css badge can single-handedly close css questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 15 '18 at 19:30


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    0
















    This question already has an answer here:




    • width: 100%-padding?

      14 answers




    So im trying to create some padding for my profile_pic div.



    This is the html:



      <body>
    <div id="content" class="content">
    <div id="profile_pic" class="profile_pic">
    </div>
    <div id="overview" class="overview">
    asdasdasdasdasd
    </div>
    <div id="buttons" class="buttons">
    <!-- Sport, Academic, Other -->
    </div>
    </div>
    </body>


    and this the css



    .profile_pic {
    height: 30%;
    width: 15%;
    margin-left: auto;
    margin-right: auto;
    background-image: url("./images/profile_pic.jpg");
    border-radius: 8px;
    background-repeat:no-repeat;
    background-size:cover;
    }


    and this is what the page looks like



    when i add the lines



    padding-top: 10%;
    padding-bottom: 10%;


    this is what happens to the image



    could someone please explain why this is happen










    share|improve this question













    marked as duplicate by Temani Afif css
    Users with the  css badge can single-handedly close css questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 15 '18 at 19:30


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      0












      0








      0


      0







      This question already has an answer here:




      • width: 100%-padding?

        14 answers




      So im trying to create some padding for my profile_pic div.



      This is the html:



        <body>
      <div id="content" class="content">
      <div id="profile_pic" class="profile_pic">
      </div>
      <div id="overview" class="overview">
      asdasdasdasdasd
      </div>
      <div id="buttons" class="buttons">
      <!-- Sport, Academic, Other -->
      </div>
      </div>
      </body>


      and this the css



      .profile_pic {
      height: 30%;
      width: 15%;
      margin-left: auto;
      margin-right: auto;
      background-image: url("./images/profile_pic.jpg");
      border-radius: 8px;
      background-repeat:no-repeat;
      background-size:cover;
      }


      and this is what the page looks like



      when i add the lines



      padding-top: 10%;
      padding-bottom: 10%;


      this is what happens to the image



      could someone please explain why this is happen










      share|improve this question















      This question already has an answer here:




      • width: 100%-padding?

        14 answers




      So im trying to create some padding for my profile_pic div.



      This is the html:



        <body>
      <div id="content" class="content">
      <div id="profile_pic" class="profile_pic">
      </div>
      <div id="overview" class="overview">
      asdasdasdasdasd
      </div>
      <div id="buttons" class="buttons">
      <!-- Sport, Academic, Other -->
      </div>
      </div>
      </body>


      and this the css



      .profile_pic {
      height: 30%;
      width: 15%;
      margin-left: auto;
      margin-right: auto;
      background-image: url("./images/profile_pic.jpg");
      border-radius: 8px;
      background-repeat:no-repeat;
      background-size:cover;
      }


      and this is what the page looks like



      when i add the lines



      padding-top: 10%;
      padding-bottom: 10%;


      this is what happens to the image



      could someone please explain why this is happen





      This question already has an answer here:




      • width: 100%-padding?

        14 answers








      html css






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 17:02









      wtrestonwtreston

      580214




      580214




      marked as duplicate by Temani Afif css
      Users with the  css badge can single-handedly close css questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 19:30


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by Temani Afif css
      Users with the  css badge can single-handedly close css questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 15 '18 at 19:30


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          2 Answers
          2






          active

          oldest

          votes


















          2














          Use box-sizing: border-box;, it includes padding and border in the element's total width and height. ;)



          Here would be the final code.






          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>








          share|improve this answer


























          • Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

            – wtreston
            Nov 15 '18 at 17:16











          • Use margin-top: 100px; by example

            – Jonathan Gagne
            Nov 15 '18 at 17:18











          • Perfect thats worked

            – wtreston
            Nov 15 '18 at 17:35











          • Awesome! I'm glad, let me know if you need anything else!

            – Jonathan Gagne
            Nov 15 '18 at 17:36



















          1














          Set this property to the image: box-sizing: border-box



          This way the total size of the image will be calculated including the padding as well, instead of adding the padding size as extra.






          share|improve this answer
























          • Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

            – rubentd
            Nov 15 '18 at 17:05


















          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Use box-sizing: border-box;, it includes padding and border in the element's total width and height. ;)



          Here would be the final code.






          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>








          share|improve this answer


























          • Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

            – wtreston
            Nov 15 '18 at 17:16











          • Use margin-top: 100px; by example

            – Jonathan Gagne
            Nov 15 '18 at 17:18











          • Perfect thats worked

            – wtreston
            Nov 15 '18 at 17:35











          • Awesome! I'm glad, let me know if you need anything else!

            – Jonathan Gagne
            Nov 15 '18 at 17:36
















          2














          Use box-sizing: border-box;, it includes padding and border in the element's total width and height. ;)



          Here would be the final code.






          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>








          share|improve this answer


























          • Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

            – wtreston
            Nov 15 '18 at 17:16











          • Use margin-top: 100px; by example

            – Jonathan Gagne
            Nov 15 '18 at 17:18











          • Perfect thats worked

            – wtreston
            Nov 15 '18 at 17:35











          • Awesome! I'm glad, let me know if you need anything else!

            – Jonathan Gagne
            Nov 15 '18 at 17:36














          2












          2








          2







          Use box-sizing: border-box;, it includes padding and border in the element's total width and height. ;)



          Here would be the final code.






          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>








          share|improve this answer















          Use box-sizing: border-box;, it includes padding and border in the element's total width and height. ;)



          Here would be the final code.






          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>








          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>





          .profile_pic {
          box-sizing: border-box;
          height: 30%;
          width: 15%;
          margin-left: auto;
          margin-right: auto;
          background-image: url("./images/profile_pic.jpg");
          border-radius: 8px;
          background-repeat:no-repeat;
          background-size:cover;
          }

          <div id="content" class="content">
          <div id="profile_pic" class="profile_pic">
          </div>
          <div id="overview" class="overview">
          asdasdasdasdasd
          </div>
          <div id="buttons" class="buttons">
          <!-- Sport, Academic, Other -->
          </div>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 17:12

























          answered Nov 15 '18 at 17:04









          Jonathan GagneJonathan Gagne

          2,1993722




          2,1993722













          • Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

            – wtreston
            Nov 15 '18 at 17:16











          • Use margin-top: 100px; by example

            – Jonathan Gagne
            Nov 15 '18 at 17:18











          • Perfect thats worked

            – wtreston
            Nov 15 '18 at 17:35











          • Awesome! I'm glad, let me know if you need anything else!

            – Jonathan Gagne
            Nov 15 '18 at 17:36



















          • Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

            – wtreston
            Nov 15 '18 at 17:16











          • Use margin-top: 100px; by example

            – Jonathan Gagne
            Nov 15 '18 at 17:18











          • Perfect thats worked

            – wtreston
            Nov 15 '18 at 17:35











          • Awesome! I'm glad, let me know if you need anything else!

            – Jonathan Gagne
            Nov 15 '18 at 17:36

















          Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

          – wtreston
          Nov 15 '18 at 17:16





          Ok so I have changed the css, however the image is still the same distance from the top of the screen as it was before. How would I move it down X amount

          – wtreston
          Nov 15 '18 at 17:16













          Use margin-top: 100px; by example

          – Jonathan Gagne
          Nov 15 '18 at 17:18





          Use margin-top: 100px; by example

          – Jonathan Gagne
          Nov 15 '18 at 17:18













          Perfect thats worked

          – wtreston
          Nov 15 '18 at 17:35





          Perfect thats worked

          – wtreston
          Nov 15 '18 at 17:35













          Awesome! I'm glad, let me know if you need anything else!

          – Jonathan Gagne
          Nov 15 '18 at 17:36





          Awesome! I'm glad, let me know if you need anything else!

          – Jonathan Gagne
          Nov 15 '18 at 17:36













          1














          Set this property to the image: box-sizing: border-box



          This way the total size of the image will be calculated including the padding as well, instead of adding the padding size as extra.






          share|improve this answer
























          • Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

            – rubentd
            Nov 15 '18 at 17:05
















          1














          Set this property to the image: box-sizing: border-box



          This way the total size of the image will be calculated including the padding as well, instead of adding the padding size as extra.






          share|improve this answer
























          • Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

            – rubentd
            Nov 15 '18 at 17:05














          1












          1








          1







          Set this property to the image: box-sizing: border-box



          This way the total size of the image will be calculated including the padding as well, instead of adding the padding size as extra.






          share|improve this answer













          Set this property to the image: box-sizing: border-box



          This way the total size of the image will be calculated including the padding as well, instead of adding the padding size as extra.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 17:04









          rubentdrubentd

          1,089822




          1,089822













          • Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

            – rubentd
            Nov 15 '18 at 17:05



















          • Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

            – rubentd
            Nov 15 '18 at 17:05

















          Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

          – rubentd
          Nov 15 '18 at 17:05





          Also, take into consideration that 10% of padding will use the parent element size as a reference, not the size of the image

          – rubentd
          Nov 15 '18 at 17:05



          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python