2017-08-07 22 views
1

我有一個app-drawer-layout元素,在其中,我希望抽屜內容(藍色)與主要內容(黃色)齊平,並且它們之間沒有間隙(白色)。請注意,我將--app-drawer-width從其默認256px更改爲100px。這可能是造成差距的原因。這是一個錯誤?或者我編碼錯了?如何關閉聚合物2.x中應用程序抽屜佈局中抽屜與主要內容之間的差距?

Here is the JSBin.注意:查看演示時,確保輸出窗格滑得足夠寬以使抽屜可見。如果輸出窗格太窄,抽屜將被隱藏。

應用抽屜佈局

enter image description here

http://jsbin.com/lulenamavo/edit?html,output
<!DOCTYPE html> 
<html> 

<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width"> 
    <title>JS Bin</title> 

    <base href="http://polygit.org/polymer+:master/components/"> 
    <link rel="import" href="polymer/polymer-element.html"> 
    <link rel="import" href="app-layout/app-layout.html"> 

</head> 

<body> 
    <dom-module id="my-el"> 
    <template> 
     <style> 
     app-drawer { 
      --app-drawer-width: 100px; 
      --app-drawer-content-container: { 
      background-color: blue; 
      color: white; 
      } 
     } 
     #main-content { 
      background-color: yellow; 
      height: 100vh; 
      width: 100vw; /* doesn't make content sections flush */ 
     } 
     </style> 
     <app-drawer-layout fullbleed> 
     <app-drawer slot="drawer"> 
      drawer content 
     </app-drawer> 
     <div id="main-content"> 
      main content 
     </div> 
     </app-drawer-layout> 
    </template> 
    <script> 
     class MyEl extends Polymer.Element { 
     static get is() { 
      return 'my-el' 
     } 
     } 
     customElements.define(MyEl.is, MyEl); 
    </script> 
    </dom-module> 

    <my-el></my-el> 
</body> 

</html> 

回答

1

這是不是一個錯誤。可能,您錯過了閱讀documentation中的備註

注意:*如果您在使用和--app-drawer-width, 該值必須是由兩個元素訪問指定的值。這可以通過 來完成對包含:host限定值(或html如果 陰影根外):

:host { --app-drawer-width: 300px; }

在這種情況下,這將是:

<style> 
    :host { 
    --app-drawer-width: 100px; 
    } 
</style> 
1

For clarity, here is the fully coded solution demo.

http://jsbin.com/jodifafuqa/edit?html,output
<!DOCTYPE html> 
<html> 

<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width"> 
    <title>JS Bin</title> 

    <base href="http://polygit.org/polymer+:master/components/"> 
    <link rel="import" href="polymer/polymer-element.html"> 
    <link rel="import" href="app-layout/app-layout.html"> 

</head> 

<body> 
    <dom-module id="my-el"> 
    <template> 
     <style> 
     :host { 
      --app-drawer-width: 100px; 
     } 
     app-drawer { 
      --app-drawer-content-container: { 
      background-color: blue; 
      color: white; 
      } 
     } 
     #main-content { 
      background-color: yellow; 
      height: 100vh; 
      width: 100vw; /* doesn't make content sections flush */ 
     } 
     </style> 
     <app-drawer-layout fullbleed> 
     <app-drawer slot="drawer"> 
      drawer content 
     </app-drawer> 
     <div id="main-content"> 
      main content 
     </div> 
     </app-drawer-layout> 
    </template> 
    <script> 
     class MyEl extends Polymer.Element { 
     static get is() { 
      return 'my-el' 
     } 
     } 
     customElements.define(MyEl.is, MyEl); 
    </script> 
    </dom-module> 

    <my-el></my-el> 
</body> 

</html> 
相關問題