基础网格系统不起作用

Any*_*are 6 css sass zurb-foundation reactjs webpack

为什么基础网格系统不会影响我的div:

  render: function(){
    var {todos,showCompleted,searchText} = this.state;
    var filteredTodos = TodoAPI.filterTodos(todos,showCompleted,searchText);
    return (
      <div>
        <h1 className="page-title">Todo App</h1>

        <div className="row">
          <div className="column small-centered small-5 medium-6 large-5">
            <div className="container">
              <TodoSearch onSearch = {this.handleSearch} />
              <TodoList todos ={filteredTodos} onToggle ={this.handleToggle}/>
              <AddTodo onAddTodo ={this.handleAddTodo}/>
            </div>
         </div>
       </div>
      </div>
    );
  }
Run Code Online (Sandbox Code Playgroud)

我使用firebug来调试样式:并且找不到:

.large-5 {
    width: 33.3333%;
}
Run Code Online (Sandbox Code Playgroud)

这个项目的回购就在这里

Dan*_*rei 2

您应该将基础导入为

@import '~foundation-sites/scss/foundation';
Run Code Online (Sandbox Code Playgroud)

由于您的 webpack.config 中已经包含了 includePath

经过一段时间的调试,我发现问题是foundation-everything mixin默认包含另一种网格样式

@mixin foundation-everything(
  $flex: true, //You can test this by modifying it directly in your node_modules, set it to false
  $prototype: false
) {
  @if $flex {
    $global-flexbox: true !global;
  }

  @include foundation-global-styles;
  @if not $flex {
    @include foundation-grid;
  }
  @else {
    @if $xy-grid {
      @include foundation-xy-grid-classes;
    }
    @else {
      @include foundation-flex-grid;
    }
  }
  //more scss here
)
Run Code Online (Sandbox Code Playgroud)

这就是为什么您的类不应用预期样式的原因,因为不同的类是根据Foundation-Everything mixin 生成的(特别是生成 XY 网格,而不是您期望的Foundation-grid)。

您可以通过不同的方式来解决这个问题,具体取决于您的应用程序。

1) 您可以在项目中包含您所需的一组确切的基础样式。(我的推荐)

2)以某种方式改变mixin(我不认为动态导入是一件事?(https://github.com/sass/sass/issues/279

可能还有其他选项,例如:生成 css 一次并将其直接包含在您的应用程序中或使用react-foundation 包。同样,这取决于您的需要。