HTML 5 image adaptive screen img proportional scaling code for webpage HTML XNUMX

Due to the booming mobile Internet,Wechat marketingThe popularity of mobile phones has becomeLifemust-have tool.

Building websitetemplate, it is recommended to useWordPressAdaptive theme for:

  • If the WordPress theme developer did not make the HTML 5 image adaptive screen well when designing the WordPress theme page...
  • When browsing the website on a mobile device, there will be a very ugly picture misalignment, and the user experience is extremely poor!

What does CSS image adaptive mean?

HTML 5 image adaptive screen img proportional scaling code for webpage HTML XNUMX

CSS image adaptive means to make the images in the html web page, through CSS code:

  • Automatically adapt to the width and height of different devices.
  • The img tag is automatically scaled proportionally.

Next,Chen WeiliangI will share with you the CSS img proportional scaling code ^_^

CSS image height and width adaptive code

Insert image in html:

If you want the image to adapt to the small size of the screen instead of staying fixed in width and height.

You can add the following code to the style.css file of your WordPress theme ▼

/*图片自适应宽度和高度*/ 
img { max-width: 100%; height: auto; width: auto\9; width: auto; }

statement heremax-widthmaximum width rule

  • to ensure that all images are displayed at maximum 100% (i.e. they can only be displayed as large as their own images).
  • At this point, if the element containing the image (for example, the body or div containing the image) is smaller than the image's inherent width, the image will be scaled to fill the maximum available space.

width:auto;means automatic width

\9 It is a way of writing hack css.

  • In this way, "\9" is added to the normal css code, only IE browser can recognize it, other browsers will ignore this statement.
  • This will achieve browser differentiation, enabling the purpose of compatible browsers.

Why not use width: 100%?

To achieve automatic scaling of images, you can also use the more commonly used width properties, e.g.width:100%.

However, this rule does not apply here.

  • Because this rule will make it appear as wide as its container.
  • In cases where the container is much wider than the image, the image will be stretched unnecessarily.

Please Note

What are CSS selectors? What is the difference between class and id?The following tutorials talk about ▼

How does the mobile website play MP4 video adaptive to the page?Please click the link below ▼

 

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "Web page HTML 5 image adaptive screen img proportional scaling code", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-964.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top