这个答案有点笼统,但这个问题并没有给我太多关于你的问题的信息。建议至少提供您正在努力的代码片段
有了这个,我将在媒体查询中插入一些 CSS 属性,如下所示:
@media only screen and (max-width: 768px) {
your_login_panel {
display: block;
width: 300px; /* the wished size for your login panel */
margin: 20px auto; /* the second attribute has to be auto, this value combined with display:block will center the element inside the element that it's located */
}
}
如果您使用position: absolute
将元素向右对齐,请记住position: inherit
在媒体查询中插入以覆盖此值。
更新
现在使用代码段,我可以看到您的 CSS 没有声明左侧属性,这对于将某些内容向右对齐非常有用。为了使其居中,只需在left:
您的媒体查询中添加一个具有相同属性值的属性,CSS 将尝试同时满足这两个属性,您还应该放置一个margin: auto;
属性,以便让 CSS 更自由地使用边距并居中登录面板。您的媒体查询应如下所示:
@media only screen and (max-width: 768px) {
.login {
position: absolute;
top: 8em;
right: 0px;
left: 0px;
margin: auto;
}
.login-card {
min-width: 20vw;
max-width: 25em;
min-height: 20vh;
max-height: 25em;
}
}