javascript - 给定文本未正确显示在按钮上
问题描述
我的问题是“如何将跨度类集中在按钮上?”。看到这个,箭头以它自己的方式表现,而不是在按钮的中心。如果代码正常工作,一个等边三角形将出现在按钮的左侧,后面跟着Go back to top。而且我的代码有错误,限制了以上述方式出现。这是正在运行的示例,https://codepen.io/vkdatta27/pen/XWdvMQL
.arrow-up {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #101010;
}
<button><span class="arrow-up"></span>Go back to top</button>
解决方案
您可以对按钮容器使用 flexbox 来实现该结果(codepen)。
CSS:
.arrow-up {
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid #101010;
}
.container {
display: flex;
align-items: center;
}
HTML:
<button class="container"><span class="arrow-up"></span>Go back to top</button>
<!-- Arrow up isn't in center like other text -->
推荐阅读
- protocol-buffers - 用于 RPC 调用的 gRPC/protobuf 设计模式涉及固定和大型重复字段的混合?
- r - 如何从字符向量中的不同文本中删除相同的文本块?
- html - 使用 FormArray 而不是 FormControl Angular
- python-3.x - 是否可以在 python3 中进行替代继承?
- python - 使用 Pandas AWS Glue Python Shell 作业
- java - String 类型的方法“nextLine()”未定义
- asp.net-core - .Net Core - 使用授权过滤器检查请求中的变量并修改它
- git - Git - 重新排序分支提交
- spring-boot - 搜索 API 规范
- bash - 解析 csv 以在 bash 中创建哈希表会导致意外功能