HTML材质设计按钮

问题描述:

我想创建一个组织的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>

如何将卡连接到其中一个下拉选项,以便它打开并如何链接卡上的“完成”按钮以关闭卡?

请帮我这个。

通过连接卡片,我相信你的意思是说你想要点击链接时弹出卡片。这可以使用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

我的不好,上次忘了保存我的编辑。我再次更新了新的要求。希望这解决了一切。 –