javascript - 如何垂直居中一系列 svg 圆圈?
问题描述
我有一系列 SVG 创建的圆圈,旁边有文本,每个圆圈都有特定的边距,以创建类似“C”的形状。我很难将它们垂直居中。
我最初的尝试是创建一个容器,其中包含<ul>
一系列<li>
. 我的想法是,<ul>
它将包含它自己的形状,因此具有完整高度的容器将使列表居中,创建我想要的,不幸的是,它没有按预期工作。
我的第二个想法是使用 bootstrap4 行列网格系统,但是当我将高度设置为满时,列完全满了,它不起作用。
这是我的列表尝试的代码,
<div class="nav_bar_container align-middle">
<ul id="nav_bar">
<li style="margin-left: 50px;" class="nav_child">
<svg height="100" width="100">
<circle id="About" cx="50" cy="50" r="30" stroke-width="3" class="expand active"> </circle>
<text>
<b> About </b>
</text>
</svg>
</li>
<li style="margin-left: 15px;" class="nav_child">
<svg height="100" width="100">
<circle id="Experience" cx="50" cy="50" r="30" stroke-width="3" class="expand disabled"> </circle>
</svg>
<span>
<b> Experience </b>
</span>
</li>
</ul>
<div>
谁能教我垂直居中元素以产生所需效果的正确方法?
我需要五个 svg 圆圈来创建一个类似 C 的形状,垂直居中在我的网页左侧。然而这个问题主要要求垂直居中。我的屏幕顶部有一个图像,使用起来很令人沮丧,因此我总是需要这个 css 来帮助,
.nav_bar_container {
background: transparent;
position: fixed;
top: 0;
height: 100vh
}
解决方案
flexbox
您可以使用这里是更新的小提琴来实现这一点:
另外,如果您想从左侧对齐,请删除内联margin-left
集li
.nav_bar_container {
background: transparent;
position: fixed;
top: 0;
height: 100vh;
display: flex;
align-items: center;
}
.nav_child{
display: flex;
align-items: center;
}
<div class="nav_bar_container align-center">
<ul id="nav_bar">
<li class="nav_child">
<svg height="100" width="100">
<circle id="About" cx="50" cy="50" r="30" stroke-width="3" class="expand active"> </circle>
<text>
<b> About </b>
</text>
</svg>
</li>
<li class="nav_child">
<svg height="100" width="100">
<circle id="Experience" cx="50" cy="50" r="30" stroke-width="3" class="expand disabled"> </circle>
</svg>
<span>
<b> Experience </b>
</span>
</li>
</ul>
<div>
推荐阅读
- ssl - 如何使用 httpclient 从 windows 窗体中使用损坏的 ssl 连接到 url
- xml - 在文档具有可选子元素的情况下,使用 Rust 和 Serde 反序列化 XML 的困难
- cuda - CUDA-为什么它不能打印 cuda 代码中的信息?
- bash - shell脚本中的问题,用变量替换显式字符串
- node.js - Joi 数组验证无法转换为数组
- reactjs - TypeError 与“无法读取未定义的属性'长度'”
- php - Yii2:Gridview过滤器中的kartik\Select2下拉列表
- php - Wordpress 将主页设置为首页(WP CLI)
- mysql - 如何检查mysql DB列是否有json对象数组并包含特定字符串
- django - 芹菜信号与 Django 信号