How to Fix Element Going Out of Div When Resized Bigger Again

One of the main parts of responsive web design is resizing the image automatically to fit the width of its container. Since present people apply different kinds of desktops, our spider web pages must be appropriate for all types of screens.

Then, let's learn three ways of resizing images and making responsive images with just HTML and CSS.

Utilise the width and acme attributes for your <img> tag to ascertain the width and superlative of the prototype. See an example below.

Example of resizing an epitome proportionally with the width and height attributes:

                              <!DOCTYPE                  html>                <html>                <head>                <title>Title of the document</championship>                </head>                <trunk>                <p>Resized image:</p>                <img                  src="/uploads/media/default/0001/01/25acddb3da54207bc6beb5838f65f022feaa81d7.jpeg"                  alt="Aleq"                  width="160"                  height="145"                  />                <p>Original epitome size:</p>                <img                  src="/uploads/media/default/0001/01/25acddb3da54207bc6beb5838f65f022feaa81d7.jpeg"                  alt="Aleq"                  />                </torso>                </html>                          

Effect

Resized paradigm:

Aleq

Original image size:

Aleq

While resizing an image, the attribute ratio (the viewable surface area and display shape) should exist preserved. Otherwise, the image can get distorted and lose its quality.

Some other way of resizing images is using the CSS width and height properties. Ready the width property to a percent value and the height to "auto". The image is going to be responsive (it will scale up and down).

Example of resizing an prototype proportionally with the width and height properties:

                              <!DOCTYPE                  html>                <html>                <head>                <title>Responsive Resized Image</title>                <style>                                  img                  {                  width:                  100%;                  height: auto;       }                                </way>                </head>                <torso>                <h2>Responsive Resized Prototype</h2>                <p>Resize the browser to see the responsive effect:</p>                <img                  src="/uploads/media/default/0001/03/5bfad15a7fd24d448a48605baf52655a5bbe5a71.jpeg"                  alt="New York"                  />                </torso>                </html>                          

Note that the epitome could be scaled more than than the original size. In several cases, a better option is to use the max-width holding alternatively.

In that location is a better way for resizing images responsively. If the max-width property is ready to 100%, the image will scale down if it has to, simply never scale up to be larger than its original size. The trick is to use height: automobile; to override any already present elevation attribute on the paradigm.

Example of adding a responsive resized image with the max-width belongings:

                              <!DOCTYPE                  html>                <html>                <caput>                <title>Responsive Resized Paradigm with max-width</title>                <style>                                  img                  {                  max-width:                  100%;                  height: auto;       }                                </mode>                </head>                <body>                <h2>Responsive Resized Image with max-width</h2>                <p>Resize the browser to see the responsive upshot:</p>                <img                  src="/uploads/media/default/0001/03/5bfad15a7fd24d448a48605baf52655a5bbe5a71.jpeg"                  alt="New York"                  />                </torso>                </html>                          

Let'southward see some other live spider web page example with the same method.

Example of resizing an image proportionally using the max-width property:

                              <!DOCTYPE                  html>                <html>                <head>                <title>Responsive Resized Epitome in a Web Page</title>                <style>                                  * {                  box-sizing: border-box;       }                  html                  {                  font-family:                  "Lucida Sans", sans-serif;       }                  img                  {                  width:                  100%;                  superlative: automobile;       }                  .row:after {         content:                  "";                  clear: both;                  display: table;       }                  .menu,                  .content                  {                  float: left;                  padding:                  15px;                  width:                  100%;       }                  @media                  only                  screen                  and                  (min-width:                  600px) {                  .carte                  {                  width:                  25%;         }                  .content                  {                  width:                  75%;         }       }                  @media                  only                  screen                  and                  (min-width:                  768px) {                  .menu                  {                  width:                  20%;         }                  .content                  {                  width:                  79%;         }       }                  .header                  {                  background-color:                  #1c87c9;                  color:                  #ffffff;                  padding:                  10px;                  text-align: center;       }                  .bill of fare                  ul                  {                  list-way-type: none;                  margin:                  0;                  padding:                  0;       }                  .carte du jour                  li                  {                  padding:                  8px;                  margin-bottom:                  7px;                  background-color:                  #666666;                  color:                  #ffffff;                  box-shadow:                  0                  1px                  3px                  rgba(0,                  0,                  0,                  0.12),                  0                  1px                  2px                  rgba(0,                  0,                  0,                  0.24);       }                  .menu                  li                  :hover                  {                  background-colour:                  #1c87c9;       }                  .footer                  {                  background-color:                  #1c87c9;                  color:                  #ffffff;                  text-align: center;                  font-size:                  12px;                  padding:                  15px;       }                                </style>                </caput>                <body>                <div                  class="header">                <h1>W3DOCS</h1>                </div>                <div                  class="row">                <div                  class="card">                <ul>                <li>Books</li>                <li>Snippets</li>                <li>Quizzes</li>                <li>Tools</li>                </ul>                </div>                <div                  course="content">                <h2>About U.s.</h2>                <p>                W3docs provides gratuitous learning materials for programming languages like HTML, CSS, Java Script, PHP etc.                </p>                <p>                It was founded in 2012 and has been increasingly gaining popularity and spreading amongst both beginners and professionals who want to raise their programming skills.                </p>                <img                  src="/uploads/media/default/0001/02/8070c999efd1a155ad843379a5508d16f544aeaf.jpeg"                  alt="Team Work"                  />                </div>                </div>                <div                  class="footer">                <p>                Resize the browser window to meet how the content answer to the resizing.                </p>                </div>                </body>                </html>                          

glascofouthe.blogspot.com

Source: https://www.w3docs.com/snippets/css/how-to-resize-images-proportionally-scaled-using-css-for-responsive-web-design.html

0 Response to "How to Fix Element Going Out of Div When Resized Bigger Again"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel