繁体   English   中英

如何在div内垂直居中span / svg

[英]How to vertically center a span/svg inside a div

小提琴: https//jsfiddle.net/6yfv3u5m/

HTML:

<div id="dvMore">
    <div id="dvMore2">
        <span id="spMore">View More</span>
        <svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="#000000" d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"></path></svg>
    </div>
</div>

我没有高度,只有动态内容。

编辑:尝试将dvMore2设置为vertically-align: center 还尝试添加占位符范围并将vertical-align设置为center但它们都不起作用。

添加display: flex; align-items: center;

https://jsfiddle.net/6yfv3u5m/1/

使用如下所示的vertical-align属性。 您需要在子项上设置它,而不是父项本身:

 #dvMore2 * { vertical-align: middle; } 
 <div id="dvMore"> <div id="dvMore2"> <span id="spMore">View More</span> <svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="#000000" d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"></path></svg> </div> </div> 

如何将<kbd>内容</kbd>垂直居中<div></div><div id="text_translate"><p>我正在尝试制作钢琴,但我从基础开始。 我住在以<strong>div</strong>的内部内容为中心。 我希望它位于他父亲 div 的中间并居中</p><p>继承人代码:html</p><pre> &lt;div class="keys"&gt; &lt;div class="key" id="keyA"&gt; &lt;kbd&gt;A&lt;/kbd&gt; &lt;/div&gt; &lt;div class="key" id="keyS"&gt; &lt;kbd&gt;S&lt;/kbd&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> css:</p><pre> * { margin: 0; padding: 0; box-sizing: border-box; } body{ background-color: chocolate; }.keys{ padding: 4px 5px; position: fixed; height: 40%; max-height: 60%; width: 60%; max-width: 80%; display: flex; justify-content: space-around; top: 50%; left: 50%; transform: translate(-50%, -50%); border: white solid; align-items: center; text-align: center; }.key{ border: black solid 1px; font-family: 'Montserrat', sans-serif; font-size: 22px; max-height: 95%; height: 90%; width: 70px; max-width: 95%; border-radius: 10px; } kbd{ /*border to see the with and weight*/ border: pink solid 1px; color: aliceblue; }</pre><p> 这是一个小提琴: <a href="https://jsfiddle.net/hnd9jr4y/" rel="nofollow noreferrer">https://jsfiddle.net/hnd9jr4y/</a>谢谢</p></div>

[英]How to center vertically <kbd> content inside an <div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在div中垂直居中放置跨度和列表? 如何在div内的span内垂直居中img? 如何在div中垂直居中放置跨度? 如何在SPAN中垂直居中图像 在悬停时垂直居中div中的跨度 如何在IE中的div中垂直居中放置文本? 如何在div中垂直居中按钮和文本 如何在div内部垂直居中放置汉堡图标? 如何在div内垂直居中放置列表? 如何将<kbd>内容</kbd>垂直居中<div></div><div id="text_translate"><p>我正在尝试制作钢琴,但我从基础开始。 我住在以<strong>div</strong>的内部内容为中心。 我希望它位于他父亲 div 的中间并居中</p><p>继承人代码:html</p><pre> &lt;div class="keys"&gt; &lt;div class="key" id="keyA"&gt; &lt;kbd&gt;A&lt;/kbd&gt; &lt;/div&gt; &lt;div class="key" id="keyS"&gt; &lt;kbd&gt;S&lt;/kbd&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> css:</p><pre> * { margin: 0; padding: 0; box-sizing: border-box; } body{ background-color: chocolate; }.keys{ padding: 4px 5px; position: fixed; height: 40%; max-height: 60%; width: 60%; max-width: 80%; display: flex; justify-content: space-around; top: 50%; left: 50%; transform: translate(-50%, -50%); border: white solid; align-items: center; text-align: center; }.key{ border: black solid 1px; font-family: 'Montserrat', sans-serif; font-size: 22px; max-height: 95%; height: 90%; width: 70px; max-width: 95%; border-radius: 10px; } kbd{ /*border to see the with and weight*/ border: pink solid 1px; color: aliceblue; }</pre><p> 这是一个小提琴: <a href="https://jsfiddle.net/hnd9jr4y/" rel="nofollow noreferrer">https://jsfiddle.net/hnd9jr4y/</a>谢谢</p></div>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM