2017-10-15 137 views
2

我想創建一個組織的GCSE選項的網站,我目前正在使用Notepad ++進行草擬。我在這方面部分是新手。HTML材質設計按鈕

我想創建一個可移動的下拉列表,其中列出了所有選項,如果單擊它,它會打開一張關於該主題的卡片。我喜歡的材料設計概念,這裏的部分代碼:

/* Style The Dropdown Button */ 
 

 
.dropbtn { 
 
    background-color: #4CAF50; 
 
    color: white; 
 
    padding: 16px; 
 
    font-size: 16px; 
 
    border: none; 
 
    cursor: pointer; 
 
} 
 

 

 
/* The container <div> - needed to position the dropdown content */ 
 

 
.dropdown { 
 
    position: relative; 
 
    display: inline-block; 
 
} 
 

 

 
/* Dropdown Content (Hidden by Default) */ 
 

 
.dropdown-content { 
 
    display: none; 
 
    position: absolute; 
 
    background-color: #f9f9f9; 
 
    min-width: 160px; 
 
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); 
 
    z-index: 1; 
 
} 
 

 

 
/* Links inside the dropdown */ 
 

 
.dropdown-content a { 
 
    color: black; 
 
    padding: 12px 16px; 
 
    text-decoration: none; 
 
    display: block; 
 
} 
 

 

 
/* Change color of dropdown links on hover */ 
 

 
.dropdown-content a:hover { 
 
    background-color: #f1f1f1 
 
} 
 

 

 
/* Show the dropdown menu on hover */ 
 

 
.dropdown:hover .dropdown-content { 
 
    display: block; 
 
} 
 

 

 
/* Change the background color of the dropdown button when the dropdown content is shown */ 
 

 
.dropdown:hover .dropbtn { 
 
    background-color: #3e8e41; 
 
}
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> 
 
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css"> 
 
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script> 
 

 
<div class="dropdown"> 
 
    <button class="dropbtn">Compulsary</button> 
 
    <div class="dropdown-content"> 
 
    <a href="#">English Language</a> 
 
    <a href="#">English Literature</a> 
 
    <a href="#">Mathematics</a> 
 
    </div> 
 
</div>

然後,我也希望每個主題鏈接到這種卡: https://getmdl.io/components/index.html#cards-section

我做了一個樣卡:

.demo-card-wide.mdl-card { 
 
    width: 512px; 
 
} 
 

 
.demo-card-wide>.mdl-card__title { 
 
    color: #fff; 
 
    height: 176px; 
 
    background: url('https://www.tes.com/sites/default/files/maths_blackboard.jpg') center/cover; 
 
} 
 

 
.demo-card-wide>.mdl-card__menu { 
 
    color: #fff; 
 
}
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> 
 
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css"> 
 
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script> 
 

 
<div class="demo-card-wide mdl-card mdl-shadow--2dp"> 
 
    <div class="mdl-card__title"> 
 
    <h2 class="mdl-card__title-text">Mathematics</h2> 
 
    </div> 
 
    <div class="mdl-card__supporting-text"> 
 
    This is one of the compulsary subjects and is crucial. It involves geometry, algebra, data, and numbers. 
 
    </div> 
 
    <div class="mdl-card__actions mdl-card--border"> 
 
    <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"> 
 
     Done 
 
    </a> 
 
    </div> 
 
</div>

如何將卡連接到其中一個下拉選項,以便它打開並如何鏈接卡上的「完成」按鈕以關閉卡?

請幫我這個。

回答

2

通過連接卡片,我相信你的意思是說你想要點擊鏈接時彈出卡片。這可以使用javascript/jquery輕鬆實現。純粹的「hacky」css解決方案也是可能的,但不推薦。

以下解決方案使用jQuery的

