我想为以下代码对齐以HTML为中心的列表内容。当屏幕尺寸较小时,它看起来不错,但在屏幕尺寸较大时,它没有居中。我试图通过使用视口使其响应,但是在触发它之前出现了模式。感谢您的帮助。
/* Modal Window */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0, 0, 0); /* Fallback color */
background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 50%;
height: 50%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #02ccba;
color: white;
text-align: center;
}
.modal-body {
padding: 2px 10px;
text-align: center;
width: 50%;
/*margin-right: 30px;*/
}
.modal-list {
padding: 2px 16px;
width: 200px;
}
#modal-body-list {
list-style-type: none;
text-align: left;
}
.list-item {
font-weight: bold;
}
#list-star {
text-align: center;
}
#playAgainButton {
-webkit-border-radius: 34;
-moz-border-radius: 34;
border-radius: 34px;
font-family: Arial;
color: #000000;
font-size: 14px;
font-weight: bold;
padding: 5px 10px;
margin: 20px 0;
border: solid #02ccbb 4px;
text-decoration: none;
cursor: pointer;
}
<!-- Modal Content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>CONGRATULATIONS!</h2>
</div>
<div class="modal-body">
<ul id="modal-body-list">
<li class="modal-list">
<span class="list-item">Moves:</span>
<span id="list-moves"></span>
</li>
<li class="modal-list">
<span class="list-item">Time:</span>
<span id="list-time"></span>
</li>
<li class="modal-list">
<span class="list-item">Star:</span>
<span id="list-star"></span>
</li>
<li class="modal-list">
<button id="playAgainButton">Play Again</button>
</li>
</ul>
</div>
</div>
PS:上面的代码来自w3schools。我刚刚修改了它。
答案 0 :(得分:0)
尝试此希望对解决方案有所帮助。
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 50%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #02ccba;
color: white;
text-align: center;
}
.modal-body {
text-align: center;
width:100%;
/*margin-right: 30px;*/
}
.modal-list {
width: 100%;
text-align: center;
}
#modal-body-list {
list-style-type: none;
padding: 0;
}
.list-item {
font-weight: bold;
}
#list-star {
text-align: center;
}
#playAgainButton {
-webkit-border-radius: 34;
-moz-border-radius: 34;
border-radius: 34px;
font-family: Arial;
color: #000000;
font-size: 14px;
font-weight: bold;
padding: 5px 10px;
margin: 20px 0;
border: solid #02ccbb 4px;
text-decoration: none;
cursor: pointer;
}
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>CONGRATULATIONS!</h2>
</div>
<div class="modal-body">
<ul id="modal-body-list">
<li class="modal-list">
<span class="list-item">Moves:</span>
<span id="list-moves"></span>
</li>
<li class="modal-list">
<span class="list-item">Time:</span>
<span id="list-time"></span>
</li>
<li class="modal-list">
<span class="list-item">Star:</span>
<span id="list-star"></span>
</li>
<li class="modal-list">
<button id="playAgainButton">Play Again</button>
</li>
</ul>
</div>
</div>