【问题标题】:Linked Stylesheet Error - Resource interpreted as Stylesheet but transferred with MIME type text/plain链接样式表错误 - 资源解释为样式表,但使用 MIME 类型文本/纯文本传输
【发布时间】:2017-11-13 23:23:21
【问题描述】:

按照基本的 React 教程 (https://www.fullstackreact.com),但由于控制台中的此错误,我无法让给定的样式表正常工作。

这是我目前所拥有的完整来源 -

    <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Timeline</title>
  <link href="https://gist.githubusercontent.com/auser/2bc34b9abf07f34f602dccd6ca855df1/raw/40c5e7c8cad4c6920fed940fc31cbb63abd94c29/timeline.css" rel="stylesheet" type="text/css" />
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

  <!-- Script tags including React -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

</head>
<body>
  <div class="demo">
    <div id="app"></div>
  </div>
  <script type="text/babel">
    class App extends React.Component {
        render() {
            return (
            <div className="notificationsFrame">
                <div className="panel">
                    <Header />
                </div>
            </div>
            )
        }
    }


    class Header extends React.Component {
        render() {
            return (
            <div className="header">
                <div className="fa fa-more"></div>

                <span className="title">Timeline</span>

                <input
                type="text"
                className="searchInput"
                placeholder="Search ..." />

                <div className="fa fa-search searchIcon"></div>
            </div>
            )
        }
    }

        var mount = document.querySelector('#app');
        ReactDOM.render(<App />, mount);
  </script>
</body>
</html>

我已经检查了开发工具和timeline.css,我认为请求标头中有“Accept:text/css”,我认为这是正确的。我不知道为什么它会被转移到不同的类型?这个问题之前有人问过,但答案似乎都在说与请求类型有关的东西不正确,但我看不到在哪里。

【问题讨论】:

  • 你给出什么样的错误?
  • 这是我控制台中的警告 - “资源解释为样式表,但使用 MIME 类型文本/纯文本传输”指的是我页面顶部链接的时间线.css 文件。
  • 如果我解决了您的问题,请告诉我 :)

标签: javascript html css reactjs


【解决方案1】:

网站站长阻止所有脚本和样式表。 这是一项避免 MIME 类型混淆攻击的安全功能。

欲了解更多信息,请访问:mozilla developer

解决方案:

在其他 CDN 中更改您的样式表 timeline.css 或在您的主机或 html 页面中输入 例如:your code

或者这个:

<html>
<head>
  <meta charset="utf-8">
  <title>Timeline</title>
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />

  <!-- Script tags including React -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.1/react-dom.min.js"></script>
  <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>

