html - 使用纯 CSS 创建上下箭头图标或按钮

标签 html css css-shapes arrow-keys

我正在尝试使用纯 CSS 和无背景图像创建如下所示的“向上和向下”控制按钮。

enter image description here

但是当我在“li.className:afterli.className:before ”中为箭头添加 CSS 时,主框的位置移动了。

这是我遇到的问题的 Fiddle > http://jsfiddle.net/8usFk/

下面是相同的代码:

HTML

<div class="positionCameras">
    <ul>
        <li title="Move Up" class="cameraLeft" id="cameraUp"></li>
        <li title="Camera" class="cameraIcon"></li>
        <li title="Move Down" class="cameraRight" id="cameraDown"></li>
    </ul>
</div>

CSS

.positionCameras ul, .positionCameras li {
    margin: 0;
    padding: 0;
    list-style: none;
    display: inline-block;
}
.positionCameras li.cameraLeft, .positionCameras li.cameraIcon, .positionCameras li.cameraRight {
    width: 25px;
    height: 25px;
    cursor: pointer;
    background: #cccccc;
    margin: 5px;
    border-radius: 5px;
    border: 1px solid #aaaaaa;
    box-shadow: 1px 2px 15px #cccccc;
}
.positionCameras li.cameraLeft:before {
    content:" ";
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 5px 10px 5px;
    border-color: transparent transparent #007bff transparent;
}
.positionCameras li.cameraIcon {
    cursor: default;
}
.positionCameras li.cameraRight:before {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8.7px 5px 0 5px;
    border-color: #007bff transparent transparent transparent;
}

如果您需要任何其他信息,请告诉我。

请提出建议。

最佳答案

如果您将伪设置为 display:inline-block(或除内联之外的任何其他值。)您可以调整它的大小。

然后,

  1. 使其居中:text-align:center 在父级上。
  2. vertical-align 它:line-height:20px(25px -5px 是伪元素高度的一半)并设置:vertical- align:middle 到伪元素:

DEMO

.positionCameras ul, .positionCameras li {
    margin: 0;
    padding: 0;
    list-style: none;
    display: inline-block;
    vertical-align:top;/* UPDATE*/
}
.positionCameras li.cameraLeft, .positionCameras li.cameraIcon, .positionCameras li.cameraRight {
    width: 25px;
    height: 25px;
    cursor: pointer;
    background: #cccccc;
    margin: 5px;
    border-radius: 5px;
    border: 1px solid #aaaaaa;
    box-shadow: 1px 2px 15px #cccccc;
    text-align:center;/* UPDATE*/
    line-height:20px;/* UPDATE*/
}
.positionCameras li.cameraLeft:before {
    content:"";
    display:inline-block;/* UPDATE*/
    width: 0;
    height: 0;
    vertical-align:middle;/* UPDATE*/
    border-style: solid;
    border-width: 0 5px 10px 5px;
    border-color: transparent transparent #007bff transparent;
}
.positionCameras li.cameraIcon {
    cursor: default;
}
.positionCameras li.cameraRight:before {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8.7px 5px 0 5px;
    border-color: #007bff transparent transparent transparent;
}

关于html - 使用纯 CSS 创建上下箭头图标或按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24145324/

相关文章:

javascript - 当我单击按钮时,我想随机旋转 "div"

javascript - Firefox 中的 Google 折线图 hAxis 格式有问题

html - 带有包装器和 float 元素的 CSS 布局

jquery - 使用 CSS 创建响应式三 Angular 形

css - 使用 CSS 在 div 的两侧添加箭头?

python - 如何从 urlib2 请求中获取完整的 header 信息?

html - CSS链接到硬盘上的文件?

javascript - 如何防止提交表单后模式关闭

javascript - 光滑的 slider 自动播放不起作用

javascript - 以内圆和外圆为界的三 Angular 形