$(document).ready(function() { 
 
    $(".dropdown-content a").click(function() { 
 
    $(".background-mask").show(); 
 
    $(".demo-card-wide.mdl-card").show(); 
 

 
    $(".mdl-card__supporting-text").text(
 
     $(this).attr("data-content") 
 
    ); 
 

 
    $(".demo-card-wide>.mdl-card__title").css('background', 'url(' + $(this).attr("data-img") + ') center/cover') 
 
    }); 
 

 
    $(".mdl-button").click(function() { 
 
    $(".demo-card-wide.mdl-card").hide(); 
 
    $(".background-mask").hide(); 
 
    }); 
 

 
});
/* Style The Dropdown Button */ 
 

 
body { 
 
    position: relative; 
 
} 
 

 
.dropbtn { 
 
    background-color: #4CAF50; 
 
    color: white; 
 
    padding: 16px; 
 
    font-size: 16px; 
 
    border: none; 
 
    cursor: pointer; 
 
} 
 

 

 
/* The container <div> - needed to position the dropdown content */ 
 

 
.dropdown { 
 
    position: relative; 
 
    display: inline-block; 
 
    z-index: 0; 
 
} 
 

 

 
/* Dropdown Content (Hidden by Default) */ 
 

 
.dropdown-content { 
 
    display: none; 
 
    position: absolute; 
 
    background-color: #f9f9f9; 
 
    min-width: 160px; 
 
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); 
 
    z-index: 1; 
 
} 
 

 

 
/* Links inside the dropdown */ 
 

 
.dropdown-content a { 
 
    color: black; 
 
    padding: 12px 16px; 
 
    text-decoration: none; 
 
    display: block; 
 
} 
 

 

 
/* Change color of dropdown links on hover */ 
 

 
.dropdown-content a:hover { 
 
    background-color: #f1f1f1 
 
} 
 

 

 
/* Show the dropdown menu on hover */ 
 

 
.dropdown:hover .dropdown-content { 
 
    display: block; 
 
} 
 

 

 
/* Change the background color of the dropdown button when the dropdown content is shown */ 
 

 
.dropdown:hover .dropbtn { 
 
    background-color: #3e8e41; 
 
} 
 

 
.demo-card-wide.mdl-card { 
 
    width: 512px; 
 
    display: none; 
 
    position: absolute; 
 
    top: 50%; 
 
    left: 50%; 
 
    transform: translate(-50%, -50%); 
 
} 
 

 
.demo-card-wide>.mdl-card__title { 
 
    color: #fff; 
 
    height: 176px; 
 
} 
 

 
.demo-card-wide>.mdl-card__menu { 
 
    color: #fff; 
 
} 
 

 
.background-mask { 
 
    display: none; 
 
    position: absolute; 
 
    width: 100vw; 
 
    height: 100vh; 
 
    top: 0; 
 
    left: 0; 
 
    background-color: rgba(0, 0, 0, 0.7); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> 
 
<link rel="stylesheet" href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css"> 
 
<script defer src="https://code.getmdl.io/1.3.0/material.min.js"></script> 
 

 
<div class="dropdown"> 
 
    <button class="dropbtn">Compulsary</button> 
 
    <div class="dropdown-content"> 
 
    <a href="#" data-content="English Language Content" data-img="https://www.tes.com/sites/default/files/maths_blackboard.jpg">English Language</a> 
 
    <a href="#" data-content="English Literature Content" data-img="https://images7.content-hcs.com/commimg/myhotcourses/blog/post/myhc_24232.jpg">English Literature</a> 
 
    <a href="#" data-content="Mathematics Content" data-img="https://c.tadst.com/gfx/750w/english-language-day.jpg">Mathematics</a> 
 
    </div> 
 
</div> 
 

 
<div class="background-mask"></div> 
 

 
<div class="demo-card-wide mdl-card mdl-shadow--2dp"> 
 
    <div class="mdl-card__title"> 
 
    <h2 class="mdl-card__title-text">Mathematics</h2> 
 
    </div> 
 
    <div class="mdl-card__supporting-text"> 
 
    This is one of the compulsary subjects and is crucial. It involves geometry, algebra, data, and numbers. 
 
    </div> 
 
    <div class="mdl-card__actions mdl-card--border"> 
 
    <a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"> 
 
     Done 
 
    </a> 
 
    </div> 
 
</div>

UPDATE:

使用數據屬性相關的內容添加到可以在卡被插入的鏈接。在這種情況下,我加入了以下內容:

<a href="#" data-content="English Language Content" data-img="https://www.tes.com/sites/default/files/maths_blackboard.jpg">English Language</a> 
<a href="#" data-content="English Literature Content" data-img="https://images7.content-hcs.com/commimg/myhotcourses/blog/post/myhc_24232.jpg">English Literature</a> 
<a href="#" data-content="Mathematics Content" data-img="https://c.tadst.com/gfx/750w/english-language-day.jpg">Mathematics</a> 
+0

這是偉大的,但是,有沒有辦法打開頁面中間的卡,調光一切,僅在進行卡可點擊? –

+0

對不起,您一定誤會了我,對不起,但我的意思是它打開在整個頁面的中間,所以您只能點擊'完成'。另外,您能否將英文語言連接到卡片的副本,但隨機文本中,所以我可以告訴如何將卡片單獨鏈接到每個按鈕? 謝謝 –

+0

我的不好,上次忘了保存我的編輯。我再次更新了新的要求。希望這解決了一切。 –