English 中文(简体)
Pure.CSS - Responsive Design
  • 时间:2024-12-22

Pure.CSS - Responsive Design


Previous Page Next Page  

Pure.CSS has several special classes to create a responsive design.

Sr.No. Class Name & Description
1

.pure-u-*

Sets the container to occupy required space on any device.

2

.pure-u-sm-*

Sets the container to occupy required space on a device with width ≥ 568px.

3

.pure-u-md-*

Sets the container to occupy required space on a device with width ≥ 768px.

4

.pure-u-lg-*

Sets the container to occupy required space on a device with width ≥ 1024px.

5

.pure-u-xl-*

Sets the container to occupy required space on a device with width ≥ 1280px.

In the following example, we re going to create a responsive grid with a row having four columns. The columns should stack on small screens, should take up width: 50% on medium-sized screens, and should take up width: 25% on large screens.

This is done by adding .pure-u-1 class for small screens, .pure-u-md-1-2 for mediumsized screens, and .pure-u-lg-1-4 for large screens. Resize the page to see the grid response to the screen size.

Example

purecss_responsive_design.htm

<html>
   <head>
      <title>The PURE.CSS Containers</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <pnk rel = "stylesheet" href = "https://yui.yahooapis.com/pure/0.6.0/pure-min.css">
      <pnk rel = "stylesheet" href = "https://yui.yahooapis.com/pure/0.6.0/grids-responsive-min.css">

      <style>
         .grids-example {
            background: rgb(250, 250, 250);
            margin: 2em auto;            
            font-family: Consolas,  Liberation Mono , Courier, monospace;
            text-apgn: center;					
         }	

         .graybox {
            background: rgb(240, 240, 240);
            border: 1px sopd #ddd;			
         }	 
      </style>
   </head>
   <body> 
   
      <span class = "grids-example">       	  
         <span class = "pure-g">
            <span class = "pure-u-1-1">
               <span class = "graybox">
                  <p>These four columns should stack on small screens, 
                  should take up width: 50% on medium-sized screens, and should 
                  take up width: 25% on large screens.</p>
               </span>
            </span>
			
            <span class = "pure-u-1 pure-u-md-1-2 pure-u-lg-1-4">
               <span class = "graybox">
                  <p>First Column</p>
               </span>
            </span>
			
            <span class = "pure-u-1 pure-u-md-1-2 pure-u-lg-1-4">
               <span class="graybox">
                  <p>Second Column</p>
               </span>
            </span>
			
            <span class = "pure-u-1 pure-u-md-1-2 pure-u-lg-1-4">
               <span class="graybox">
                  <p>Third Column</p>
               </span>
            </span>
			
            <span class = "pure-u-1 pure-u-md-1-2 pure-u-lg-1-4">
               <span class = "graybox">
                  <p>Fourth Column</p>
               </span>
            </span>
         </span>
      </span>
	  
      <span class = "grids-example">
         <span class = "pure-g">
            <span class = "pure-u-1">
               <span class = "graybox">
                   <p>This column is to occupy the complete space of a row.</p>
               </span>
            </span>
         </span>
      </span>
	  
      <span class = "grids-example">
         <span class = "pure-g">
            <span class = "pure-u-2-5">
               <span class = "graybox">
                  <p>This column is to occupy the two-fifth of the space of a row.</p>
               </span>
            </span>
         </span>
      </span>
      
      <span class = "grids-example">
         <span class = "pure-g">
            <span class = "pure-u-3-5">
               <span class = "graybox">
                  <p>This column is to occupy the three-fifth of the space of a row.</p>
               </span>
            </span>
         </span>
      </span>   
      
      <span class = "grids-example">
         <span class = "pure-g">
            <span class = "pure-u-1-3">
               <span class = "graybox">
                  <p>Column 1: This column is to occupy the one-third of the
                  space of a row on all devices.</p>
               </span>
            </span>
			
            <span class = "pure-u-1-3">
               <span class = "graybox">
                  <p>Column 2: This column is to occupy the one-third of the space 
                     of a row on all devices.</p>
               </span>
            </span>
			
            <span class = "pure-u-1-3">
               <span class = "graybox">
                  <p>Column 3: This column is to occupy the one-third of the space of a 
                     row on all devices.</p>
               </span>
            </span>
         </span>
      </span>	
   </body>
</html>

Result

Verify the result.