Search code examples
htmlcssbackground-imageyui-pure-css

Background-image in <div> doesn't display


The background-image within the video id (#video) isn't displaying. I've included the pure gridstyles. I've tried alternate ways of using tags, however later on i'd also like to add in a button in the middle of the image. Is there a way of using div tags to display my background-image? Thanks

The HTML code:

<div id="right_content">
              <div class="pure-g">
                  <div class="pure-u-10-24">
                      <h1 id="about">About</h1>
                      <p class="text chinese_paragraph"> 
                          (Some text)
                      </p>
                  </div>
                  <div class="pure-u-14-24 section2">
                      <div id="video">
                      </div>
                      <button>Watch</button>
                  </div>
              </div>
          </div>

The CSS code:

#right_content {
    background-color: #414141;
    position: fixed;
    right: 0;
    top: 0;
    width: 700px;
    height: 100%;
    box-sizing: border-box;
    padding: 30px 20px;
    overflow: auto;
}
.pure-g > div {
    padding-left: 10px;
    padding-right: 10px;
    box-sizing: border-box;
}
#about {
    color: white;
    display: inline-block;
    position: relative;
    border-top: 2px solid white;
    vertical-align: middle;
    font-family: "Source Sans Pro","Yuanti SC",sans-serif;
    margin: 0;
    padding: 0;
}
p.text {
    color: white;
    font-family: "Source Sans Pro","Yuanti SC",sans-serif;
}
.pure-g .section2 {
    padding-top: 42px;
}
#video {
    background-image: url("../images/video.png");
    position: relative;
    width: 360px;
    height: 200px;
}

Solution

  • Your #video div has no size, it's width and height are 0px. Set a size to your div and it will solve the problem.

    #video {
        background-image: url("../images/video.png");
        position: relative;
        width: 240px;
        height: 100px;
    }
    

    Working example