</head>
  <style>
    .demo {
  position: relative;
}
.demo .notificationsFrame {
  z-index: 2;
  width: 100%;
  top: 20px;
  background: #fff;
  border-radius: 3px;
  overflow: hidden;
  font-family: 'Open Sans', Helvetica, sans-serif;
  margin-bottom: 40px;
}
.demo .notificationsFrame.show-menu {
  transform: translate3d(150px, 0, 0);
}
.demo .notificationsFrame .searchInput {
  border: 10px solid red;
  box-sizing: border-box;
  position: absolute;
  top: 13px;
  right: 55px;
  width: 200px;
  height: 34px;
  border-radius: 17px;
  border: none;
  background: #fff;
  padding: 0 17px;
  font-size: 13px;
  color: #666;
  transition: all 0.3s ease-in-out;
  transform: translateX(15px);
  opacity: 0;
  pointer-events: none;
}
.demo .notificationsFrame .searchInput:focus {
  outline: none;
}
.demo .notificationsFrame .searchInput.active {
  -webkit-transform: translateX(0);
  transform: translateX(0);
  opacity: 1;
  pointer-events: all;
}
.demo .notificationsFrame .header {
  position: relative;
  height: 60px;
  background: #5f98cd;
  padding-top: 0;
}
.demo .notificationsFrame .header .menuIcon {
  position: absolute;
  width: 29px;
  height: 15px;
  top: 23px;
  left: 20px;
  cursor: pointer;
}
.demo .notificationsFrame .header .menuIcon:hover .dashTop, .demo .notificationsFrame .header .menuIcon:hover .dashBottom, .demo .notificationsFrame .header .menuIcon:hover .circle {
  background: #fff;
}
.demo .notificationsFrame .header .menuIcon .dashTop {
  position: absolute;
  width: 20px;
  height: 3px;
  top: 0;
  left: 0;
  background: #b2daff;
  border-radius: 3px;
  -webkit-transition: all 0.2s ease-in-out;
  transition: all 0.2s ease-in-out;
}
.demo .notificationsFrame .header .menuIcon .dashBottom {
  position: absolute;
  width: 20px;
  height: 3px;
  top: 0;
  left: 0;
  background: #b2daff;
  border-radius: 3px;
  -webkit-transition: all 0.2s ease-in-out;
  transition: all 0.2s ease-in-out;
  width: 29px;
  top: auto;
  bottom: 0;
}
.demo .notificationsFrame .header .menuIcon .circle {
  position: absolute;
  height: 7px;
  width: 7px;
  border-radius: 4px;
  top: -2px;
  right: 0;
  background: #b2daff;
  -webkit-transition: all 0.2s ease-in-out;
  transition: all 0.2s ease-in-out;
}
.demo .notificationsFrame .header .title {
  display: block;
  text-align: center;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
}
.demo .notificationsFrame .header .searchIcon {
  position: absolute;
  z-index: 3;
  font-size: 21px;
  color: #fff;
  top: 18px;
  right: 20px;
  -webkit-transition: all 0.3s ease;
  transition: all 0.3s ease;
  cursor: pointer;
}
.demo .notificationsFrame .header .searchIcon:hover {
  color: #fff;
}
.demo .notificationsFrame .content {
  position: relative;
  height: 100%;
  overflow: hidden;
}
.demo .notificationsFrame .content .line {
  position: absolute;
  top: 0;
  left: 40px;
  bottom: 0;
  width: 3px;
  background: #ebebeb;
}
.demo .notificationsFrame .content .item {
  position: relative;
  z-index: 2;
  margin: 20px 30px 30px 70px;
  display: block;
  /*border-radius: 50%;
   border: 5px solid #ecf0f1;
   box-sizing: border-box;
   position: absolute;
   height: 20px;
   width: 20px;
   background: #fff;
   border: 2px solid #5F98CD;
   box-shadow: 0 0 0 3px #fff;*/
}
.demo .notificationsFrame .content .item:hover {
  color: #5f98cd;
  cursor: pointer;
}
.demo .notificationsFrame .content .item .circle {
  box-sizing: border-box;
  position: absolute;
  height: 11px;
  width: 11px;
  background: #fff;
  border: 2px solid #5f98cd;
  box-shadow: 0 0 0 3px #fff;
  border-radius: 6px;
  top: 0;
  left: -20px;
}
.demo .notificationsFrame .content .item .avatar {
  position: absolute;
  height: 40px;
  width: 40px;
  display: inline-block;
  vertical-align: top;
  overflow: hidden;
  left: -49px;
}
.demo .notificationsFrame .content .item .avatar img {
  width: 100%;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  -ms-border-radius: 50%;
  -o-border-radius: 50%;
  border-radius: 50%;
  position: absolute;
  left: 0;
  top: 0;
}
.demo .notificationsFrame .content .item .time {
  display: block;
  font-size: 11px;
  line-height: 11px;
  margin-bottom: 2px;
}
.demo .notificationsFrame .content .item p {
  font-size: 15px;
  line-height: 20px;
  margin: 0px 40px 0px 0px;
  font-family: 'Open Sans', Lora, Times, no-serif;
}
.demo .notificationsFrame .content .item p b {
  font-weight: 600;
}
.demo .notificationsFrame .content .item .right {
  position: absolute;
  right: 5px;
  font-size: 11px;
  top: 11px;
}
.demo .notificationsFrame .content .item .commentCount {
  position: absolute;
  right: 15px;
  font-size: 12px;
  top: 11px;
}
.demo .notificationsFrame .content .item .commentCount:after {
  content: "\f075";
  font-family: FontAwesome;
  position: absolute;
  font-size: 20px;
  color: #ebebeb;
  top: -50%;
  left: 100%;
  margin-left: 10px;
  z-index: 3;
}
.demo .notificationsFrame .content .item .commentCount:hover:after {
  color: lightblue;
}
.demo .notificationsFrame .footer {
  position: relative;
  background: #fff;
  margin: auto;
  height: 30px;
  border-top: 1px solid #eee;
  width: 100%;
  border-radius: 10px;
}
.demo .notificationsFrame .footer button {
  background: #eee;
  position: absolute;
  width: 100%;
  right: 0px;
  left: 0px;
  top: 0px;
  bottom: 0px;
  border: 0;
}
.demo .notificationsFrame .footer button i {
  margin: 0 10px;
}

  </style>
<body>
  <div class="demo">
    <div id="app"></div>
  </div>
  <script type="text/babel">
    class App extends React.Component {
        render() {
            return (
            <div className="notificationsFrame">
                <div className="panel">
                    <Header />
                </div>
            </div>
            )
        }
    }


    class Header extends React.Component {
        render() {
            return (
            <div className="header">
                <div className="fa fa-more"></div>

                <span className="title">Timeline</span>

                <input
                type="text"
                className="searchInput"
                placeholder="Search ..." />

                <div className="fa fa-search searchIcon"></div>
            </div>
            )
        }
    }

        var mount = document.querySelector('#app');
        ReactDOM.render(<App />, mount);
  </script>
</body>
</html>

【讨论】:

    猜你喜欢
    • 2018-08-16
    • 2012-09-20
    • 2011-11-12
    • 2014-11-06
    • 2018-11-09
    • 2015-08-09
    • 2012-11-25
    • 2013-06-17
    • 2012-05-20
    相关资源
    最近更新 更多