Images leads to better engagement with your website visitors. They help in presenting the important pieces of information in a fun and effective manner. And so, when creating a mobile version of your website, make sure that your images look perfect on any mobile display. But, let\'s face it! Making your images responsive can be challenging, since not all of them are adaptable. Put it simply, the fixed-width images cannot resize according to the device they\'re accessed on.
- Demo
- Phóng to
- Tải lại
- Cửa sổ mới
Miễn phí web hosting 1 năm đầu tại iPage
Nếu bạn vẫn còn đang tìm kiếm một nhà cung cấp hosting đáng tin cậy, tại sao không dành chút thời gian để thử với iPage, chỉ với không quá 40.000 VNĐ/tháng, nhưng bạn sẽ được khuyến mãi kèm với quà tặng trị giá trên 10.000.0000 VNĐ nếu thanh toán cho 24 tháng ~ 900.000 VNĐ?
Có trên 1 triệu khách hàng hiện tại của iPage đã & đang hài lòng với dịch vụ, tuyệt đối chắc chắn bạn cũng sẽ hài lòng giống họ! Quan trọng hơn, khi đăng ký sử dụng web hosting tại iPage thông qua sự giới thiệu của chúng tôi, bạn sẽ được hoàn trả lại toàn bộ số tiền bạn đã sử dụng để mua web hosting tại iPage. Wow, thật tuyệt vời! Bạn không phải tốn bất kì chi phí nào mà vẫn có thể sử dụng miễn phí web hosting chất lượng cao tại iPage trong 12 tháng đầu tiên. Chỉ cần nói chúng tôi biết tài khoản của bạn sau khi đăng ký.
Nếu muốn tìm hiểu thêm về ưu / nhược điểm của iPage, bạn hãy đọc đánh giá của ChọnHostViệt.com nhé!
Images leads to better engagement with your website visitors. They help in presenting the important pieces of information in a fun and effective manner. And so, when creating a mobile version of your website, make sure that your images look perfect on any mobile display. But, let's face it! Making your images responsive can be challenging, since not all of them are adaptable. Put it simply, the fixed-width images cannot resize according to the device they're accessed on.
There are techniques using which you can make the images having fixed width fluid, however, you might find them complex and incomprehensible to implement. For example, the <picture> element when used together with the "srcset/sizes" attributes proves an effective technique to implement responsive image in your website design. But, working with the srcset attribute can give you a hard time. Even though, this responsive image technique may seem befitting to experienced designers, but a beginner will find working on this technique quite challenging.
But, there is a simple approach following which you can easily create responsive images without going through much trouble. You can make images responsive using CSS properties: width and height. Reading this post further will help you better understand how you can use this approach to make your images fit for different mobile devices and platforms.
Let's Get Started
Remember before beginning with the process of making the images responsive, it's important for you to create a responsive (or a fluid) layout. Even when using CSS, you'll have to work with different variations to make the images responsive. However, the concept on which all those variations will rely upon will remain to be same: the width of the image will be set to percentage-length (or a rel unit), and the value of height will be auto, as shown in the following code snippet:
img { width: 100%; height: auto; }
Create a Simple Responsive Image
Let's understand how you can create a simple responsive image. For this let's consider an example, use “div” as the container containing an image element. Below is a simple HTML markup with the div container:
<div class="container"> <img src="abc1_image.jpg" width="940" height="620" /> </div>
Assume that the image container has a width set to 94%, so as to save some margin on the left and right side of the container. As you can see in the code above, the maximum width of the container is 940px. This will ascertain that the layout won't exceed when being viewed on a large screen.
The image-width of an element inside the container will contain a percentage-length of 100%, making it's value equal to that of the container-width. This will help in making your image scale according to the size of the container, no matter whatever viewport it used for accessing the images. This results in making the images responsive. Apart from the width, the height will be set to auto (as we had discussed previously). This will make the image to scale proportionally.
Let us now look at how the CSS will look, once the above discussed technique is implemented:
div.container { width: 94%; max-width: 940px; margin: 0 auto; /* to center the container */ } img { width: 100%; height: auto; }
Note: Implementing the above discussed image responsive technique will turn the image element into a responsive one, even though it features fixed dimensions (i.e. width and height). This is an ideal approach, you can use for website containing content with fixed dimensions.
Making Responsive Images For Different Column Layouts
When browsing the web, you'll most likely have come across sites featuring a responsive web design with images presented in a column. For instance, several sites contain image gallery added in the form of gird with plenty of images and thumbnails.
In order to make the images responsive for column layout, you just need to lessen the value of CSS width. And then, simply set the value of your image element "display" property to “inline-block”. Since a website design may contain two-column or three-column layout, let's understand how we can implement responsive images in both these column layouts:
Implementing Responsive Images in Two-column Layout
For this purpose, you just need to make your CSS width property reduced to one-half of the container's width, i.e. 47%. Since the CSS width isn't set to 50%, the images will be placed on your design having proper space on the left and right sides (or margins).
<div class="container"> <img src="abc1_image.jpg" width="940" height="620" /> <img src="abc2_image.jpg" width="940" height="620" /> </div>
img { width: 47%; display: inline-block; }
Implementing Responsive Images in Three-column Layout
In order to implement responsive images in the three-column layout, we'll have to follow the same approach as discussed in the two-column layout scheme. However, the only difference in both the schemes is that here the CSS width will be calculated based on one-third of the container's width, i.e. 31%.
<div class="container"> <img src="abc1_image.jpg" width="940" height="620" /> <img src="abc2_image.jpg" width="940" height="620" /> <img src="abc3_image.jpg" width="940" height="620" /> </div>
.three-columns { width: 31%; display: inline-block; }
Adding Conditional Breakpoints
When you need to incorporate responsive images in different columns, you'll be required to resize the images quite often, based on the size of small or large screen. But, making our scale for multiple screen sizes separately isn't a viable solution. One best way to implement responsive images in columns is to make use of conditional breakpoints, which further requires using media queries.
Here's an example demonstrating how you can use media queries to display responsive images in different column layouts:
<div class="container"> <img src="abc1_image.jpg" width="940" height="620" /> <img src="abc2_image.jpg" width="940" height="620" /> <img src="abc3_image.jpg" width="940" height="620" /> <img src="abc4_image.jpg" width="940" height="620" /> </div>
/* Code for making images responsive for small devices (i.e. Smartphones) */ img { max-width: 100%; display: inline-block; } /* Code for making images responsive for medium-size devices (i.e. tablets) */ @media (min-width: 420px) { img { max-width: 47%; } } /* Code for making images responsive for large devices (i.e. desktops) */ @media (min-width: 760px) { img { max-width: 24%; } }
Conclusion
Hope that the post will prove a useful resource to you, helping you understand a simple approach to making the images responsive and implementing them in your responsive design.
Tác giả
Samuel Dawson is a extreme professional in Designs2HTML Ltd, a leading PSD to HTML conversion company. He is also a serial blogger sharing his knowledge across the globe on the web.
- Lượt gửi (0)
- Mới
Tạo video doanh nghiệp của bạn bằng AI chỉ với giọng nói hoặc văn bản
chatGPTaz.com
Nói chuyện với ChatGPT bằng ngôn ngữ mẹ đẻ của bạn
Ứng dụng AI Video
Ứng dụng video AI MIỄN PHÍ đầu tiên của bạn
Deepfake Video
Deepfake AI Video Maker
Deepfake
Deepfake AI Video Maker
AI Deep Fake
Deepfake AI Video Maker
AIvidio
AI Video Mobile Solutions
AIvideos
AI Video Platform & Solutions
AIvedio
AI Video App Maker
Faceswap AI trực tuyến
Đổi mặt Video, Ảnh & GIF ngay lập tức với Công cụ AI mạnh mẽ - Faceswap AI Trực tuyến MIỄN PHÍ
Faceswap AI trực tuyến
Đổi mặt Video, Ảnh & GIF ngay lập tức với Công cụ AI mạnh mẽ - Faceswap AI Trực tuyến MIỄN PHÍ
Temu tặng $500 cho người dùng mới
Claim Free Temu $500 Credit via Affiliate & Influencer Program
Tín dụng quảng cáo TikTok miễn phí
Làm chủ quảng cáo TikTok cho hoạt động tiếp thị doanh nghiệp của bạn
Dall-E-OpenAI.com
Tự động tạo ra hình ảnh sáng tạo với AI
chatGPT4.win
Nói chuyện với ChatGPT bằng ngôn ngữ mẹ đẻ của bạn
Sản phẩm AI đầu tiên của Elon Musk - Grok/UN.com
Nói chuyện với Grok AI Chatbot bằng ngôn ngữ của bạn
Công cụ.win
Mở trung tâm công cụ miễn phí để mọi người sử dụng với hàng trăm công cụ
GateIO.gomymobi.com
Airdrop miễn phí để nhận, chia sẻ lên đến 150.000 đô la cho mỗi dự án
iPhoneKer.com
Tiết kiệm tới 630$ khi mua iPhone 16 mới
Mua Robot Tesla Optimus
Đặt mua Tesla Bot: Robot Optimus Gen 2 ngay hôm nay với giá dưới 20.000 đô la
Great Srcipts Phản hồi