“材质设计”对话框guidelines不会解决平板电脑或桌面大小视口上的对话框宽度问题。我在某地读过应该使用56px的增量,但不知道这是否达成共识。
我在对话框中需要的HTML输入对于默认大小的对话框来说太小了。它只是看起来没有定义,我不想将输入宽度拉得太远以填充对话框。
对一些基本CSS的任何建议来调整对话框的大小?也许是sm,md,lg类型的解决方案?我应该使用56px的增量还是?...提前致谢。
答案 0 :(得分:1)
“材质设计”对话框指南未解决平板电脑或桌面大小的视口上的对话框宽度。
这是真的,规范没有描述桌面的对话框宽度,所以每个团队都有自己的实现。 Material Design Lite小组使用固定宽度,如下例所示,
(function() {
'use strict';
var dialogButton = document.querySelector('.dialog-button');
var dialog = document.querySelector('#dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
dialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])')
.addEventListener('click', function() {
dialog.close();
});
}());

body {
padding-top: 20px;
padding-left: 20px;
box-sizing: border-box;
}
.mdl-dialog {
border: none;
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
width: 280px; }
.mdl-dialog__title {
padding: 24px 24px 0;
margin: 0;
font-size: 2.5rem; }
.mdl-dialog__actions {
padding: 8px 8px 8px 24px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap; }
.mdl-dialog__actions > * {
margin-right: 8px;
height: 36px; }
.mdl-dialog__actions > *:first-child {
margin-right: 0; }
.mdl-dialog__actions--full-width {
padding: 0 0 8px 0; }
.mdl-dialog__actions--full-width > * {
height: 48px;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
padding-right: 16px;
margin-right: 0;
text-align: right; }
.mdl-dialog__content {
padding: 20px 24px 24px 24px;
color: rgba(0,0,0, 0.54); }

<link href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" rel="stylesheet"/>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<button class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button>
<p>
Remember that the Dialog component requires the <a href="https://github.com/GoogleChrome/dialog-polyfill">Dialog polyfill</a> in order to function.
It takes advantage of the native dialog element to provide the most robust experience possible.
</p>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">MDL Dialog</h3>
<div class="mdl-dialog__content">
<p>
This is an example of the Material Design Lite dialog component.
Please use responsibly.
</p>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Close</button>
<button type="button" class="mdl-button" disabled>Disabled action</button>
</div>
</dialog>
&#13;
MDC-Web小组使用min-width
640px
和max-width
865px
。他们讨论此问题的MDL团队的Here is a discussion。
我在对话框中需要的HTML输入对于默认大小的对话框来说太小了。它只是看起来没有定义,我不想将输入宽度拉得太远以填充对话框。
因此,总而言之,您可以简单地实施最适合您的方式。您可以使用每行一个全宽输入:
(function() {
'use strict';
var dialogButton = document.querySelector('.dialog-button');
var dialog = document.querySelector('#dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
dialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])')
.addEventListener('click', function() {
dialog.close();
});
}());
&#13;
body {
padding-top: 20px;
padding-left: 20px;
box-sizing: border-box;
}
.mdl-dialog {
border: none;
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14),
0 11px 15px -7px rgba(0, 0, 0, 0.12),
0 24px 38px 3px rgba(0, 0, 0, 0.2);
width: 280px;
}
.mdl-dialog__title {
padding: 24px 24px 0;
margin: 0;
font-size: 2.5rem;
}
.mdl-dialog__actions {
padding: 8px 8px 8px 24px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.mdl-dialog__actions > * {
margin-right: 8px;
height: 36px;
}
.mdl-dialog__actions > *:first-child {
margin-right: 0;
}
.mdl-dialog__actions--full-width {
padding: 0 0 8px 0;
}
.mdl-dialog__actions--full-width > * {
height: 48px;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
padding-right: 16px;
margin-right: 0;
text-align: right;
}
.mdl-dialog__content {
padding: 20px 24px 24px 24px;
color: rgba(0, 0, 0, 0.54);
}
/**/
.mdl-dialog {
width: fit-content;
}
.mdl-dialog__content .mdl-textfield {
width: 100%;
margin-right: 24px;
}
&#13;
<link href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" rel="stylesheet"/>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<button class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button>
<p>
Remember that the Dialog component requires the <a href="https://github.com/GoogleChrome/dialog-polyfill">Dialog polyfill</a> in order to function. It takes advantage of the native dialog element to provide the most robust experience possible.
</p>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">MDL Dialog</h3>
<div class="mdl-dialog__content">
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
</form>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Close</button>
<button type="button" class="mdl-button" disabled>Disabled action</button>
</div>
</dialog>
&#13;
或者你可以使用每行多个输入来填充更多空间:
(function() {
'use strict';
var dialogButton = document.querySelector('.dialog-button');
var dialog = document.querySelector('#dialog');
if (!dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
dialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])')
.addEventListener('click', function() {
dialog.close();
});
}());
&#13;
body {
padding-top: 20px;
padding-left: 20px;
box-sizing: border-box;
}
.mdl-dialog {
border: none;
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
width: 280px;
}
.mdl-dialog__title {
padding: 24px 24px 0;
margin: 0;
font-size: 2.5rem;
}
.mdl-dialog__actions {
padding: 8px 8px 8px 24px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.mdl-dialog__actions>* {
margin-right: 8px;
height: 36px;
}
.mdl-dialog__actions>*:first-child {
margin-right: 0;
}
.mdl-dialog__actions--full-width {
padding: 0 0 8px 0;
}
.mdl-dialog__actions--full-width>* {
height: 48px;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
padding-right: 16px;
margin-right: 0;
text-align: right;
}
.mdl-dialog__content {
padding: 20px 24px 24px 24px;
color: rgba(0, 0, 0, 0.54);
}
/**/
.mdl-dialog {
width: fit-content;
min-width: 600px;
}
.mdl-dialog__content .mdl-textfield {
width: 45%;
margin-right: 24px;
}
&#13;
<link href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" rel="stylesheet" />
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<button class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button>
<p>
Remember that the Dialog component requires the <a href="https://github.com/GoogleChrome/dialog-polyfill">Dialog polyfill</a> in order to function. It takes advantage of the native dialog element to provide the most robust experience possible.
</p>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">MDL Dialog</h3>
<div class="mdl-dialog__content">
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
</form>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Close</button>
<button type="button" class="mdl-button" disabled>Disabled action</button>
</div>
</dialog>
&#13;