【问题标题】:I want to use grid.css In reactjs我想在 reactjs 中使用 grid.css
【发布时间】:2020-09-10 06:50:54
【问题描述】:

我想在 reactjs 中使用 grid.css,就像我在普通 HTML 和 CSS 中使用的一样。

<head>
  <link rel="stylesheet" type="text/css" href="./vendors/css/grid.css">
</head>

我在这里用过,效果很好。

<div class="col span-1-of-4 box">
  <ion-icon name="infinite-outline" class="icon-big"></ion-icon>
  <h3>Up to 365 days/year</h3>
  <p>Never cook again! We really mean that. Our subscription plans include up to 365 days/year coverage. You can also choose to order more flexibly if that's your style.</p>
</div>

现在我想在 Reactjs 中使用同样的东西。

这是我的 Grid.css

/*  SECTIONS  ============================================================================= */

.section {
    clear: both;
    padding: 0px;
    margin: 0px;
}

/*  GROUPING  ============================================================================= */

.row {
    zoom: 1; /* For IE 6/7 (trigger hasLayout) */
}

.row:before,
.row:after {
    content:"";
    display:table;
}
.row:after {
    clear:both;
}

/*  GRID COLUMN SETUP   ==================================================================== */

.col {
    display: block;
    float:left;
    margin: 1% 0 1% 1.6%;
}

.col:first-child { margin-left: 0; } /* all browsers except IE6 and lower */


/*  REMOVE MARGINS AS ALL GO FULL WIDTH AT 480 PIXELS */

@media only screen and (max-width: 480px) {
    .col { 
        /*margin: 1% 0 1% 0%;*/
        margin: 0;
    }
}


/*  GRID OF TWO   ============================================================================= */


.span-2-of-2 {
    width: 100%;
}

.span-1-of-2 {
    width: 49.2%;
}

/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-2-of-2 {
        width: 100%; 
    }
    .span-1-of-2 {
        width: 100%; 
    }
}


/*  GRID OF THREE   ============================================================================= */


.span-3-of-3 {
    width: 100%; 
}

.span-2-of-3 {
    width: 66.13%; 
}

.span-1-of-3 {
    width: 32.26%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-3-of-3 {
        width: 100%; 
    }
    .span-2-of-3 {
        width: 100%; 
    }
    .span-1-of-3 {
        width: 100%;
    }
}

/*  GRID OF FOUR   ============================================================================= */


.span-4-of-4 {
    width: 100%; 
}

.span-3-of-4 {
    width: 74.6%; 
}

.span-2-of-4 {
    width: 49.2%; 
}

.span-1-of-4 {
    width: 23.8%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-4-of-4 {
        width: 100%; 
    }
    .span-3-of-4 {
        width: 100%; 
    }
    .span-2-of-4 {
        width: 100%; 
    }
    .span-1-of-4 {
        width: 100%; 
    }
}


/*  GRID OF FIVE   ============================================================================= */


.span-5-of-5 {
    width: 100%;
}

.span-4-of-5 {
    width: 79.68%; 
}

.span-3-of-5 {
    width: 59.36%; 
}

.span-2-of-5 {
    width: 39.04%;
}

.span-1-of-5 {
    width: 18.72%;
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-5-of-5 {
        width: 100%; 
    }
    .span-4-of-5 {
        width: 100%; 
    }
    .span-3-of-5 {
        width: 100%; 
    }
    .span-2-of-5 {
        width: 100%; 
    }
    .span-1-of-5 {
        width: 100%; 
    }
}


/*  GRID OF SIX   ============================================================================= */


.span-6-of-6 {
    width: 100%;
}

.span-5-of-6 {
    width: 83.06%;
}

.span-4-of-6 {
    width: 66.13%;
}

.span-3-of-6 {
    width: 49.2%;
}

.span-2-of-6 {
    width: 32.26%;
}

.span-1-of-6 {
    width: 15.33%;
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-6-of-6 {
        width: 100%; 
    }
    .span-5-of-6 {
        width: 100%; 
    }
    .span-4-of-6 {
        width: 100%; 
    }
    .span-3-of-6 {
        width: 100%; 
    }
    .span-2-of-6 {
        width: 100%; 
    }
    .span-1-of-6 {
        width: 100%; 
    }
}



/*  GRID OF SEVEN   ============================================================================= */


.span-7-of-7 {
    width: 100%;
}

.span-6-of-7 {
    width: 85.48%;
}

.span-5-of-7 {
    width: 70.97%;
}

