Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

为啥组件格式只对第一个button起作用了?

<el-button v-for="i in 4"></el-button>
<!-- 我在html里面定义了四个按钮 -->
<style>
.el-button{
        width: 400px; 
        height: 200px; 
        display: block; 
        margin: 2em auto;
        border: 10px solid black; 
        border-radius: 20px;
    }
/*
*主要是在button居中这部分的问题
*只有第一个居中了
*为啥啊??
*/
</style>

效果图是这样的
image.png


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

1 Reply

0 votes
by (71.8m points)

猜测渲染出来的 button display:inline-block,所以无法用 margin: 2em auto 居中。

最简单的做法给父元素加上:

.parent
  display flex
  flex-direction column
  align-items center

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...