2

我正在制作一个所有样式都在 css3 中的游戏。

正如您在演示中看到的那样,框架的两侧都有按钮。但目前我不得不为按钮包装器制作图像,因为我无法通过 css3 找到优雅的解决方案。

我已经为视网膜屏幕制作了这些图像,因此您无法区分代码和图像之间的区别,但我希望看到它的副本作为 css 形状,但我不确定这是否可能?

非常感谢您的帮助

编辑:这个形状的两边都有一个 4 像素的纯白色边框,外侧有一个 2 像素的盒子阴影(取决于它是左侧还是右侧)。

形状

HTML

<div class="interaction farmyard">

<div class="page-decorations"></div>

<div class="nav">
    <div class="left"><span class="btn prev"></span></div>
    <div class="right"><span class="btn next"></span></div>
</div>

CSS

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
    border: 0 none;
    font: inherit;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none outside none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
*, *:before, *:after {
    -moz-box-sizing: border-box;
}
.clearfix:after {
    clear: both;
    content: "";
    display: table;
}
body {
    background: none repeat scroll 0 0 #71AFDF;
    font-family: 'Open Sans';
}
.interaction {
    background: none repeat scroll 0 0 #E7F3FF;
    border: 4px solid #FFFFFF;
    border-radius: 16px 16px 16px 16px;
    box-shadow: 0 2px 2px rgba(1, 1, 1, 0.2);
    color: #054B98;
    height: 620px;
    margin: 35px auto 20px;
    padding: 20px;
    position: relative;
    width: 930px;
}
.page-decorations {
    background: none repeat scroll 0 0 #00576F;
    border: 4px solid #FFFFFF;
    border-radius: 9px 9px 9px 9px;
    height: 100%;
    overflow: hidden;
    position: relative;
}
.interaction .nav {
    left: -42px;
    margin-top: -80px;
    position: absolute;
    right: -42px;
    top: 50%;
}
.interaction .nav > div {
    background: url("http://s16.postimg.org/5fp9qny85/button_containers_retina.png") no-repeat scroll 0 0 / 250px 165px transparent;
    border-radius: 100% 100% 100% 100%;
    height: 165px;
    left: -1px;
    position: absolute;
    width: 125px;
}
.interaction .nav > .right {
    background-position: -122px 0;
    left: auto;
    right: 2px;
}
.interaction .nav > .left > .btn {
    display: block;
    left: 25px;
    position: absolute;
    top: 44px;
}
.interaction .nav > .right > .btn {
    display: block;
    position: absolute;
    right: 21px;
    top: 44px;
}
.btn {
    background: none repeat scroll 0 0 #108FE8;
    border: 4px solid #FFFFFF;
    border-radius: 100% 100% 100% 100%;
    box-shadow: 0 -2px 0 3px #0869AF inset, 0 5px 5px rgba(24, 24, 25, 0.17), 0 15px rgba(255, 255, 255, 0.25) inset;
    cursor: pointer;
    display: inline-block;
    -webkit-transition: all 100ms ease-in 0s;
    -moz-transition: all 100ms ease-in 0s;
    transition: all 100ms ease-in 0s;
    height: 75px;
    width: 75px;
}
4

3 回答 3

6

我破旧的尝试:D

http://jsfiddle.net/takrN/5/

我的目标是只用一个来创建形状,<div>但这有点棘手!最后我有了主要的形状,但没有边框和阴影

这很有趣 :D 如果我有时间,我稍后会尝试改进!

更新:我已经尝试过 Troy Alford 推荐的方式!它看起来更准确,最后是带有阴影的边框!圆形边框不能 100% 匹配,但是……只有一个div匹配!只有一个div!我割喉!:D

这是另一个带有正确边框的版本(有点重叠),但是......有两个<div>:http: //jsfiddle.net/takrN/8/

于 2013-06-11T06:52:49.533 回答
4

这是一个很好的开始:http: //jsfiddle.net/carasin/QMaBc/16/

如果你真的深入研究它,你会发现它是创建矩形和覆盖弯曲部分的组合。

我确实必须在标记中添加一些内容:

<div class="interaction farmyard">
    <div class="page-decorations"></div>
        <div class="nav">
            <div class="left">
                <span class="btn prev"></span>
                <div class="top-right-corner"></div>
                <div class="bottom-right-corner"></div>
            </div>
            <div class="right">
                <span class="btn next"></span>
                <div class="top-left-corner"></div>
                <div class="bottom-left-corner"></div>
            </div>
        </div>
    </div>
