Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a asp.net webpage with background image. In my laptop image is appearing properly where as the same webpage background image appearing half and other portion are blank on mobile phone.

What css code should i use to achieve responsive background image.

image dimension - 1920 * 1080

What I have tried:

CSS
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #212529;
  text-align: left;
  background-color: #fff;
  background-image:url('Stock/exam5.jpg');  
  background-repeat:no-repeat;  
  background-position:center center;
  background-size:cover;
  min-height:100%;
}
Posted
Updated 19-Jul-20 0:27am
v2

1 solution

You can use media queries to achieve it.

Example:
CSS
body {
	background: url(../images/desktop.jpg) no-repeat center center fixed;
}

@media only screen and (min-width : 320px) and (max-width : 480px) {
	background: url(../images/mobile.jpg) no-repeat center center fixed;
}


CSS Media Queries: these are media based stylesheets, that enables the content's presentation to be customized to a specific range of output devices without having to change the content itself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900