Panduan Pengguna Batal

Create media queries

 

 

You can use media queries to specify CSS files based on the reported characteristics of a device (responsive design). The browser on a device checks the media query and uses the corresponding CSS file to display the web page.

For example, the following media query specifies the phone.css file for devices that are 300-320 pixels wide.

<link href="css/orig/phone.css" rel="stylesheet" type="text/css" media="all and (min-width: 300px) and (max-width: 320px)">
<link href="css/orig/phone.css" rel="stylesheet" type="text/css" media="all and (min-width: 300px) and (max-width: 320px)">
<link href="css/orig/phone.css" rel="stylesheet" type="text/css" media="all and (min-width: 300px) and (max-width: 320px)">

For an extensive introduction to media queries see Don Booth’s article on the Adobe Developer Center www.adobe.com/go/learn_dw_medquery_don_en.

For more information on media queries from the W3C see www.w3.org/TR/css3-mediaqueries/.

Create a media query

In Dreamweaver, you can create a site-wide media query file, or a document-specific media query.

Site-wide media query file

Specifies display settings for all pages in your site that include the file.

The site-wide media query file acts as the central repository for all media queries in your site. After you create this file, link to it from pages in your site that must use the media queries in the file for their display.

Document-specific media query

The media query is inserted directly into the document, and the page is displayed based on the inserted media query.

  1. Create a web page.

  2. Select Modify > Media Queries.

  3. Do one of the following:

    • To create a site-wide media query file, select Site Wide Media Queries File.

    • To create a document-specific media query, select This Document.

  4. For site-wide media query, do the following:

    1. Click Specify.

    2. Select Create New File.

    3. Specify a name for the file, and click OK.

  5. It is possible that some devices do not report their actual width. To force devices to report their actual width, ensure that the option Force Devices To Report Actual Width is enabled.

    The following code is inserted into your file when you choose this option.

    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="width=device-width">
  6. Do one of the following:

    • Click "+" to define the properties for the media query file.

    • Click Default Presets if you want to begin with standard presets.

  7. Select rows in the table, and edit their properties using the options under Properties.

    Description

    The description of the device for which the CSS file must be used. For example, phone, TV, tablet, and so on.

    Min Width and Max width

    The CSS file is used for devices whose reported width is within the specified values.

    Nota:

    Leave either Min Width or Max Width blank if you do not want to specify an explicit range for a device. For example, it is common to leave Min Width blank if you want to target phones, which are 320px wide, or less.

    CSS file

    Select Use Existing File, and browse to the CSS file for the device.

    If you want to specify a CSS file that you are yet to create, select Create New File. Enter the name of the CSS file. The file is created when you press OK.

  8. Click OK.

  9. For site-wide media query, a new file is created. Save it.

Site-wide media query: For existing pages, ensure that you include the media query file in all the pages in the <head> tag.

Example of a media query link where mediaquery_adobedotcom.css is the site-wide media query file for the site www.adobe.com:

<link href="mediaquery_adobedotcom.css" rel="stylesheet" type="text/css">
<link href="mediaquery_adobedotcom.css" rel="stylesheet" type="text/css">
<link href="mediaquery_adobedotcom.css" rel="stylesheet" type="text/css">

Use an existing media queries file

  1. Create a web page, or open an existing page.

  2. Select Modify > Media Queries.

  3. Select Site-Wide Media Queries File.

  4. Click Specify.

  5. Select Use Existing File if you have already created a CSS file with the Media Query.

  6. Click the browse icon to navigate to, and specify the file. Click OK.

  7. Select Site-Wide Media Queries File.

  8. To force devices to report their actual width, ensure that the option Force Devices To Report Actual Width is enabled. The following code is inserted into your file when you choose this option.

    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content="width=device-width">
  9. Click OK.

Choose a different site-wide media queries file

Use this procedure to change the site-wide media queries file that you have set in the Media Queries dialog box.

  1. Select Site > Manage Sites.

  2. In the Manage Sites dialog, select your site.

  3. Click Edit. The Site Setup dialog box is displayed.

  4. Under Advanced Settings in the left panel, select Local Info.

  5. In Site-Wide Media Query File on the right panel, click Browse to select the media query CSS file.

    Nota:

    Changing the site-wide media queries file does not affect documents linked to a different or previous site-wide media query file.

  6. Click Save.

View web pages based on media query

Dimensions specified in a media query appear in the options for Multiscreen button/window size. When you select a dimension from the menu, the following changes are seen:

  • The view size changes to reflect the specified dimensions. The document frame size is unaltered.

  • The CSS file specified in the media query is used to display the page.

Dapatkan bantuan dengan lebih pantas dan mudah

Pengguna baharu?