gpt4 book ai didi

html - 如何并排放置 svg 和按钮并垂直对齐它们?

转载 作者:太空宇宙 更新时间:2023-11-03 20:26:33 25 4
gpt4 key购买 nike

我有以下片段:

.float-left {
float: left !important;
}

.float-right {
float: right !important;
}

.container {
padding: 1rem;
}

.clearfix {
clear: both;
}

.has-border {
border: 2px solid #000;
}

.d-inline-block {
display: inline-block !important;
}

.align-middle {
vertical-align: middle !important;
}
<div class="has-border">
<div class="container">
<div class="div1 float-left">
Contact
</div>
<div class="div2 float-right">
<button class="d-inline-block">
Hey
</button>
<svg width="20" height="20">
<circle cx="10" cy="10" r="40"
stroke="green" stroke-width="4" fill="yellow" />
Sorry, your browser does not support inline SVG.
</svg>
</div>
<div class="clearfix"></div>
</div>
</div>

如您所见,按钮和 svg 并排但未垂直对齐。

那么,我怎样才能将 svg 和按钮并排放置并且垂直对齐呢?

最佳答案

我用了flexbox对齐元素并稍微清理一下代码。

.container {
padding: 1rem;
display: flex;
align-items: center; /* vertical alignment */
}

.has-border {
border: 2px solid #000;
}

.div2 {
margin-left: auto; /* Pushes it to the right */
display: flex;
align-items: center; /* vertical alignment */
}
<div class="has-border">
<div class="container">
<div class="div1">
Contact
</div>
<div class="div2">
<button>
Hey
</button>
<svg width="20" height="20">
<circle cx="10" cy="10" r="40"
stroke="green" stroke-width="4" fill="yellow" />
Sorry, your browser does not support inline SVG.
</svg>
</div>
</div>
</div>

关于html - 如何并排放置 svg 和按钮并垂直对齐它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52930915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com