无法添加背景图片css

时间:2017-05-07 11:26:34

标签: html css

我遵循了本教程:

https://www.youtube.com/watch?v=on7p8oqfv80

我似乎无法将背景图像添加到类中。这个图片链接确实有效,我已经在浏览器中打开了,之前我还使用" img src ="直接将它添加到了html中。它有效。

我知道样式表正在正确链接,因为文本的样式会发生变化。

我尝试使用单引号而不是双引号添加宽度,尝试使用背景图像而不是背景。我尝试使用本地映像,是的我在Linux上,是的,我在该目录中的所有文件上都有chmod 777,只是为了确定。我已尝试通过以下链接提供的所有不同解决方案:

Cannot add background image to my <div>

How to add background image in css?

Cannot add background image to my <div>

在Linux,Windows和Mac上的Firefox,Chrome和IE上试过这个。

这是代码

&#13;
&#13;
var errorCallback = function(e) {
  console.log('Reeeeejected!', e);
};

navigator.getUserMedia = navigator.getUserMedia ||
  navigator.webkitGetUserMedia ||
  navigator.mozGetUserMedia ||
  navigator.msGetUserMedia;

var video = document.querySelector('video');

if (navigator.getUserMedia) {
  navigator.getUserMedia(

    {
      audio: true,
      video: true
    },

    function(stream)

    {
      video.src = window.URL.createObjectURL(stream)
    },

    errorCallback);
} else {
  video.src = 'somevideo.webm';
}
&#13;
* {
  margin: 0;
  padding: 0;
  border: 0;
}

h1 {
  text-align: center;
  font-size: 575%;
  color: #4A4444;
  text-transform: uppercase;
  letter-spacing: 1%;
  margin: 45% 0;
}

h2 {
  text-align: center;
  font-size: 275%;
  color: #E5E5E5;
  text-transform: uppercase;
  letter-spacing: 1
}


}

/*---Start Parallex---*/
.parallax {
  float: left;
  border: 5px groove;
  margin-left: 70px;
  width: 100px;
  height: 100px;
  background-image: url('http://www.w3newbie.com/wp-content/uploads/parallax-2.jpg') repeat fixed 100%;
  */ background-size: 100% 100%;
  width: auto;
}
.parallax-inner {
  padding-top: 50%;
  padding-bottom: 50%;
}
&#13;
<h1> Space </h1>
<section class="parallex">
  <div class="parallex-inner">
    <h2>Space</h2>
  </div>
</section>
<h1>Space</h1>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

*{

margin: 0;
padding: 0;
border: 0;

}

h1 {

text-align: center;
font-size: 575%;
color: #4A4444;
text-transform: uppercase;
letter-spacing: 1%;
margin: 45% 0;

}

h2 {

    text-align: center;
    font-size: 275%;
    color: #E5E5E5;
    text-transform: uppercase;
    letter-spacing: 1
  }



/*---Start Parallex---*/

.parallex{

float: left;
border: 5px groove;
margin-left: 70px;
width: 100px;
height: 100px;

background: url('http://www.w3newbie.com/wp-content/uploads/parallax-2.jpg') repeat fixed 100%;
background-size: 100% 100%;
width: 100%;

}


.parallax-inner{
    padding-top: 50%;
    padding-bottom: 50%;

}
<body>

        <h1> Space </h1>


    <section class="parallex">

        <div class="parallex-inner">

            <h2>Space</h2>

        </div>

    </section>


        <h1>Space</h1>

</body>

我喜欢一些拼写错误和语法错误。

希望这会帮助你在途中放弃!

答案 1 :(得分:0)

我使用本地图像文件尝试了您的代码,发现背景图像显示但是直接传递给(或者部分或div)

<section style="background-image: url('049.JPG');" class="parallex">

    <div class="parallex-inner">

        <h2>Space</h2>

    </div>

</section>

我必须在这里使用正确的类添加,并在你的背景图像声明返回后没有正面结果删除* /(肯定是一个bug)...除了我直接尝试时