Fit Background Image To Div - Intellipaat Community

Login Sign Up Remember
  • Register
Intellipaat Community Courses Ask a Question
  • Questions
  • Unanswered
  • Ask a Question
  • Blog
  • Tutorials
  • Interview Questions

Back

Login Sign Up Explore Courses Blog Tutorials Interview Questions
  • community
  • Web Technology
  • Fit background image to div
Fit background image to div Fit background image to div 0 votes 2 views asked Sep 6, 2019 in Web Technology by (20.3k points)

I have a background image in the following div, but the image gets cut off:

<div style='text-align:center;background-image: url(/media/img_1_bg.jpg);background-repeat:no-repeat;width:450px;height:900px;' id="mainpage" align="center">

Is there a way to show the background image without cutting it off?

  • html
  • css
  • background-image

Please log in or register to add a comment.

Please log in or register to answer this question.

1 Answer

0 votes answered Sep 7, 2019 by (40.7k points)

You can do it by using the background-size property, which is now supported by most of the browsers.

Try using the code given below to scale the background image to fit inside the div:

background-size: contain;

Use the below code to scale the background image to cover the whole div:

background-size: cover;

You can refer to these links for detailed information:

https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

https://caniuse.com/#feat=background-img-opts

http://jsfiddle.net/grc4/wGRD7/

Please log in or register to add a comment.

Related questions

0 votes 1 answer CSS Display an Image Resized and Cropped asked Sep 4, 2019 in Web Technology by Tech4ever (20.3k points)
  • html
  • css
  • background-image
  • image
0 votes 1 answer How do I auto-resize an image to fit a 'div' container? asked Aug 14, 2019 in Web Technology by Sammy (47.6k points)
  • css
  • html
  • image
0 votes 1 answer How to make an image center (vertically & horizontally) inside a bigger div asked Aug 30, 2019 in Web Technology by Soni Kumari (40.7k points)
  • html
  • css
0 votes 1 answer Align image in center and middle within div asked Sep 6, 2019 in Web Technology by Tech4ever (20.3k points)
  • html
  • css
0 votes 1 answer Image inside div has extra space below the image asked Aug 28, 2019 in Web Technology by Tech4ever (20.3k points)
  • html
  • css
  • image
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.9k questions

32.9k answers

500 comments

111k users

  • All categories
  • Python (3.4k)
  • Java (2.3k)
  • SQL (1.6k)
  • Linux (374)
  • Big Data Hadoop & Spark (1.3k)
  • Data Science (3.3k)
  • R Programming (871)
  • C Programming (34)
  • DevOps and Agile (3k)
  • Docker (55)
  • AI and Deep Learning (1.4k)
  • Machine Learning (1.2k)
  • AWS (2.5k)
  • Azure (1.6k)
  • GCP (226)
  • RPA (626)
  • Selenium (205)
  • Software Testing (58)
  • Blockchain (428)
  • Salesforce (822)
  • Others (582)
  • BI (1.9k)
  • IoT (24)
  • Web Technology (1.5k)
  • Cyber Security (358)
  • Digital Marketing (327)
  • Technology Trends (108)
  • SEO (105)
  • Informatica (22)
  • UI UX (152)
  • Electric Vehicle (14)
  • Investment Banking (56)
  • Supply Chain Management (20)

Popular Questions

  • Are there any industry-specific trends in data analysis that I should be aware of during my career transition? Mar 22
  • How do I showcase my MIS experience to make a successful transition into data analysis? Mar 22
  • Are there specific tools I should learn for a successful transition from MIS Executive to Data Analyst? Mar 22
  • How does the salary and benefits package typically differ between associate analyst and analyst positions? Mar 22
  • Are there any industry-specific trends or advancements that aspiring analysts should be aware of during their career transition? Mar 22
  • What are common challenges faced by individuals transitioning from associate analyst to analyst, and how can they be overcome? Mar 22

Browse Categories

  • Master Program
  • Big Data
  • Data Science
  • Business Intelligence
  • Salesforce
  • Cloud Computing Courses
  • Mobile Development
  • Digital Marketing
  • Database
  • Programming
  • Testing
  • Project Management
  • Web Development Courses
Intellipaat

Popular Courses

Data Science Course | Artificial Intelligence Course | Machine Learning Course | Python Course | DevOps Course | AWS Solutions Architect | Cyber Security Course | Ethical Hacking Course | Digital Marketing Course | SQL Course | Business Analyst Course | Data Analyst course | Investment Banking Course | Electric Vehicle Course | UI UX Design Course | AWS DevOps Course | Azure DevOps Course | Full Stack Developer Course | Data Analytics Course | Python Data Science Course | Salesforce Certification Course | Informatica Course

Top Tutorials

Python Tutorial | AWS Tutorial | Devops Tutorial | Data Science Tutorial | Machine Learning Tutorial | Cyber Security Tutorial | Salesforce Tutorial | Azure Tutorial | Power BI Tutorial | SQL Tutorial | Selenium Tutorial | Ethical Hacking Tutorial | Artificial Intelligence Tutorial | Digital Marketing Tutorial | UI/UX Tutorial

Top Articles

Cloud Computing | Data Science | Machine Learning | AWS | Digital Marketing | Cyber Security | Artificial Intelligence | SQL | UI/UX Design | Ethical Hacking

Top Interview Questions

Python Interview Questions | AWS Interview Questions | Data Science Interview Questions | Devops Interview Questions | Salesforce Interview Questions | Java Interview Questions | Selenium Interview Questions | Cyber Security Interview Questions | Azure Interview Questions | Power Bi Interview Questions | Software Testing Interview Questions | Data Analyst Interview Questions

© COPYRIGHT 2011-2023 INTELLIPAAT.COM. ALL RIGHTS RESERVED.

Download Salary Trends Now !

Learn how professionals like you got up to 100% Salary Hike.

By providing your contact details, you agree to our Terms of Use & Privacy Policy ...

Từ khóa » Html Scale Background Image To Fit Div