我有两个水平条,我正在尝试对齐。它们都需要拉伸视口的整个宽度,并且其中的文本需要居中对齐。为此,我使用以下HTML:
<div class="logo-header-desktop">Header</div>
<ul class="logos">
<li>Thing 1</li>
<li>Thing 2</li>
</ul>
<div class="logo-footer-desktop">
<span class="call-button">Footer</span>
</div>
以下SCSS:
.logo-header-desktop, .logo-footer-desktop {
@media screen and (min-width: 1000px) {
position: relative !important;
left: -16%;
width: 100vw;
}
@media screen and (max-width: 999px) {
border: solid 2px #f2f2f2;
}
padding: 30px;
text-align: center;
font-family: 'Sedgwick Ave', cursive;
font-size: 2rem;
}
.logo-header-desktop {
margin-top: 5rem;
@media screen and (min-width: 1000px) {
background: #202020;
}
@media screen and (max-width: 999px) {
border-bottom: 0;
}
}
.logo-footer-desktop {
padding-top: 0;
@media screen and (max-width: 999px) {
border-top: 0;
}
.call-button {
display: block;
font-family: 'Nunito', sans-serif !important;
background: rgba(20, 20, 20, 1);
padding: 20px;
@media screen and (min-width: 1000px) {
width: 100vw;
}
@media screen and (max-width: 999px) {
box-shadow: 0 8px 6px -6px black;
}
transition: color 0.2s, background-color ease-in-out 0.2s;
transform: perspective(1px) translateZ(0);
&:hover, &:focus, &:active {
background: #4b3be7;
color: white;
}
}
}
页眉和页脚使用几乎相同的CSS。但是,这会导致页脚文本与宽度超过1000px的视口中的标题文本不对齐。 1000px以下的视口不受影响。
此行为在JSFiddle中可重现:https://jsfiddle.net/j6j4cck2/
为什么会发生这种情况,我该如何解决?
答案 0 :(得分:1)
call-button
的填充导致错位。
由于您在更宽的屏幕上给它宽度,您还需要添加box-sizing: border-box;
,以便填充包含在设置的宽度中(或使用CSS Calc width: calc(100vw - 40px);
)
.call-button {
display: block;
font-family: 'Nunito', sans-serif !important;
background: rgba(20, 20, 20, 1);
padding: 20px;
box-sizing: border-box; /* added property */
@media screen and (min-width: 1000px) {
width: 100vw;
}
HTML
<div class="logo-header-desktop">Header</div>
<ul class="logos">
<li>Thing 1</li>
<li>Thing 2</li>
</ul>
<div class="logo-footer-desktop">
<span class="call-button">
Footer
</span>
</div>
SCSS
html {
@media screen and (min-width: 768px) {
font-size: 2.5vmin;
}
@media screen and (max-width: 767px) {
font-size: 14px;
}
}
body {
font-family: 'Nunito', sans-serif;
margin: 0;
background-color: #202020;
color: #f2f2f2;
overflow-x: hidden;
}
.logo-header-desktop, .logo-footer-desktop {
@media screen and (min-width: 1000px) {
position: relative !important;
left: -16%;
width: 100vw;
}
@media screen and (max-width: 999px) {
border: solid 2px #f2f2f2;
}
padding: 30px;
text-align: center;
font-family: 'Sedgwick Ave', cursive;
font-size: 2rem;
}
.logo-header-desktop {
margin-top: 5rem;
@media screen and (min-width: 1000px) {
background: #202020;
}
@media screen and (max-width: 999px) {
border-bottom: 0;
}
}
.logo-footer-desktop {
padding-top: 0;
@media screen and (max-width: 999px) {
border-top: 0;
}
.call-button {
display: block;
font-family: 'Nunito', sans-serif !important;
background: rgba(20, 20, 20, 1);
padding: 20px;
box-sizing: border-box;
@media screen and (min-width: 1000px) {
width: 100vw;
}
@media screen and (max-width: 999px) {
box-shadow: 0 8px 6px -6px black;
}
transition: color 0.2s, background-color ease-in-out 0.2s;
transform: perspective(1px) translateZ(0);
&:hover, &:focus, &:active {
background: #4b3be7;
color: white;
}
}
}
ul.logos {
@media screen and (min-width: 1000px) {
background: #202020;
position: relative;
left: -16%;
width: 100vw;
}
@media screen and (max-width: 999px) {
border: solid 2px #f2f2f2;
border-top: 0;
border-bottom: 0;
}
// box-shadow: 0 8px 6px -6px black;
margin: 0;
text-align: center;
list-style: none;
padding-left: 30px;
padding-right: 30px;
li {
line-height: 3;
display: inline-block;
vertical-align: middle;
-webkit-transform: perspective(1px) translateZ(0);
transform: perspective(1px) translateZ(0);
box-shadow: 0 0 1px transparent;
position: relative;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: transform;
transition-property: transform;
&:not(:last-child) {
margin-right: 5%;
}
font-family: 'Sedgwick Ave', cursive;
font-size: 2em;
color: #ffffff;
img {
height: 7vmin;
}
}
}
答案 1 :(得分:0)
您需要从这些元素中删除left
属性。您的负值为-16%
。见this updated fiddle。从代码中删除下面注释的代码。
.logo-header-desktop, .logo-footer-desktop {
@media screen and (min-width: 1000px) {
position: relative !important;
left: -16%; /* Delete this. Line 21 */
width: 100vw;
}
}
将其从以下位置删除:
ul.logos {
@media screen and (min-width: 1000px) {
background: #202020;
position: relative;
left: -16%; /* Delete this. Line 72 */
width: 100vw;
}
}
然后,您需要将box-sizing: border-box
添加到某些元素,并将.call-button
更改为100%,因为100vh
在带填充或边距的div中不起作用。
ul.logos,
.logo-footer-desktop,
.call-button {
box-sizing: border-box; /* Add this. */
}
.call-button {
width: 100%; /* Change from 100vh to 100%. Line 48. */
}
答案 2 :(得分:0)
更改$ iptables -t nat -A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE
,如下所示:
cell-button