javascript - 如何使用 CSS 创建马蹄形仪表

标签 javascript html css

我希望使用 CSS 绘制一个马蹄形仪表,如下图所示:

horse-shoe-gauge

我尝试过的方法是做一些事情,比如创建一个圆圈并像这样的 fiddle 一样切断底部:http://jsfiddle.net/Fz3Ln/12/

标记:

<div class="container">
    <div class="horse-shoe-gauge"></div>
</div>

CSS:

.container {
  width: 200px;
  height: 180px;
  overflow: hidden;
}

.horse-shoe-gauge {

    width: 200px;
    height: 200px;
    -webkit-border-radius: 50%; 
    -moz-border-radius: 50%; 
    border-radius: 50%; 
    border: 10px solid black;
    box-sizing: border-box;
}

但我无法获得圆形底部。

如有任何建议,我们将不胜感激。谢谢。

最佳答案

我添加了一个外容器,然后绝对放置了几个额外的部件以获得您正在寻找的圆形底部。

HTML

<div class="outerContainer">
    <div class="container">
        <div class="horse-shoe-gauge"></div>
    </div>
    <div class="bottom left"></div>
    <div class="bottom right"></div>
</div>

CSS

.outerContainer {
    position: relative;
}
.container {
    width: 200px;
    height: 180px;
    overflow: hidden;
}
.horse-shoe-gauge {
    width: 200px;
    height: 200px;
    -webkit-border-radius: 50%; 
    -moz-border-radius: 50%; 
    border-radius: 50%; 
    border: 10px solid black;
    box-sizing: border-box;
}
.bottom {
    position: absolute;
    width: 25px;
    height: 10px;
    border-radius: 8px;
    background: #000;
}
.left {
    bottom: -6px;
    left: 38px;
    -webkit-transform: rotate(32deg);
}
.right {
    bottom: -6px;
    left: 137px;
    -webkit-transform: rotate(-32deg);
}

这是一个 jsFiddle

关于javascript - 如何使用 CSS 创建马蹄形仪表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24716980/

相关文章:

javascript - 将 HTML 表格导出到 Excel 时无法将数据加载到 excel 文件中

html - 如何删除自定义复选框中的勾号?

javascript - 如何在我的 Rails 4 应用程序中添加时间选择器字段?

javascript - 未捕获的 TypeError : this. props.xxx 不是 React 中的函数

javascript - 基于 JavaScript 中的相对路径导入文件

javascript - 完整日历描述中的新行

javascript - 从 JSP 中读取 javascript 响应

javascript - 在所有输入字段的 div 上应用 onChange 事件

html - 设置 div 最大高度不起作用

javascript - Extjs 6.2.0 现代文件字段作为按钮