.span-4-of-7 {
    width: 56.45%;
}

.span-3-of-7 {
    width: 41.94%;
}

.span-2-of-7 {
    width: 27.42%;
}

.span-1-of-7 {
    width: 12.91%;
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-7-of-7 {
        width: 100%; 
    }
    .span-6-of-7 {
        width: 100%; 
    }
    .span-5-of-7 {
        width: 100%; 
    }
    .span-4-of-7 {
        width: 100%; 
    }
    .span-3-of-7 {
        width: 100%; 
    }
    .span-2-of-7 {
        width: 100%; 
    }
    .span-1-of-7 {
        width: 100%; 
    }
}


/*  GRID OF EIGHT   ============================================================================= */


.span-8-of-8 {
    width: 100%;
}

.span-7-of-8 {
    width: 87.3%; 
}

.span-6-of-8 {
    width: 74.6%; 
}

.span-5-of-8 {
    width: 61.9%; 
}

.span-4-of-8 {
    width: 49.2%; 
}

.span-3-of-8 {
    width: 36.5%;
}

.span-2-of-8 {
    width: 23.8%; 
}

.span-1-of-8 {
    width: 11.1%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-8-of-8 {
        width: 100%; 
    }
    .span-7-of-8 {
        width: 100%; 
    }
    .span-6-of-8 {
        width: 100%; 
    }
    .span-5-of-8 {
        width: 100%; 
    }
    .span-4-of-8 {
        width: 100%; 
    }
    .span-3-of-8 {
        width: 100%; 
    }
    .span-2-of-8 {
        width: 100%; 
    }
    .span-1-of-8 {
        width: 100%; 
    }
}


/*  GRID OF NINE   ============================================================================= */


.span-9-of-9 {
    width: 100%;
}

.span-8-of-9 {
    width: 88.71%;
}

.span-7-of-9 {
    width: 77.42%; 
}

.span-6-of-9 {
    width: 66.13%; 
}

.span-5-of-9 {
    width: 54.84%; 
}

.span-4-of-9 {
    width: 43.55%; 
}

.span-3-of-9 {
    width: 32.26%;
}

.span-2-of-9 {
    width: 20.97%; 
}

.span-1-of-9 {
    width: 9.68%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-9-of-9 {
        width: 100%; 
    }
    .span-8-of-9 {
        width: 100%; 
    }
    .span-7-of-9 {
        width: 100%; 
    }
    .span-6-of-9 {
        width: 100%; 
    }
    .span-5-of-9 {
        width: 100%; 
    }
    .span-4-of-9 {
        width: 100%; 
    }
    .span-3-of-9 {
        width: 100%; 
    }
    .span-2-of-9 {
        width: 100%; 
    }
    .span-1-of-9 {
        width: 100%; 
    }
}


/*  GRID OF TEN   ============================================================================= */


.span-10-of-10 {
    width: 100%;
}

.span-9-of-10 {
    width: 89.84%;
}

.span-8-of-10 {
    width: 79.68%;
}

.span-7-of-10 {
    width: 69.52%; 
}

.span-6-of-10 {
    width: 59.36%; 
}

.span-5-of-10 {
    width: 49.2%; 
}

.span-4-of-10 {
    width: 39.04%; 
}

.span-3-of-10 {
    width: 28.88%;
}

.span-2-of-10 {
    width: 18.72%; 
}

.span-1-of-10 {
    width: 8.56%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-10-of-10 {
        width: 100%; 
    }
    .span-9-of-10 {
        width: 100%; 
    }
    .span-8-of-10 {
        width: 100%; 
    }
    .span-7-of-10 {
        width: 100%; 
    }
    .span-6-of-10 {
        width: 100%; 
    }
    .span-5-of-10 {
        width: 100%; 
    }
    .span-4-of-10 {
        width: 100%; 
    }
    .span-3-of-10 {
        width: 100%; 
    }
    .span-2-of-10 {
        width: 100%; 
    }
    .span-1-of-10 {
        width: 100%; 
    }
}


/*  GRID OF ELEVEN   ============================================================================= */

.span-11-of-11 {
    width: 100%;
}

.span-10-of-11 {
    width: 90.76%;
}

.span-9-of-11 {
    width: 81.52%;
}

.span-8-of-11 {
    width: 72.29%;
}

.span-7-of-11 {
    width: 63.05%; 
}

.span-6-of-11 {
    width: 53.81%; 
}

.span-5-of-11 {
    width: 44.58%; 
}

.span-4-of-11 {
    width: 35.34%; 
}

