Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

1,使用技术(产品)
HTML5,Vue,Element
2,问题描述
image.png如图,主卡片无法居中
3,预期结果(期望解决的问题)
使得<div id="app"><el-card class="box-card" style="width:480px;margin:auto;">垂直居中
4,参考资料
Element相关文档
5,已尝试过的解决方案(失败)
(1)

#app{
display:flex;
justify-content: center;
align-items: center;
}

(2)

#app{
position:relative;
.box-card{
    position: absolute;
    top: 0;
    left: 0;
    right:0;
    bottom: 0;
    margin: auto;
    }
}

6,代码(前端HTML)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Login - Unified authentication for Lime Network users</title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script src="https://cdn.staticfile.org/element-ui/2.13.2/index.js"></script>
        <script src="https://cdn.staticfile.org/element-ui/2.13.2/locale/en.min.js"></script>
        <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.13.2/theme-chalk/index.css">
    </head>
    
    <body>
        <div id="app">
            <el-card class="box-card" style="width:480px;margin:auto;">
                <p style="text-align:center">Login - Unified authentication for Lime Network users</p>
                <el-form ref="form" :model="form" status-icon :rules="rules" label-position="left" label-width="auto">
                    <el-form-item label="Username" prop="username">
                        <el-input v-model="form.username" prefix-icon="el-icon-user"></el-input>
                    </el-form-item>
                    <el-form-item label="Password" prop="password">
                        <el-input v-model="form.password" prefix-icon="el-icon-lock" show-password></el-input>
                    </el-form-item>
                    <el-form-item label="Remember me">
                        <el-switch v-model="form.remember"></el-switch>
                    </el-form-item>
                    <el-form-item label="Other ways">
                        <el-button type="text" @click="oauth_github()">GitHub</el-button>
                        <el-button type="text" @click="oauth_gitee()">Gitee</el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('form')">Login</el-button>
                        <el-button @click="resetForm('form')">Reset</el-button>
                    </el-form-item>
                </el-form>
            </el-card>
        </div>
        <script>
        Script部分省略
        </script>
    </body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
217 views
Welcome To Ask or Share your Answers For Others

1 Answer

试试将 #app 元素撑开

#app{
    position: relative;
    width: 100%;
    height: 100vh;
    display:flex;
    justify-content: center;
    align-items: center;
}

另外可能会出现的展开元素后页面出现滚动条,尝试设置 body 元素的 marginpadding 为 0px


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...