</div>

CSS,看看小提琴。

.interaction .nav > div {
    background: #E7F3FF;
    border:5px solid #fff;
    border-radius: 100% 100% 100% 100%;
    height: 101px;
    width: 101px;
    left: -1px;
    position: absolute;
    z-index:1;
}
.interaction .nav > .right {
    left: auto;
    right: -1px;
}
.interaction .nav > .left > .btn {
    display: block;
    left: 9px;
    position: absolute;
    top: 9px;
}
.interaction .nav > .right > .btn {
    display: block;
    position: absolute;
    right: 9px;
    top: 9px;
}
.btn {
    background: none repeat scroll 0 0 #108FE8;
    border: 4px solid #FFFFFF;
    border-radius: 100% 100% 100% 100%;
    box-shadow: 0 -2px 0 3px #0869AF inset, 0 5px 5px rgba(24, 24, 25, 0.17), 0 15px rgba(255, 255, 255, 0.25) inset;
    cursor: pointer;
    display: inline-block;
    -webkit-transition: all 100ms ease-in 0s;
    -moz-transition: all 100ms ease-in 0s;
    transition: all 100ms ease-in 0s;
    height: 75px;
    width: 75px;
}
.btn:after {
    content:"";
    display:block;
    background:#E7F3FF;
    height:130px;
    width:31px;
    position:absolute;
    left:25px;
    top:-26px;
    z-index:-1;
}
.right .btn:after {
    left:auto;
    right:25px;
}
.top-right-corner {
    content:"";
    display: block;
    width: 14px;
    height: 37px;
    background: #00576F;
    border-radius: 0 0 0 29px;
    position: absolute;
    top: -38px;
    right: 25px;
    border-left: 4px solid #fff;
    border-bottom: 4px solid #fff;
}
.top-right-corner:before {
    content:"";
    display: block;
    width: 40px;
    height: 40px;
    background: #00576F;
    border-radius: 95px;
    position: absolute;
    top: 0px;
    right: -27px;
}
.bottom-right-corner {
    content:"";
    display: block;
    width: 14px;
    height: 37px;
    background: #00576F;
    border-radius: 29px 0 0 0;
    position: absolute;
    bottom: -36px;
    right: 25px;
    border-left: 4px solid #fff;
    border-top: 4px solid #fff;
}
.bottom-right-corner:before {
    content:"";
    display: block;
    width: 40px;
    height: 40px;
    background: #00576F;
    border-radius: 95px;
    position: absolute;
    top: -3px;
    right: -29px;
}
.top-left-corner {
    content:"";
    display: block;
    width: 14px;
    height: 37px;
    background: #00576F;
    border-radius: 0 0 29px 0;
    position: absolute;
    top: -38px;
    left: 25px;
    border-right: 4px solid #fff;
    border-bottom: 4px solid #fff;
}    
.top-left-corner:before {
    content:"";
    display: block;
    width: 40px;
    height: 40px;
    background: #00576F;
    border-radius: 95px;
    position: absolute;
    top: 0px;
    left: -27px;
}
.bottom-left-corner {
    content:"";
    display: block;
    width: 14px;
    height: 37px;
    background: #00576F;
    border-radius: 0 29px 0 0;
    position: absolute;
    bottom: -36px;
    left: 25px;
    border-right: 4px solid #fff;
    border-top: 4px solid #fff;
}
.bottom-left-corner:before {
    content:"";
    display: block;
    width: 40px;
    height: 40px;
    background: #00576F;
    border-radius: 95px;
    position: absolute;
    top: -3px;
    left: -29px;
}
于 2013-06-11T02:39:52.487 回答
0

我完全不知道这是否会有所帮助,但是您是否考虑过将图像转换为画布?这会以任何方式满足您的要求吗?

如果您可以使用 javascript 来完成此操作,这里有一些很好的信息。

话虽如此,并非所有浏览器/设备都支持画布绘图

我被困在只能对具有 3D UI 要求的跨设备/跨平台应用程序使用 css3D 转换,并尝试使用 SVG 放屁。这很痛苦。

于 2013-06-10T22:44:14.323 回答