我使用Material Design构建了一个网页。我想将侧边栏(mdl-layout__drawer
)标题设为固定。
这是我的HTML代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="google-site-verification" content="">
<meta name="description" content="Introducing Lollipop, a sweet new take on Android.">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<base href="{$site_conf.site.base_url}">
<title>{$site_title|default:"undefined"}</title>
<link rel="icon" type="image/png" href="template/desktop/atah/images/favicon.png">
<link rel="stylesheet" href="system/plugins/mdl/material.min.css">
<link rel="stylesheet" href="template/desktop/atah/styles.css">
<link rel="stylesheet" href="system/plugins/mdl/material-icon.css">
<script src="system/plugins/mdl/material.min.js"></script>
<script src="system/plugins/mdl/jquery.min.js"></script>
<script src="system/plugins/tinyMCE/tinymce.min.js"></script>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--fixed-drawer">
<div class="android-header mdl-layout__header mdl-layout__header--waterfall">
<div class="mdl-layout__header-row">
<span class="droidic android-title mdl-layout-title mdl-color-text--green-500 mdl-typography--text-uppercase">
{$site_conf.site.name}
</span>
<div class="android-header-spacer mdl-layout-spacer"></div>
<button id="d" class="mdl-button mdl-js-button mdl-button--icon">
<i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="d">
<li class="mdl-menu__item">Profil saya</li>
<li class="mdl-menu__item">Pengaturan</li>
<li data-href="/site/logout" class="mdl-menu__item">Keluar</li>
</ul>
<span class="droidic android-mobile-title mdl-layout-title mdl-color-text--green-500">
{$site_conf.site.name}
</span>
</div>
</div>
<!-- SIDEBAR STARTED HERE -->
<div class="android-drawer mdl-layout__drawer non-scrollable">
<span class="mdl-layout-title">
<img class="android-logo-image" src="template/desktop/atah/images/android-logo-white.png">
</span>
<nav class="mdl-navigation scrollable">
{foreach from=$array_menu item=item}
{if $item.kd != "ds"}
<a class="mdl-navigation__link" href="{$item.anchor_link}">
<button type="button" class="mdl-button mdl-button--icon">
<i class="material-icons">{$item.icon}</i>
</button> {$item.anchor}
</a>
{else}
<span class="mdl-navigation__link">{$item.anchor}</span>
{/if}
{foreachelse}
<span class="mdl-navigation__link">Menu tidak tersedia</span>
{/foreach}
</nav>
</div>
<main class="android-content mdl-layout__content">
这是我的CSS:
.non-scrollable{
overflow: hidden;
}
.scrollable{
overflow-y: scroll;
}
.tab-action{
line-height: 55px; text-align: right; padding: 0 2vh;
}
.list-scrollable{
max-height: 390px; overflow-y: scroll;
}
.list-scrollable::-webkit-scrollbar {
width: 6px;
}
.list-scrollable::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
}
.list-scrollable::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
.mdl-button--file input {
cursor: pointer; height: 100%;
right: 0; opacity: 0;
position: absolute; top: 0;
width: 300px; z-index: 4;
}
.mdl-textfield--file .mdl-textfield__input {
box-sizing: border-box;
width: calc(100% - 32px);
}
.mdl-textfield--file .mdl-button--file {
right: 0;
}
ul.fileList{
list-style: none; padding: 0; margin: 0; overflow-y: scroll; min-height: 320px;
width: 100%; max-height: 320px
}
ul.fileList li:nth-child(odd){
background: #eee;
}
ul.fileList li{
padding: 0 16px; position: relative; line-height: 35px;
}
ul.fileList li .dropSign{
float: right;
}
.block_copy{
display: block; clear: both; margin: 0.5vh 0; width: 100%; border: none; background: transparent;
padding: 4px 0;
}
ul.articleLists{
width: 100%; margin: 0; padding: 0;
}
ul.articleLists li{
width: 100%; margin: 0; padding: 20px 0; list-style: none; line-height: 40px;
border-bottom: 1px solid #eee;
}
ul.articleLists li:first-child{
padding-top: 0;
}
ul.articleLists li:last-child{
border: none;
}
ul.articleLists li h4{
margin: 0; padding: 0; font-size: 16px; width: 100%; text-align: left;
}
ul.articleLists li h4 small{
display: block; font-size: 12px; color: #333;
}
a.btn_pagging{
text-decoration: none; margin: 1vh 2vh; background: #eee; padding: 1vh;
color: #333; border-radius: 5px;
}
span.btn_pagging{
text-decoration: none; margin: 1vh 2vh;
}
.uploadQueue{
margin: 0; padding: 0; list-style: none;
}
.uploadQueue li{
word-wrap: break-word; padding: 4px 2px; border-bottom: 1px solid #eee;
}
.uploadQueue li:last-child{
border: none;
}
.table-no-border{
border: none;
}
.table-no-border th, .table-no-border td{
border: none;
}
.table-content--on-left{
text-align: left; font-size: 1rem;
border-collapse: collapse; padding: 6px;
}
.table-content--on-left tr:hover{
background: #cfd8dc;
}
.table-content--on-left td{
text-align: left;
}
.inline-categories{
margin: 0; padding: 0;
}
.inline-categories li{
display: inline-table; background: #eeeeee; padding: 0 4px; text-align: center;
border-radius: 6px; margin: 2px 0;
}
.hide_dom{
display: none;
}
.show_dom{
visibility: visible;
}
.input-judul{
font-size: 24px;
}
.frm_reg_blog{
}
.left-aligned{
float: left;
}
.right-aligned{
float: right;
}
.inliner{
display: inline;
}
body {
margin: 0;
}
.label-grafik{
width: 120px;
}
.ringkasan{
min-height: 350px;
}
.fill-container{
width: 100%;
}
@font-face {
font-family: droidfont;
src: url(../../../system/font/droidlogo.ttf);
}
@font-face {
font-family: droidmono;
src: url(../../../system/font/droid-sans-mono.ttf);
}
.droidic{
font-family: droidfont;
}
.html_editor{
width: auto; margin-right: 1vh;
}
.html_editor #inFile{
margin: 0; background: #607d8b; padding: 4px; color: white; font-weight: bold;
}
.html_editor textarea{
margin: 0px; width: 100%; resize: none; height: 390px; background: #37474f; color: white;
padding: 5px; font-family: droidmono; border: none;
}
.html_editor textarea:focus{
outline: none;
}
.html_editor textarea::-webkit-scrollbar {
width: 6px;
}
.html_editor textarea::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
.html_editor textarea::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px #607d8b;
border-radius: 10px;
}
/* Disable ugly boxes around images in IE10 */
a img{
border: 0px;
}
::-moz-selection {
background-color: #6ab344;
color: #fff;
}
::selection {
background-color: #6ab344;
color: #fff;
}
.android-search-box .mdl-textfield__input {
color: rgba(0, 0, 0, 0.87);
}
.android-header .mdl-menu__container {
z-index: 50;
margin: 0 !important;
}
.mdl-textfield--expandable {
width: auto;
}
.android-fab {
position: absolute;
right: 20%;
bottom: -26px;
z-index: 3;
background: #64ffda !important;
color: black !important;
}
.android-mobile-title {
display: none !important;
}
.android-logo-image {
height: 28px;
width: 140px;
}
.android-header {
overflow: visible;
background-color: white;
}
.android-header .material-icons {
color: #767777 !important;
}
.android-header .mdl-layout__drawer-button {
background: transparent;
color: #767777;
}
.android-header .mdl-navigation__link {
color: #757575;
font-weight: 700;
font-size: 14px;
}
.android-navigation-container {
/* Simple hack to make the overflow happen to the left instead... */
direction: rtl;
-webkit-order: 1;
-ms-flex-order: 1;
order: 1;
width: 500px;
transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.android-navigation {
/* ... and now make sure the content is actually LTR */
direction: ltr;
-webkit-justify-content: flex-end;
-ms-flex-pack: end;
justify-content: flex-end;
width: 800px;
}
.android-search-box.is-focused + .android-navigation-container {
opacity: 0;
width: 100px;
}
.android-navigation .mdl-navigation__link {
display: inline-block;
height: 60px;
line-height: 68px;
background-color: transparent !important;
border-bottom: 4px solid transparent;
}
.android-navigation .mdl-navigation__link:hover {
border-bottom: 4px solid #8bc34a;
}
.android-search-box {
-webkit-order: 2;
-ms-flex-order: 2;
order: 2;
margin-left: 16px;
margin-right: 16px;
}
.android-more-button {
-webkit-order: 3;
-ms-flex-order: 3;
order: 3;
}
.android-drawer {
border-right: none;
}
.android-drawer-separator {
height: 1px;
background-color: #dcdcdc;
margin: 8px 0;
}
.android-drawer .mdl-navigation__link.mdl-navigation__link {
font-size: 14px;
color: #757575;
}
.android-drawer span.mdl-navigation__link.mdl-navigation__link {
color: #8bc34a;
}
.android-drawer .mdl-layout-title {
position: relative;
background: #6ab344;
height: 160px;
}
.android-drawer .android-logo-image {
position: absolute;
bottom: 16px;
}
.android-be-together-section {
position: relative;
height: 800px;
width: auto;
background-color: #f3f3f3;
background: url('images/slide01.jpg') center 30% no-repeat;
background-size: cover;
}
.logo-font {
font-family: 'Roboto', 'Helvetica', 'Arial', sans-serif;
line-height: 1;
color: #767777;
font-weight: 500;
}
.android-slogan {
font-size: 60px;
padding-top: 160px;
}
.android-sub-slogan {
font-size: 21px;
padding-top: 24px;
}
.android-create-character {
font-size: 21px;
padding-top: 400px;
}
.android-create-character a {
text-decoration: none;
color: #767777;
font-weight: 300;
}
.android-screen-section {
position: relative;
padding-top: 60px;
padding-bottom: 80px;
}
.android-screens {
text-align: right;
width: 100%;
white-space: nowrap;
overflow-x: auto;
}
.android-screen {
text-align: center;
}
.android-screen .android-link {
margin-top: 16px;
display: block;
z-index: 2;
}
.android-image-link {
text-decoration: none;
}
.android-wear {
display: inline-block;
width: 160px;
margin-right: 32px;
}
.android-wear .android-screen-image {
width: 40%;
z-index: 1;
}
.android-phone {
display: inline-block;
width: 64px;
margin-right: 48px;
}
.android-phone .android-screen-image {
width: 100%;
z-index: 1;
}
.android-tablet {
display: inline-block;
width: 110px;
margin-right: 64px;
}
.android-tablet .android-screen-image {
width: 100%;
z-index: 1;
}
.android-tablet .android-link {
display: block;
z-index: 2;
}
.android-tv {
display: inline-block;
width: 300px;
margin-right: 80px;
}
.android-tv .android-screen-image {
width: 100%;
z-index: 1;
}
.android-auto {
display: inline-block;
width: 300px;
overflow: hidden;
}
.android-auto .android-screen-image {
display: block;
height: 300px;
z-index: 1;
}
.android-wear-section {
position: relative;
background: url('images/wear.png') center top no-repeat;
background-size: cover;
height: 800px;
}
.android-wear-band {
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
background-color: #37474f;
}
.android-wear-band-text {
max-width: 800px;
margin-left: 25%;
padding: 24px;
text-align: left;
color: white;
}
.android-wear-band-text p {
padding-top: 8px;
}
.android-link {
text-decoration: none;
color: #8bc34a !important;
}
.android-link:hover {
color: #7cb342 !important;
}
.android-link .material-icons {
position: relative;
top: -1px;
vertical-align: middle;
}
.android-alt-link {
text-decoration: none;
color: #64ffda !important;
font-size: 16px;
}
.android-alt-link:hover {
color: #00bfa5 !important;
}
.android-alt-link .material-icons {
position: relative;
top: 6px;
}
.android-customized-section {
text-align: center;
}
.android-customized-section-text {
max-width: 500px;
margin-left: auto;
margin-right: auto;
padding: 80px 16px 0 16px;
}
.android-customized-section-text p {
padding-top: 16px;
}
.android-customized-section-image {
background: url('images/devices.jpg') center top no-repeat;
background-size: cover;
height: 400px;
}
.android-more-section {
padding: 80px 0;
max-width: 1044px;
margin-left: auto;
margin-right: auto;
}
.android-more-section .android-section-title {
margin-left: 12px;
padding-bottom: 24px;
}
.android-card-container {
}
.android-card-container .mdl-card__media {
overflow: hidden;
background: transparent;
}
.android-card-container .mdl-card__media img {
width: 100%;
}
.android-card-container .mdl-card__title {
background: transparent;
height: auto;
}
.android-card-container .mdl-card__title-text {
color: black;
height: auto;
}
.android-card-container .mdl-card__supporting-text {
height: auto;
color: black;
padding-bottom: 56px;
}
.android-card-container .mdl-card__actions {
position: absolute;
bottom: 0;
}
.android-card-container .mdl-card__actions a {
border-top: none;
font-size: 16px;
}
.android-footer {
background-color: #fafafa;
position: relative;
}
.android-footer a:hover {
color: #8bc34a;
}
.android-footer .mdl-mega-footer--top-section::after {
border-bottom: none;
}
.android-footer .mdl-mega-footer--middle-section::after {
border-bottom: none;
}
.android-footer .mdl-mega-footer--bottom-section {
position: relative;
}
.android-footer .mdl-mega-footer--bottom-section a {
margin-right: 2em;
}
.android-footer .mdl-mega-footer--right-section a .material-icons {
position: relative;
top: 6px;
}
.android-link-menu:hover {
cursor: pointer;
}
/**** Mobile layout ****/
@media (max-width: 900px) {
.android-navigation-container {
display: none;
}
.android-title {
display: none !important;
text-transform: uppercase;
}
.android-mobile-title {
text-transform: uppercase;
display: block !important;
position: absolute;
left: calc(50% - 70px);
top: 12px;
transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
/* WebViews in iOS 9 break the "~" operator, and WebViews in OS X 10.10 break
consecutive "+" operators in some cases. Therefore, we need to use both
here to cover all the bases. */
.android.android-search-box.is-focused ~ .android-mobile-title,
.android-search-box.is-focused + .android-navigation-container + .android-mobile-title {
opacity: 0;
}
.android-more-button {
display: none;
}
.android-search-box.is-focused {
width: calc(100% - 48px);
}
.android-search-box .mdl-textfield__expandable-holder {
width: 100%;
}
.android-be-together-section {
height: 350px;
}
.android-slogan {
font-size: 26px;
margin: 0 16px;
padding-top: 24px;
}
.android-sub-slogan {
font-size: 16px;
margin: 0 16px;
padding-top: 8px;
}
.android-create-character {
padding-top: 200px;
font-size: 16px;
}
.android-create-character img {
height: 12px;
}
.android-fab {
display: none;
}
.android-wear-band-text {
margin-left: 0;
padding: 16px;
}
.android-footer .mdl-mega-footer--bottom-section {
display: none;
}
}
我尝试将overflow: hidden;
提供给.mdl-layout__drawer.non-scrollable
,并将overflow-y: scroll
提供给.mdl-navigation.scrollable
。
.mdl-layout__drawer.non-scrollable
现在不可滚动,但.mdl-navigation.scrollable
无法滚动。
怎么做?
答案 0 :(得分:0)
在CSS中查找此规则:
.android-title {
display: none !important;
text-transform: uppercase;
}
然后像这样更新:
.android-title {
display: none !important;
text-transform: uppercase;
position: fixed;
display: block;
}
答案 1 :(得分:0)
我找到了办法。 如果有人像这篇文章一样有麻烦,请分享
使侧边栏导航可以使用固定标题滚动我使用javascript来执行此操作。
使用document
元素的高度减少.mdl-layout__drawer .mdl-layout-title
的高度。并将结果用作导航可滚动高度。
这是代码:
document.addEventListener('mdl-componentupgraded', function(e) {
if (typeof e.target.MaterialLayout !== 'undefined'){
$('.scrollable').height(function(){
var a = $('.android-drawer .mdl-layout-title').height();
var b = $(document).height();;
return (Math.ceil(parseInt(b) - parseInt(a))) - 20;
});
}
});
如果某人有简单或更好的方式,请在此处写下来。