VUE Slot 样式设置无效

谷若汐

2018-10-24

有没有办法在Vue组件中设置slot的样式?

<slot style="position: absolute"></slot>

<slot class="slot"></slot>

都无效.

第83篇《VUE Slot 样式设置无效》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

1个回答
谷若汐 2018.10.24

Wrap the slot in a <div> and style the <div> instead:

<div style="...">
  <slot></slot>
</div>

If you really need to style the slot element, you can use CSS selectors like this:

<div class="wrapper">
  <slot></slot>
</div>
.wrapper > * {
  color: red;
}

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android