Пользовательский элемент: граница хоста - PullRequest
0 голосов
/ 14 апреля 2019

Не можете понять, почему черная граница :host не проходит вокруг теневого корня, содержащего svg-границу красного цвета?

<!doctype html>
<html>
  <head>
    <title>HelloWorld</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"/>
    <meta name="mobile-web-app-capable" content="yes">
    <style>
      html, body {
        padding: 0;
        margin: 0;
      }
    </style>
    <script type="module">
      import {html, render} from 'https://unpkg.com/lit-html'
      class HelloWorld extends HTMLElement {
        constructor() {
          super()
          this.attachShadow({mode: 'open'});
        }
        connectedCallback() {
          render(html`
            <style>
              :host {
                width: 24px;
                height: 24px;
                border: 1px solid black;
              }
              svg {
                border: 1px solid red;
              }
            </style>
            <svg viewBox="0 0 24 24" width="24" heigth="24">
              <g><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></g>
            </svg>
          `, this.shadowRoot)
        }
      }
      customElements.define('hello-world', HelloWorld)
    </script>
  </head>
  <body>
    <hello-world></hello-world>
  </body>
</html>

1 Ответ

1 голос
/ 14 апреля 2019

Doh!забыл добавить display:block;

<!doctype html>
<html>
  <head>
    <title>HelloWorld</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"/>
    <meta name="mobile-web-app-capable" content="yes">
    <style>
      html, body {
        padding: 0;
        margin: 0;
      }
    </style>
    <script type="module">
      import {html, render} from 'https://unpkg.com/lit-html'
      class HelloWorld extends HTMLElement {
        constructor() {
          super()
          this.attachShadow({mode: 'open'});
        }
        connectedCallback() {
          render(html`
            <style>
              :host {
                display: block;
                width: 24px;
                height: 24px;
                border: 1px solid black;
              }
              svg {
                border: 1px solid red;
              }
            </style>
            <svg viewBox="0 0 24 24" width="24" heigth="24">
              <g><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></g>
            </svg>
          `, this.shadowRoot)
        }
      }
      customElements.define('hello-world', HelloWorld)
    </script>
  </head>
  <body>
    <hello-world></hello-world>
  </body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...