2
HTML & CSS
Well, it wasn’t an easy task, but it worked:
body{
background: gold;
}
#octagon {
width: 100px; height: 50px; background: white; position: relative;
line-height: 45px;
text-align: center;
color: #fff;
}
#octagon:before {
content: "";
position: absolute;
top: 0;
left: 0;
border-bottom: 10px solid white;
border-left: 10px solid #eee;
border-right: 10px solid #eee;
width: 80px;
height: 0;
}
#octagon:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 10px solid white;
border-left: 10px solid #eee;
border-right: 10px solid #eee;
width: 80px; height: 0;
}
#octagon #octagon-inner{
width: 96px;
height: 46px;
background: gold;
position: relative;
top: 2px;
left: 2px;
}
#octagon #octagon-inner:before {
content: "";
position: absolute;
top: 0;
left: 0;
border-bottom: 10px solid gold;
border-left: 10px solid white;
border-right: 10px solid white;
width: 76px;
height: 0;
}
#octagon #octagon-inner:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 10px solid gold;
border-left: 10px solid white;
border-right: 10px solid white;
width: 76px;
height: 0;
z-index: 10;
}
#border-top:before{
content: "";
position: absolute;
top: 0;
left: 0;
border-bottom: 10px solid transparent;
border-left: 10px solid gold;
border-right: 10px solid transparent;
width: 5px;
height: 0;
z-index: 15;
}
#border-top:after{
content: "";
position: absolute;
top: 0;
right: 0;
border-bottom: 10px solid transparent;
border-left: 10px solid transparent;
border-right: 10px solid gold;
width: 5px;
height: 0;
z-index: 15;
}
#border-bottom:before{
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 10px solid transparent;
border-left: 10px solid gold;
border-right: 10px solid transparent;
width: 5px;
height: 0;
z-index: 15;
}
#border-bottom:after{
content: "";
position: absolute;
bottom: 0;
right: 0;
border-top: 10px solid transparent;
border-left: 10px solid transparent;
border-right: 10px solid gold;
width: 5px;
height: 0;
z-index: 15;
}
#octagon:hover #octagon-inner:after{
border-top-color: #dfbc00;
}
#octagon:hover #octagon-inner:before{
border-bottom-color: #dfbc00;
}
#octagon:hover #octagon-inner{
background-color: #dfbc00;
}
<div id="octagon" >
<div id="border-top" ></div>
<div id="octagon-inner" > TESTE </div>
<div id="border-bottom" ></div>
</div>
In the example above you have a template made completely in CSS and HTML, your application is not difficult, however its manipulation is, when it comes to customization. Its corners are not transparent, are, in this case, the background color of the body
. Because of this, the impression.
SVG
body {
background: gold;
}
#buttonRect{
cursor: pointer;
}
#buttonRect:hover > polygon{
fill: #dfbc00;
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="buttonRect">
<polygon id="button" points="40,5 130,5 145,20 145,60 130,75
40,75 25,60 25, 20" fill='#FFD700' style="stroke:#fff;stroke-width: 2;" />
<text id="buttonText" x="60" y="45" fill="#fff">TESTE</text>
</g>
</svg>
But this svg solution is much simpler to handle, can be done by vector programs, or even some online applications. And much easier customization, the only thing more "laborious" will be the modification of the size by the coordinates of polygon
, what even doing "in hand" does not take long.
I used the :hover
in the <g>
grouping together all the button elements, as I explain in that matter this can be done without problems.
In the polygon
with the attribute points
I specify the coordinates of each point that forms the octagon, following this model:
pt1:(x,y) pt2:(x,y) pt3:(x,y)...
have tried using border-Radius?
– user37612
The border-Radius leaves the edges round, need to leave them straight, the same way this in the post image.
– Marcelo Victor
what bullshit huh ... Oce could create the border in a png image. now in Html5 and css3 I don’t know if it has that function
– user37612
Did you ever take a look at the "border-image-source" property of CSS3? I would use it as a starting point and embed a svg with the drawing inside css.
– PerryWerneck