close[x]


CSS

CSS-Home CSS-Environment CSS-Basic syntax CSS-Selector CSS-How To Add CSS CSS-Comment CSS-Color CSS-Background CSS-Font CSS-Text CSS-Boarder CSS-Margin CSS-Padding CSS-Height/Width CSS-Link CSS-Table CSS-Visibility CSS-Scrollable CSS-Float/Clear CSS-Line CSS-Align CSS-Dimension CSS-Event CSS-Pusedo class CSS-Position CSS-Transparency CSS-Dropdown CSS-Form CSS-List/Counter CSS-Website layout CSS-Text effect CSS-Image effect CSS-Button effect CSS-page number CSS-Box CSS-@media CSS-Multi device CSS-Multi device 1 CSS-Multi device 2



learncodehere.com




CSS - Media Queries

The most important feature of style sheet is how a document is to be presented in diffeent media.

Media query is a w3c recommendation .

Media rule makes you to set different rules for media types.

Media queries also used to check :

  • View point (Width and Height)
  • Device (Width and Height)
  • Orientation mode(Landscape and portable)
  • resolution
  • using these media queries techniques you can set a tailored style sheet to all type of devices.


    Syntax : Media Queries

    @media not|only mediatype and (expressions) {
    CSS-Code;
    }

    The corresponding stylesheet or style rules are applied when the media query is true.

    Unless you use the not or only operators, the media type is optional.

    Media features for Media queries

    The following is a list of media features for media queries

    Feature Value Min/Max Description
    color integer yes Used to specifies the number of bits per color component.
    color-index integer yes Used to specifies the number of entries in the color lookup table.
    device-aspect-ratio integer yes Used to specifies the aspect ratio of the device.
    device-height length yes Used to specifies the height of the output device.
    device-width length yes Used to specifies the width of the output device.
    grid integer no Used to is true for a grid-based device.
    height length yes Used to specifies the height of the rendering surface.
    monochrome integer yes Used to specifies the number of bits per pixel in a monochrome frame buffer.
    resolution resolution (dpi or dpcm) yes Used to specifies the resolution of the display screen.
    scan progressive or interlaced no Used to specifies scanning process of "tv" media types.
    width length yes Used to specifies the width of the rendering surface.


    Responsive background-color


    Example : Media Queries

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    /* Default background color is yellow and
    the screen that are 600px and more ,
    the background color is yellow*/
    body {
    background-color: yellow;
    color: black;
    }
    /* On screens that are 600px wide or less,
    the background color is blue */
    @media screen and (max-width: 600px) {
    body {
    background-color: blue;
    color: white;
    }
    }
    </style>
    </head>

    <body>
    <h1>Resize the browser window to see the effect.</h1>
    <hr>
    <h1>Media Queries techniques used to set a tailored style sheet to all
    type of devices. </h1>
    </body>
    </html>




    Responsive Menu


    Example : Media Queries

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    * {
    box-sizing: border-box;
    }
    /* Style the top navigation bar */
    .toplink {
    overflow: hidden;
    background-color: rgb(2, 8, 63);
    }
    /* Style the links */
    .toplink a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    }
    /* Change color on hover */
    .toplink a:hover {
    background-color: rgb(16, 80, 218);
    }
    /* On screens that are 600px wide or less,
    make the menu links stack on top */
    @media screen and (max-width: 600px) {
    .toplink a {
    float: none;
    width: 100%;
    }
    }
    </style>
    </head>
    <body>
    <h2>Responsive Menu</h2>
    <p>Media Queries techniques used to set a tailored style sheet to all
    type of devices.</p>
    <div class="toplink">
    <a href="/html/html.html">HTML</a>
    <a href="/css/css.html ">CSS</a>
    <a href="/javascript/javascript.html ">Java Script </a>
    </div>
    </body>
    </html>




    Responsive Div Element


    Example : Media Queries

    <!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    /* browser's width is between 600 and 900px OR above 1100px, Change the DIV. */
    @media screen and (max-width: 900px) and (min-width: 600px), (min-width: 1100px) {
    div.example{
    font-size: 50px;
    padding: 50px;
    border: 6px solid red;
    background: rgb(2, 8, 63);
    color:white;
    }
    }
    </style>
    </head>
    <body>

    <h2>Change the DIV on different screen sizes</h2>
    <div class="example">codealways.com</div>
    <p>Media Queries techniques used to set a tailored style sheet to all
    type of devices.</p>
    </body>
    </html>




    Webpage Home Page


    Example :

    <!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    * {
    box-sizing: border-box;
    }
    /* Style the body */
    body {
    font-family: Arial;
    margin: 0;
    }
    /* Header */
    .header {
    padding: 10px;
    text-align: center;
    background: white;
    color: black;
    }
    /* Style the top navigation bar */
    .mainlink {
    display: flex;
    background-color: rgb(2, 8, 63);
    }
    /* Style the navigation bar links */
    .mainlink a {
    color: white;
    padding: 14px 20px;
    text-decoration: none;
    text-align: center;
    }
    /* Change color on hover */
    .mainlink a:hover {
    background-color: blue;
    color: white;
    }
    /* Column container */
    .left {
    display: flex;
    flex-wrap: wrap;
    }
    .side {
    flex: 30%;
    background-color: #f1f1f1;
    padding: 20px;
    }
    /* Main column */
    .main {
    flex: 70%;
    background-color: white;
    padding: 20px;
    }
    /* Footer */
    .footer {
    padding: 20px;
    text-align: center;
    background: #ddd;
    }
    .Linksides a {
    text-decoration: none;
    padding: 14px 20px;
    text-align: center;
    }
    .Linksides a:hover {
    background-color: blue;
    color: white;
    }
    .Linksides {
    background: rgb(187, 184, 184);
    padding: 10px;
    border-style: line;
    color: black;
    }
    /* Responsive layout */
    @media screen and (max-width: 600px) {
    .left, .mainlink {
    flex-direction: column;
    }
    }
    </style>
    </head>
    <body>
    <div class="header">
    <h1>codealways.com</h1>
    <p>code always to become best programmer.</p>
    </div>

    <div class="mainlink">
    <a href="/html/html.html">HTML</a>
    <a href=" ">CSS</a>
    <a href=" ">Java Script </a>
    </div>

    <div class="left">
    <div class="side">
    <div class="Linksides ">
    <a href=" ">CSS - @media</a><br> <br>
    <a href=" ">CSS - Multidevice</a><br> <br>
    <a href=" ">CSS - Multidevice 1</a><br> <br>
    <a href=" ">CSS - Multidevice 2</a><br> <br>
    </div>

    </div>
    <div class="main">
    <h2>CSS - Media Queries</h2>
    <p> The most important feature of style sheet is how a document
    is to be presented in diffeent media.</p>
    <p>Media query is a w3c recommendation .</p>
    <p>Media rule makes you to set different rules for media types.</p>
    <p>Media queries also used to check :</p>
    <ui>
    <li>View point (Width and Height)</li>
    <li>Device (Width and Height)</li>
    <li>Orentation mode(Landscape and portable)</li>
    <li>resoulation</li>
    </ui>
    <br>
    <h2>Syntax : Media Queries</h2>
    <pre>
    @media not|only mediatype and (expressions) {
    CSS-Code;
    }
    </pre>
    <img alt="" src="image/backgroundimage.png" style="height:200px;" />
    <h4>Responsive background-color</h4>
    <h4>Example : Media Queries</h4>
    <pre>
    <!DOCTYPE html>
    <html>
    <head>
    <style>
    /* Default background color is yellow and
    the screen that are 600px and more ,
    the background color is yellow*/

    body {
    background-color: yellow;
    color: black;
    }
    /* On screens that are 600px wide or less,
    the background color is blue */

    @media screen and (max-width: 600px) {
    body {
    background-color: blue;
    color: white;
    }
    }
    </style>
    </head>
    <body>
    <h1>Resize the browser window to see the effect.</h1>
    <hr>
    <h1>Media Queries techniques used to set a tailored style sheet to all
    type of devices. </h1>

    </body>
    </html>
    </pre>

    </div>
    </div>

    <div class="footer">
    <h2>about codealways contact</h2>
    </div>
    </body>
    </html>