2014-10-22 38 views
1

我正在嘗試創建一個包含核心頭部面板的「my-app」元素。看起來人們會想要爲SPA做一件很常見的事情。另一個元素內部的聚合物核心頭部面板

我的index.html:

<!DOCTYPE html> 
<html> 
<head>   
    <script src="bower_components/platform/platform.js"></script> 
    <link rel="import" href="elements/my-app.html"> 
</head> 
<body fullbleed layout vertical unresolved> 
    <my-app></my-app> 
</body> 
</html> 

與我-app.html:

<link rel="import" href="/bower_components/polymer/polymer.html"> 
<link rel="import" href="/bower_components/core-toolbar/core-toolbar.html"> 
<link rel="import" href="/bower_components/paper-tabs/paper-tabs.html"> 
<link rel="import" href="/bower_components/core-header-panel/core-header-panel.html"> 

<polymer-element name="my-app"> 
    <template> 

     <core-header-panel flex> 
      <core-toolbar> 
       <div>Hello World!</div> 
      </core-toolbar> 
     </core-header-panel> 

    </template> 
    <script src="my-app.js"></script> 
</polymer-element> 

,但我似乎得到的是:

enter image description here

什麼想法?

編輯:我已經改變了我的代碼,與聚合物文檔(https://www.polymer-project.org/docs/elements/core-elements.html#core-header-panel)上的第一個例子完全相同,只是核心頁眉面板在另一個元素內,而不是直接在主體內部。

EDIT2:如果禁用現在的位置是:相對核心頭面板上,然後它看起來更好:enter image description here

回答

2

你需要明確地設置core-header-panel的高度。可以使用佈局屬性:

<body fullbleed layout vertical> <core-header-panel flex>

或CSS:

html, body { height: 100%; margin: 0; } core-header-panel { height: 100%; }

這在覈心報頭面板API文檔中描述:

https://www.polymer-project.org/docs/elements/core-elements.html#core-header-panel

編輯:我沒有想出正確的咒語,使柔性佈局屬性瓦特ork在你的自定義元素中。但是,你應該能夠在my-app.html明確設置高度:

<template> <style> :host, core-header-panel { height: 100%; } </style>

或者,你可以使用:

core-header-panel { height: 100vh; }

前者解決方案需要您設置在一個明確的高度body元素是my-app的父元素。後一種解決方案不會,它只是使用窗口高度。

+1

我試過了,它沒有工作:(我已經編輯我的問題是完全相同的聚合物文檔的例子,除了它在另一個組件內,但它仍然沒有工作.. – mikeysee 2014-10-22 23:00:02

+0

嗯。我不知道爲什麼flex屬性是不是在這種情況下工作 但是,如果你離開'index.html'您可以在'我-app.html'設置的樣式: