I have to do it like this
I want to make this icon from two elements. There are should be blue background and svg. How can I make this?
This is my code:
.facebook_logo {
fill: white;
stroke: black;
display: inline-block;
width: 22px;
height: 40px;
}
<svg display="none">
<symbol id="facebook" viewBox="0 0 23.101 23.101">
<path d="M8.258,4.458c0-0.144,0.02-0.455,0.06-0.931c0.043-0.477,0.223-0.976,0.546-1.5c0.32-0.522,0.839-0.991,1.561-1.406
C11.144,0.208,12.183,0,13.539,0h3.82v4.163h-2.797c-0.277,0-0.535,0.104-0.768,0.309c-0.231,0.205-0.35,0.4-0.35,0.581v2.59h3.914
c-0.041,0.507-0.086,1-0.138,1.476l-0.155,1.258c-0.062,0.425-0.125,0.819-0.187,1.182h-3.462v11.542H8.258V11.558H5.742V7.643
h2.516V4.458z"/>
</symbol>
</svg>
<svg class="facebook_logo">
<use xlink:href="#facebook"></use>
</svg>
Use same width & height and add some padding.
.facebook_logo {
fill: white;
stroke: black;
display: inline-block;
width: 20px;
height: 20px;
background: #000;
padding: 10px; /* your icon's total width & height is 40px */
border-radius: 8px;
}
<svg display="none">
<symbol id="facebook" viewBox="0 0 23.101 23.101">
<path d="M8.258,4.458c0-0.144,0.02-0.455,0.06-0.931c0.043-0.477,0.223-0.976,0.546-1.5c0.32-0.522,0.839-0.991,1.561-1.406
C11.144,0.208,12.183,0,13.539,0h3.82v4.163h-2.797c-0.277,0-0.535,0.104-0.768,0.309c-0.231,0.205-0.35,0.4-0.35,0.581v2.59h3.914
c-0.041,0.507-0.086,1-0.138,1.476l-0.155,1.258c-0.062,0.425-0.125,0.819-0.187,1.182h-3.462v11.542H8.258V11.558H5.742V7.643
h2.516V4.458z"/>
</symbol>
</svg>
<svg class="facebook_logo">
<use xlink:href="#facebook"></use>
</svg>
This is an example using flex on a parent div + hover;
.facebook_logo {
fill: white;
stroke: black;
display: inline-block;
width: 22px;
height: 40px;
}
.facebook_ {
background-color: #3b5998;
width: 50px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 20%;
transition: .3s;
cursor: pointer;
}
.facebook_:hover {
background-color: grey;
}
<svg display="none">
<symbol id="facebook" viewBox="0 0 23.101 23.101">
<path d="M8.258,4.458c0-0.144,0.02-0.455,0.06-0.931c0.043-0.477,0.223-0.976,0.546-1.5c0.32-0.522,0.839-0.991,1.561-1.406
C11.144,0.208,12.183,0,13.539,0h3.82v4.163h-2.797c-0.277,0-0.535,0.104-0.768,0.309c-0.231,0.205-0.35,0.4-0.35,0.581v2.59h3.914
c-0.041,0.507-0.086,1-0.138,1.476l-0.155,1.258c-0.062,0.425-0.125,0.819-0.187,1.182h-3.462v11.542H8.258V11.558H5.742V7.643
h2.516V4.458z"/>
</symbol>
</svg>
<div class="facebook_">
<svg class="facebook_logo">
<use xlink:href="#facebook"></use>
</svg>
<div>
<svg id=FaceBookLogo width=100px viewBox='0 0 300 300'>
<rect fill='#3b5998' width='100%' height='100%' rx='15%'/>
<path fill='white' d='M110 80c0-1 0-5 1-9 0-5 2-10 6-15 3-5 8-10 16-14 7-4
18-6 31-6h38v42h-28c-3 0-5 1-8 3-2 2-3 4-3 6v26h39c0
5-1 10-1 15l-1 13c-1 4-1 8-2 12h-35v115h-52v-115
h-25v-39h25v-32z'/>
</svg>
<style>
#FaceBookLogo rect{
fill:var(--FBblue,#3b5998);
}
#FaceBookLogo path{
fill:var(--FBwhite,white)
}
#FaceBookLogo:hover{
--FBblue:green;
--FBwhite:gold;
width:150px;
}
</style>
I used https://yqnn.github.io/svg-path-editor/ to multiply the path definition by a scale 10 to get rid of all decimal positions and still maintain some accuracy in the letter F outline.
Now play with the 300 viewBox size to scale the letter, and change M110 80 at the start of the path (x y) to position the letter.
I need to make a circle emulating the button for closing the window in the Mac OS. But when I try to move it lower, svg's border cuts it off. How can I move the border to place the circle directly in the middle of the panel (vertically)?
JSFiddle: https://jsfiddle.net/sm6r0kvn/2/
<div class="panel">
<svg viewbox="0 0 20 17" width="20" heigth="50"><circle r="7" cx="14" cy="9.5" fill="#fc615e"/></svg>
</div>
You can set your viewbox like <svg viewbox="0 0 20 20" width="20" heigth="20"> and then set cx and cy 50%. If you want to center it in the panel vertically just make it a flexbox and add align-items: center - see demo below:
.block {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
max-width: 550px;
min-width: 480px;
width: 80vw;
height: 200px;
background: black;
border-radius: 10px 10px 5px 5px;
}
.panel {
background-color: #e0e0e0;
border-radius: 5px 5px 0 0;
display: flex; /* added */
align-items: center; /* added */
}
.text {
color: white;
padding: 5px;
}
<div class="block">
<div class="panel">
<svg viewbox="0 0 20 20" width="20" heigth="20">
<circle r="7" cx="50%" cy="50%" fill="#fc615e"/>
</svg>
</div>
<div class="text">
Text here
</div>
</div>
This is because you are drawing your cicrcle outside of the svg viewbox. You can either use CSS to move whole svg box or make it larger
svg {
border: 1px blue solid;
}
.panel.moved {
margin-left: 100px;
}
<div class="panel">
<svg viewbox="0 0 20 20" width="200" heigth="200">
<circle r="10" cx="10" cy="10" fill="#fc615e"/>
</svg>
</div>
<div class="panel">
<svg viewbox="0 0 20 20" width="200" heigth="200">
<circle r="10" cx="20" cy="10" fill="#fc615e"/>
</svg>
</div>
<div class="panel">
<svg viewbox="0 0 30 20" width="300" heigth="200">
<circle r="10" cx="20" cy="10" fill="#fc615e"/>
</svg>
</div>
<div class="panel moved">
<svg viewbox="0 0 20 20" width="200" heigth="200">
<circle r="10" cx="10" cy="10" fill="#fc615e"/>
</svg>
</div>
I have a 16x16px SVG with 10px of padding and 1px border and for some reason, the height is 40px instead of 38px, like the width (on my local site, it's actually 36.95x44px). What can I do to eliminate this extra space and achieve a perfect square?
.layout-toggle {
display: inline-block;
padding: 10px;
border: 1px solid grey;
}
.layout-toggle.layout-active {
background-color: black;
}
.layout-toggle.layout-active svg {
fill: white;
width: 1em;
height: 1em;
}
.layout-toggle .layout-icon {
width: 1em;
height: 1em;
vertical-align: middle;
}
<a href="#">
<div class="layout-toggle">
<svg class="layout-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16px" viewbox="0 0 17 16" style="enable-background:new 0 0 17 16;" xml:space="preserve">
<g>
<g>
<g id="calendar-view-01">
<g>
<g id="Calender-Layout-Icon_no-border-1">
<path d="M0.3,0h4v4h-4V0z M0.3,6h4v4h-4V6z M0.3,12h4v4h-4V12z M6.3,0h4v4h-4V0z M6.3,6h4v4h-4V6z M6.3,12h4v4h-4
V12z M12.3,0h4v4h-4V0L12.3,0z M12.3,6h4v4h-4V6L12.3,6z M12.3,12h4v4h-4V12L12.3,12z" />
</g>
</g>
</g>
</g>
</g>
</svg>
</div>
</a>
http://codepen.io/ourcore/pen/rjLmRM
That is because your <svg> element is displayed inline by default. If you explicitly declare display: block on the element, the height will compute correctly.
When inline display is active, the element will often have "uncontrollable" height due to the fact that:
you cannot explicitly dictate vertical dimensions—be it margin, padding, height—on inline elements, resulting in unpredictable dimensions and
the element's vertical height is influenced by line height inherited from the text node.
.layout-toggle {
display: inline-block;
padding: 10px;
border: 1px solid grey;
}
.layout-toggle.layout-active {
background-color: black;
}
.layout-toggle.layout-active svg {
fill: white;
width: 1em;
height: 1em;
}
.layout-toggle .layout-icon {
display: block; /* Use display: block to force proper height */
width: 1em;
height: 1em;
vertical-align: middle;
}
<a href="#">
<div class="layout-toggle">
<svg class="layout-icon" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16px" viewbox="0 0 17 16" style="enable-background:new 0 0 17 16;" xml:space="preserve">
<g>
<g>
<g id="calendar-view-01">
<g>
<g id="Calender-Layout-Icon_no-border-1">
<path d="M0.3,0h4v4h-4V0z M0.3,6h4v4h-4V6z M0.3,12h4v4h-4V12z M6.3,0h4v4h-4V0z M6.3,6h4v4h-4V6z M6.3,12h4v4h-4
V12z M12.3,0h4v4h-4V0L12.3,0z M12.3,6h4v4h-4V6L12.3,6z M12.3,12h4v4h-4V12L12.3,12z" />
</g>
</g>
</g>
</g>
</g>
</svg>
</div>
</a>
I'm in the process of creating a circular menu using SVG. There's going to be five parts in total, with each piece being built using an SVG path element. I also have an icon generated via a use attribute. It calls a symbol attribute that defines the SVG icon.
The issue I'm running into is that Firefox (v45.0.1, latest version as today for me) for some reason isn't rendering the icon at all. I noticed that if I inspect the SVG element, the symbol section is grayed out in Firefox (whereas in Chrome, it's not).
On the second example I've posted, I noticed that when inspecting the use element, it's not rotated like it should be, almost as if Firefox is ignoring the rotation attribute entirely.
The first example is built off the original code where I first noticed the issue. The second one mentioned earlier is a variation where I modified the SVG code to be a specific size, as the original dimensions I was handed over by a designer wasn't in the 0,0 coordinates --- not sure if this is an issue since it didn't cause an issue in any other browsers besides Firefox.
Any ideas what the cause may be? I have the examples collapsed since the code is a bit long with both of them visible at once (let me know if you guys would prefer one to be made visible and I can update it).
(Note that due to how it's setup, you'll need to scroll some to the left and the right to see the segment I have visible, depending on your screen settings.)
.wrapper {
padding: 80px;
position: relative;
text-align: center;
width: 100%;
}
.wrapper svg {
display: inline-block;
height: 100%;
touch-action: none;
transform: matrix3d(0.59051, -0.80703, 0, 0, 0.80703, 0.59051, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform-origin: 50% 50% 0;
-webkit-transform: matrix3d(0.59051, -0.80703, 0, 0, 0.80703, 0.59051, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
-webkit-transform-origin: 50% 50% 0;
-webkit-user-select: none;
}
.wrapper svg symbol {
overflow: visible;
}
.wrapper svg a {
cursor: pointer;
outline: none;
}
.wrapper svg #item-procurement .sector {
fill: #f8ba10;
stroke: #f8ba10;
}
<div class="wrapper" style="height: 978px;">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-2 -2 504 504" id="menu">
<g id="symbolsContainer">
<symbol class="icon" id="icon-procurement-desktop" viewBox="0 0 39 39">
<g>
<path stroke="#1a1302" stroke-width="1.5" d="M25.9,44.8v63.1h111h3.1V44.8H25.9z M139.3,107.2h-2.4H26.6V45.6h112.7V107.2z"></path>
<path stroke="#1a1302" stroke-width="1.5" class="st2" d="M101.1,107.6"></path>
<rect stroke="#1a1302" stroke-width="1.5" x="31.9" y="51.1" width="0.8" height="50.7"></rect>
<path stroke="#1a1302" stroke-width="1.5" d="M115.7,49.6H50.2v0.8h27.9c-6.5,2-11.1,8.1-11.1,15.2v21.2c0,7.1,4.7,13.2,11.1,15.2H50.2v0.8h65.4V102H87.8c6.5-2,11.1-8.1,11.1-15.2V65.5c0-7.1-4.7-13.2-11.1-15.2h27.9C115.7,50.3,115.7,49.6,115.7,49.6z M98.2,65.5v21.2c0,8.4-6.8,15.2-15.2,15.2s-15.2-6.8-15.2-15.2V65.5c0-8.4,6.8-15.2,15.2-15.2C91.3,50.3,98.2,57.1,98.2,65.5z"></path>
<path stroke="#1a1302" stroke-width="1.5" d="M36.3,59.4L36.3,59.4v-0.8c0,0,3.4,0,5.8-2.4c1.7-1.6,2.5-4.1,2.5-7.2h0.8c0,3.3-0.9,5.9-2.8,7.7C40.1,59.3,36.8,59.4,36.3,59.4z"></path>
<path stroke="#1a1302" stroke-width="1.5" d="M45.4,103.8h-0.8c0-3.1-0.9-5.5-2.5-7.2c-2.4-2.4-5.8-2.4-5.8-2.4v-0.8c0.1,0,3.7,0,6.4,2.6C44.5,97.9,45.4,100.5,45.4,103.8z"></path>
<rect stroke="#1a1302" stroke-width="1.5" x="32.2" y="113.4" width="108" height="0.8"></rect>
<rect stroke="#1a1302" stroke-width="1.5" x="42.8" y="119.1" width="97.4" height="0.8"></rect>
</g>
</symbol>
</g>
<g id="itemsContainer">
<a class="item" id="item-procurement" role="link" tabindex="0" transform="matrix(-0.80901,0.58778,-0.58778,-0.80901,599.2005616668552,305.30793552061857)" data-svg-origin="250 250">
<path d="M415,250 l85,0 A250,250 0 0,0 327.25424859373686,12.235870926211618 l-26.26644452187054,80.83980388508806 A165,165 0 0,1 415,250" class="sector"></path>
<use xlink:href="#icon-procurement-desktop" width="21" height="21" x="370.12713623046875" y="92.61793518066406" transform="rotate(-90 413.62713623046875 131.11793518066406)"></use>
</a>
</g>
</svg>
</div>
.wrapper {
padding: 80px;
position: relative;
text-align: center;
width: 100%;
}
.wrapper svg {
display: inline-block;
height: 100%;
touch-action: none;
transform: matrix3d(0.59051, -0.80703, 0, 0, 0.80703, 0.59051, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
transform-origin: 50% 50% 0;
-webkit-transform: matrix3d(0.59051, -0.80703, 0, 0, 0.80703, 0.59051, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
-webkit-transform-origin: 50% 50% 0;
-webkit-user-select: none;
}
.wrapper svg symbol {
overflow: visible;
}
.wrapper svg a {
cursor: pointer;
outline: none;
}
.wrapper svg #item-procurement .sector {
fill: #f8ba10;
stroke: #f8ba10;
}
<div class="wrapper" style="height: 978px;">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-2 -2 504 504" id="menu">
<g id="symbolsContainer">
<symbol class="icon" id="icon-procurement-desktop" viewBox="0 0 19 15.81">
<g>
<g>
<rect stroke="#1a1302" stroke-width="1.5" x="1.2" y="1.4" width="3" height="0.1"/>
<rect stroke="#1a1302" stroke-width="1.5" x="1.2" y="2.4" width="4.6" height="0.1"/>
<path stroke="#1a1302" stroke-width="1.5" stroke-miterlimit="10" d="M8.5,5"/>
</g>
<g>
<path stroke="#1a1302" stroke-width="1.5" d="M17,6.4V0H0v13.5h12.5L11,15.8h8V3.3L17,6.4z M0.1,13.4V0.1h16.8v6.4l-1.1,1.6V2.4H8.4v3.1H1.3v6h7.3v-0.9h5.8l-1.8,2.8
H0.1z M8.4,7.3v4.1h-7V5.6H6v3.2H2.9V9h3.2V5.6h2.4V2.5h3.8v6h2.8V8.3h-2.7V2.5h1.8v3h0.1v-3h1.4v3h-0.6v0.1h0.6v2.8h0l-1.3,2.1
H8.6V7.3H8.4z M18.9,5.7h-0.6v0.1h0.6v1.4h-0.6v0.1h0.6v1.4h-0.6v0.1h0.6v1.4h-0.6v0.1h0.6v1.4h-0.6v0.1h0.6v1.4h-0.6v0.1h0.6v1.4
h-0.6v0.1h0.6v0.8h-7.7l7.7-11.9V5.7z"/>
<path stroke="#1a1302" stroke-width="1.5" d="M17,10.2v3.7h-2.4L17,10.2L17,10.2z M17.1,9.8L14.4,14h2.7V9.8L17.1,9.8z"/>
</g>
</g>
</symbol>
</g>
<g id="itemsContainer">
<a class="item" id="item-procurement" role="link" tabindex="0" transform="matrix(-0.80901,0.58778,-0.58778,-0.80901,599.2005616668552,305.30793552061857)" data-svg-origin="250 250">
<path d="M415,250 l85,0 A250,250 0 0,0 327.25424859373686,12.235870926211618 l-26.26644452187054,80.83980388508806 A165,165 0 0,1 415,250" class="sector"></path>
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-procurement-desktop" width="19" height="15.81" x="413.12713623046875" y="131.61793518066406" transform="rotate(-90 413.62713623046875 131.11793518066406)" />
</a>
</g>
</svg>
</div>
I am trying to implement the
http://demosthenes.info/blog/760/Create-A-Responsive-Imagemap-With-SVG
to my needs
The problem is that I want the button Ive created to change the style of a div outside the figure tag. I can not find a way to do that.
All I need is by hovering over the .my-1 button, to display the .y1 div
Here is the code so far.
<style type="text/css">
#burj-imagemap {
overflow: hidden;
padding-bottom: 75%;
vertical-align: middle;
width: 100%;
}
#burj-imagemap svg {
display: inline-block;
left: 0;
position: absolute;
top: 0;
}
.my-1:hover {background:#fff; z-index:100; opacity:0.3; filter: alpha(opacity=30); border:1px solid #000;
}
.my-1 {cursor: pointer;}
.y1 {
display: none;
}
.my-1:hover .y1 {
display: block;
background-color: #F00;
height: 250px;
width: 250px;
z-index:1000;
}
</style>
<figure id="burj-imagemap">
<svg preserveAspectRatio="xMinYMin meet" viewBox="0 0 1200 808" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1">
<image xlink:href="http://demosthenes.info/assets/images/burj-khalifa.jpg" height="808" width="1200">
</image>
<a class="my-1" >
<g>
<defs>
<polygon id="SVGID_1_" points="322,131 62,240 79,346 274,250 412,405 501,250"/>
</defs>
<clipPath id="SVGID_2_">
<use xlink:href="#SVGID_1_" overflow="visible"/>
</clipPath>
<g clip-path="url(#SVGID_2_)">
<image overflow="visible" width="1200" height="808" xlink:href="http://demosthenes.info/assets/images/burj-khalifa.jpg" transform="matrix(1 0 0 1 -33.5 -301)">
</image>
</g>
</g></a>
</svg>
</figure>
<div class="y1">Hi!</div>
any ideas?
You could include an event handler in the svg like this..
<g clip-path="url(#SVGID_2_)" onmouseover="document.getElementById('y1').style['display'] = 'inline';">
<div id="y1" class="y1">Hi!</div>
fiddle here http://jsfiddle.net/9mDur/