HTML材质设计按钮

时间:2017-10-15 13:07:51

标签: html css button material-design

我想为组织的GCSE选项创建一个网站,我目前正在使用Notepad ++起草它。我部分是新手。

我想创建一个可悬停的下拉列表,其中列出了所有选项,如果点击,它会打开一张关于主题的卡片。我喜欢Material Design概念,这里是代码的一部分:

    [FunctionName("DeleteDocument")]
    public static async Task Run(
        [TimerTrigger("00:01", RunOnStartup = true)] TimerInfo timer,
        [DocumentDB] DocumentClient client,
        TraceWriter log)
    {
        var collectionUri = UriFactory.CreateDocumentCollectionUri("ItemDb", "ItemCollection");
        var documents = client.CreateDocumentQuery(collectionUri);

        foreach (Document d in documents)
        {
            await client.DeleteDocumentAsync(d.SelfLink);
        }
    }
/* 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;
}

然后,我还想将每个主题链接到这种卡: https://getmdl.io/components/index.html#cards-section

我制作了样卡:

<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>
.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;
}

如何将卡片链接到其中一个下拉选项,这样就会打开,如何连接卡片上的“完成”按钮以关闭卡片?

请帮助我。

1 个答案:

答案 0 :(得分:3)

通过链接卡片,我相信您的意思是说您希望在点击链接时弹出卡片。这可以使用javascript / jquery轻松实现。一个纯粹的&#34; hacky&#34; css解决方案也是可行的,但不建议使用。

以下解决方案使用jQuery

&#13;
&#13;
$(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();
  });

});
&#13;
/* 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);
}
&#13;
<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>
&#13;
&#13;
&#13;

更新:

使用数据属性将相关内容添加到可插入卡中的链接。在这种情况下,我添加了以下内容:

<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>