2016-11-16 70 views
0

首先發布在StackOverflow上,但長期用戶。我正在嘗試向我的網站添加兩張MDlite卡片,每張卡片都有不同的背景圖片,但最後聲明的背景圖片始終顯示兩者。很感謝任何形式的幫助。以下是完整的代碼,你可以撲通到任何瀏覽器中看到的問題(對不起,格式化,我的手機就這樣做):每個MDlite卡的新背景圖片

   <!doctype html> 

      <html lang="en"> 
      <head> 
       <meta charset="utf-8"> 
       <title>Website Title</title> 
       <meta name="description" content="Percula Creative"> 
       <meta name="author" content="Percula Creative Author"> 
       <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet"> 
       <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> 
       <link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.deep_purple-orange.min.css" /> 
       <script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script> 
       <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

      <!--[if IE]><link rel="shortcut icon" href="favicon.ico"><![endif]--> 
       <link rel="icon" href="favicon.png"> 
      </head> 
      <body> 
       <!-- Uses a transparent header that draws on top of the layout's background --> 
      <style> 
      .demo-layout-transparent { 
       background: url('../assets/demos/transparent.jpg') center/cover; 
      } 
      .demo-layout-transparent .mdl-layout__header, 
      .demo-layout-transparent .mdl-layout__drawer-button { 
       /* This background is dark, so we set text to white. Use 87% black instead if 
       your background is light. */ 
       color: white; 
      } 
      </style> 

      <!-- Always shows a header, even in smaller screens. --> 
      <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header"> 
       <header class="mdl-layout__header"> 
       <div class="mdl-layout__header-row"> 
        <!-- Title --> 
      <a href="index.html" style="text-decoration: none; color:white" class="mdl-layout-title">Website Title</a> 
        <!-- Add spacer, to align navigation to the right --> 
        <div class="mdl-layout-spacer"></div> 
        <!-- Navigation. We hide it in small screens. --> 
        <nav class="mdl-navigation mdl-layout--large-screen-only"> 
        <a class="mdl-navigation__link" href="apps.html">Apps</a> 
        <a class="mdl-navigation__link" href="">About</a> 
        <a class="mdl-navigation__link" href="">Contact</a> 
        </nav> 
       </div> 
       </header> 
       <div class="mdl-layout__drawer"> 
       <span class="mdl-layout-title">Website</span> 
       <nav class="mdl-navigation"> 
        <a class="mdl-navigation__link" href="">Apps</a> 
        <a class="mdl-navigation__link" href="">About</a> 
        <a class="mdl-navigation__link" href="">Contact</a> 
       </nav> 
       </div> 
       <main class="mdl-layout__content" style="background-color: #EEEEEE;"> 
       <div class="page-content" > 


        <div style="width:80%; max-width:780px; margin: 0 auto; padding: 16px"> 
      <!-- Wide card with share menu button --> <style> .demo-card-wide.mdl-card { width: 100%; } .demo-card-wide > .mdl-card__title { color: #fff; height: 176px; background: URL('http://www.imagenspng.com.br/wp-content/uploads/2015/07/minions-03.png') center/cover; } .demo-card-wide > .mdl-card__menu { color: #fff; } </style> 
      <div class="demo-card-wide mdl-card mdl-shadow--2dp""> 
      <div class="mdl-card__title"> 
      <h2 class="mdl-card__title-text"></h2> </div> 
      <div class="mdl-card__supporting-text"> 
      <p>Lorem Ipsum dolor1...</p> 
      </div> 
      <div class="mdl-card__actions mdl-card--border"> 
      <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" href="">Download</a> 
      </div> 

      <div class="mdl-card__menu"> 
      <button class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect"> 
      <i class="material-icons">share</i> 
      </button> 
      </div> 

      </div> 
      </div> 




        <div style="width:80%; max-width:780px; margin: 0 auto; padding: 16px"> 
      <!-- Wide card with share menu button --> <style> .demo-card-wide.mdl-card { width: 100%; } .demo-card-wide > .mdl-card__title { color: #fff; height: 176px; background: URL('http://i2.mirror.co.uk/incoming/article6379795.ece/ALTERNATES/s615b/Minion.jpg') center/cover; } .demo-card-wide > .mdl-card__menu { color: #fff; } </style> 
      <div class="demo-card-wide mdl-card mdl-shadow--2dp""> 
      <div class="mdl-card__title"> 
      <h2 class="mdl-card__title-text"></h2> </div> 
      <div class="mdl-card__supporting-text"> 
      <p>Lorem Ipsum dolor2...</p> 
      </div> 
      <div class="mdl-card__actions mdl-card--border"> 
      <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect" href="">Download</a> 
      </div> 

      <div class="mdl-card__menu"> 
      <button class="mdl-button mdl-button--icon mdl-js-button mdl-js-ripple-effect"> 
      <i class="material-icons">share</i> 
      </button> 
      </div> 

      </div> 
      </div> 


       </div> 
       </main> 
      </div> 


      </body> 
      </html> 

回答

2

那是因爲你的內聯CSS兩次進入頁面,以及第二是壓倒第一。這一行CSS既影響div,也影響第一或第二。

.demo-card-wide > .mdl-card__title { color: #fff; height: 176px; background: URL('http://www.imagenspng.com.br/wp-content/uploads/2015/07/minions-03.png') center/cover; } 

你需要創建兩個單獨的規則,每一個格,如果你想在每兩個不同的背景圖像。

總之執行以下操作:

1)刪除整個第二<style>...</style>

2)一種新的類添加到第二個div所以它成爲

<div class="mdl-card__title second"> 

3)加入一個新的CSS規則到你的第<style>...</style>塊這樣的

.demo-card-wide > .mdl-card__title.second { color: #fff; height: 176px; background: URL('http://i2.mirror.co.uk/incoming/article6379795.ece/ALTERNATES/s615b/Minion.jpg') center/cover; } 
+0

謝謝!您的解決方案完美運作不幸的是,我對StackOverflow太新了,所以我不能將它標記爲正確答案,但非常感謝。 –