Welcome to OStack Knowledge Sharing 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 Answer

0 votes
by (71.8m points)

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

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...