Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

สร้างเมนูการนำทางที่ตอบสนองด้วย CSS Media Queries


Media Queries ถูกใช้เมื่อคุณต้องการกำหนดรูปแบบให้กับอุปกรณ์ต่างๆ เช่น แท็บเล็ต มือถือ เดสก์ท็อป ฯลฯ

คุณสามารถลองเรียกใช้รหัสต่อไปนี้เพื่อสร้างเมนูการนำทางที่ตอบสนองด้วย Media Queries:

ตัวอย่าง

<!DOCTYPE html>
<html lang = "en">
   <head>
      <meta charset = "utf-8">
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <style>
         .demo {
            overflow: hidden;
            background-color: blue;
         }
         .demo a {
            float: left;
            display: block;
            color: white;
            text-align: center;
            padding: 10px;
            text-decoration: none;
         }
         @media screen and (max-width: 600px) {
            .demo a {
               float: none;
               width: 100%;
            }
         }
      </style>
   </head>
   <body>
      <p>Navigation Menu:</p>
      <div class = "demo">
         <a href = "#">Home</a>
         <a href = "#">About</a>
         <a href = "#">Tutorials</a>
         <a href = "#">QA</a>
         <a href = "#">Videos</a>
         <a href = "#">Contact</a>
      </div>
   </body>
</html>