How do I change css for to work best on a mobile phone?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

How do I change css for to work best on a mobile phone?

Expert Solution
Step 1

A new feature is added into CSS3 “Media queries” which enables a web-developer to create a website that can be accessed in different devices having different screen resolutions.

Media queries focus on device capability rather than the type of device.

It mainly focuses on the following terms: -

  • Height of the device
  • Width of the device
  • Height of the viewport (browser)
  • Width of the viewport (browser)
  • Screen resolution
  • Orientation (for tablets and mobile phones; landscape or portrait)  

By using this technique, a website can be made compatible with mobile devices.

Step 2

To understand it better let’s take a small example to change the color of the website when the resolution of the screen is changed.

Code: -

<!html section- begin>

<html>

<!head section- begin>

<head>

<!style section-begin>

<style>

/*body section*/

body

{

  background-color: red;

  color: black;

}

/* setting the background color as tan when the size of the screen is 900px or less */

@media screen and (max-width: 900px)

{

  /*body section*/          

  body

  {

    background-color: tan;

    color: white;

  }           

}

/*style section- end*/

</style>

<!head section- end>

</head>

<!body sectin- begin>

<body>

<!heading>

<h1>Please change the size of the screen to see the effects</h1>

<!paragraph section>

<p>The background color is "red" by default, if the size of the screen size is 900px or less, the background color will change to "tan".</p>

<!body section - end>

</body>

<!html section- end>

</html>

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Designing Webpage
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education