.span-3-of-11 {
    width: 26.1%;
}

.span-2-of-11 {
    width: 16.87%; 
}

.span-1-of-11 {
    width: 7.63%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-11-of-11 {
        width: 100%; 
    }
    .span-10-of-11 {
        width: 100%; 
    }
    .span-9-of-11 {
        width: 100%; 
    }
    .span-8-of-11 {
        width: 100%; 
    }
    .span-7-of-11 {
        width: 100%; 
    }
    .span-6-of-11 {
        width: 100%; 
    }
    .span-5-of-11 {
        width: 100%; 
    }
    .span-4-of-11 {
        width: 100%; 
    }
    .span-3-of-11 {
        width: 100%; 
    }
    .span-2-of-11 {
        width: 100%; 
    }
    .span-1-of-11 {
        width: 100%; 
    }
}


/*  GRID OF TWELVE   ============================================================================= */

.span-12-of-12 {
    width: 100%;
}

.span-11-of-12 {
    width: 91.53%;
}

.span-10-of-12 {
    width: 83.06%;
}

.span-9-of-12 {
    width: 74.6%;
}

.span-8-of-12 {
    width: 66.13%;
}

.span-7-of-12 {
    width: 57.66%; 
}

.span-6-of-12 {
    width: 49.2%; 
}

.span-5-of-12 {
    width: 40.73%; 
}

.span-4-of-12 {
    width: 32.26%; 
}

.span-3-of-12 {
    width: 23.8%;
}

.span-2-of-12 {
    width: 15.33%; 
}

.span-1-of-12 {
    width: 6.86%; 
}


/*  GO FULL WIDTH AT LESS THAN 480 PIXELS */

@media only screen and (max-width: 480px) {
    .span-12-of-12 {
        width: 100%; 
    }
    .span-11-of-12 {
        width: 100%; 
    }
    .span-10-of-12 {
        width: 100%; 
    }
    .span-9-of-12 {
        width: 100%; 
    }
    .span-8-of-12 {
        width: 100%; 
    }
    .span-7-of-12 {
        width: 100%; 
    }
    .span-6-of-12 {
        width: 100%; 
    }
    .span-5-of-12 {
        width: 100%; 
    }
    .span-4-of-12 {
        width: 100%; 
    }
    .span-3-of-12 {
        width: 100%; 
    }
    .span-2-of-12 {
        width: 100%; 
    }
    .span-1-of-12 {
        width: 100%; 
    }
}
import classes from './App.module.css';
import Logo from './bg-image.svg';
import grid from './assets/css/Grid.css';


class App extends Component {

  state= {
    showDay : false
  }

  showDayHandler = () =>{
    const day = this.state.showDay;
    this.setState({
      showDay: !day
    });
  }


  render(){
    let date = new Date();
    let time = date.toLocaleTimeString();

    let showDetail = false;
    if(this.state.showDay){
      const day = date.toLocaleDateString();
      showDetail = (day);
    }

    return (
      <div className={classes.App}>
          <h1 className={classes.h1}>Your Time is here </h1>
          <img  src={Logo} width="500" height="600" className={`${grid.col} ${grid.span-1-of-2}`}/>
          <button className={`${classes.btn} ${classes.some}`} onClick={this.showDayHandler}> Choose me! </button>
          <div className={classes.time}>
            <div>{time}</div>
            <div>{showDetail}</div>
          </div>
      </div>
    );
  }
}

export default App;

但它给出了这样的错误

./src/App.js 第 34:91 行:'of' 未定义为 no-under

搜索关键字以了解有关每个错误的更多信息。

请指导我

【问题讨论】:

  • 您的&lt;img src={logo}... 是您收到错误的行吗?我不知道网格是如何工作的,但你给你的className 一个对象,你不只需要写${grid.col} ${grid.span-1-of-2} 包含特殊引号而不是{ }?否则,请向我们提供更多代码以及出现错误的位置。

标签: javascript css reactjs styling


【解决方案1】:

${grid.span-1-of-2}在JavaScript中不是一个正确的标识符,实际上它的意思是“取grid.span的值,减去1,减去of的值,再减去2”。

假设你的类是这样命名的,它应该是${grid['span-1-of-2']}

【讨论】:

    猜你喜欢
    • 2021-08-02
    • 2021-06-08
    • 1970-01-01
    • 2021-04-21
    • 2019-05-02
    • 2019-04-26
    • 2018-09-30
    • 2022-12-18
    • 2023-01-20
    相关资源
    最近更新 更多