SVG fill / stroke - html
Need some help with filling my svg with color on hover.
On the left I have my test svg, on the right - the result I want on hover.
How to fill with color on hover only gray lines and let the space inside be transparent (empty)?
(that's strange that space inside is fillinbg with color, because there is no svg content there)
.container {
width: 50%;
margin: 0 auto;
display: flex;
justify-content: space-between;
background: gray;
padding: 20px;
}
svg:hover {
fill: #40bfff;
stroke:#40bfff;
}
<div class="container">
<div>
<svg width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M7.188 19a.562.562 0 100-1.125.562.562 0 000 1.125zM15.063 19a.562.562 0 100-1.125.562.562 0 000 1.125z" fill="#9098B1" stroke="#9098B1" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/><path d="M1 1h2.25L5.5 14.5h11.25L19 4.375H4.375" stroke="#9098B1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</div>
<!-- changing stroke and fill to color i need -->
<div>
<svg width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M7.188 19a.562.562 0 100-1.125.562.562 0 000 1.125zM15.063 19a.562.562 0 100-1.125.562.562 0 000 1.125z" fill="#40bfff" stroke="#40bfff" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/><path d="M1 1h2.25L5.5 14.5h11.25L19 4.375H4.375" stroke="#40bfff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</div>
</div>
All you have to do to change the wheel fill colour is add a second rule targetting the wheels.
Note: The SVG below is exactly the same as your original one. Except that I have reformatted it a little, and added a viewBox so that we can scale it up to see the wheels. I wanted to show that you can style the SVG how you want without having to change the SVG.
svg {
/* just here to make the svg large enough to see the wheel centres */
width: 200px;
height: 200px;
}
svg:hover path {
stroke: #40bfff;
}
/* Target the first path (the wheels) */
svg:hover path:nth-child(1) {
fill: #40bfff;
}
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7.188 19a.562.562 0 100-1.125.562.562 0 000 1.125zM15.063 19a.562.562 0 100-1.125.562.562 0 000 1.125z"
fill="#9098B1" stroke="#9098B1"
stroke-width="2" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M1 1h2.25L5.5 14.5h11.25L19 4.375H4.375"
stroke="#9098B1"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
try this:
.container {
width: 50%;
margin: 0 auto;
display: flex;
justify-content: space-between;
background: gray;
padding: 20px;
}
svg:hover path {
stroke: #40bfff;
}
<div class="container">
<div>
<svg width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M7.188 19a.562.562 0 100-1.125.562.562 0 000 1.125zM15.063 19a.562.562 0 100-1.125.562.562 0 000 1.125z" fill="#9098B1" stroke="#9098B1" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/><path d="M1 1h2.25L5.5 14.5h11.25L19 4.375H4.375" stroke="#9098B1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</div>
<!-- changing stroke and fill to color i need -->
<div>
<svg width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M7.188 19a.562.562 0 100-1.125.562.562 0 000 1.125zM15.063 19a.562.562 0 100-1.125.562.562 0 000 1.125z" fill="#40bfff" stroke="#40bfff" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/><path d="M1 1h2.25L5.5 14.5h11.25L19 4.375H4.375" stroke="#40bfff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
</div>
</div>
Put all your stroke & fill attributes into the svg element since that's where your hover is set.
.container {
width: 50%;
margin: 0 auto;
display: flex;
justify-content: space-between;
background: gray;
padding: 20px;
}
svg:hover {
fill: none;
stroke: #40bfff;
}
<div class="container">
<div>
<svg width="20" height="20" stroke="#9098B1" fill-opacity="0" stroke-width="2" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round">
<path d="M7.188 19a.562.562 0 100-1.125.562.562 0 000 1.125zM15.063 19a.562.562 0 100-1.125.562.562 0 000 1.125z" />
<path d="M1 1h2.25L5.5 14.5h11.25L19 4.375H4.375"/>
</svg>
</div>
Related
How can I translate an element and at the same time rotate realistically?
It turns out of position and moves incorrectly. It's hard to find the exact point so it looks realistic and the transitions are smooth. the turning is out of cue and can not find a solution to make it turn faster as it moves at its normal rate. I have tried many times to get the exact timing but I cant find a way. function wid() { if (window.innerWidth < 960) { var r = document.querySelector(':root'); r.style.setProperty('--wid', '100%'); } wid(); } #car { background-color: transparent; width: 10px; height: 20px; transform: translate(241.5px, 215px); position: relative; animation-name: driving; animation-duration: 10s; animation-timing-function: linear; /*linear ease-in-out*/ } #map { background-color: transparent; width: 400px; margin: auto; position: absolute; transform: translate(5%, 5%); } #bod { background-color: green; position: absolute; width: 100%; height: 100%; } html, body { margin: 0px; padding: 0px; width: 100%; height: 100%; } .mainsec {} #keyframes driving { 0% { transform: translate(241.5px, 215px); } 10% { transform: translate(241.5px, 40px)rotate(-60deg); } 28% { transform: translate(41.5px, 86px)rotate(-125deg); } 38% { transform: translate(41.5px, 300px)rotate(-180deg); } 40% { transform: translate(120px, 360px)rotate(-220deg); } 50% { transform: translate(160px, 360px)rotate(-125deg); } 60% { transform: translate(200px, 450px)rotate(-230deg); } 70% { transform: translate(400px, 460px)rotate(-360deg); } 80% { transform: translate(260.5px, 215pxrotate(360deg)); } 90% { transform: translate(241.5px, 180pxrotate(360deg)); } 100% { transform: translate(241.5px, 215pxrotate(360deg)); } } <div id="bod"> <div id="map"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="415.00774" height="464.03421" viewBox="0,0,415.00774,464.03421"> <g transform="translate(-5.56354,24.30861)"> <g data-paper-data="{"isPaintingLayer":true}" fill-rule="nonzero" stroke-width="0" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" style="mix-blend-mode: normal"> <path d="M193.21864,323.70241c2.08101,14.58763 -0.75936,39.6034 -0.75936,39.6034l-76.95053,-59.65507c0,0 27.04231,-21.9967 43.16349,-20.31537c5.01955,0.5235 15.96324,3.86994 22.75063,11.80093c6.7874,7.93099 11.43447,26.03343 11.79578,28.56611z" fill="#e2ea8f" stroke="none"/> <path d="M5.56688,290.21195c0.51544,-15.25718 8.62251,-39.2653 8.62251,-39.2653l75.02651,85.4148c0,0 -34.79132,12.85441 -52.63063,5.75382c-5.55452,-2.21087 -17.2321,-9.2315 -23.32635,-19.42903c-6.09425,-10.19755 -7.78154,-29.82536 -7.69204,-32.47428z" fill="#e2ea8f" stroke="none"/> <path d="M219.05583,250.34734v-212.80012c0,0 1.48764,-14.0667 -3.9272,-17.72172c-5.41484,-3.65502 -26.47434,-0.83576 -26.47434,-0.83576l-66.30684,14.95228c0,0 -31.54844,6.49453 -43.16799,13.0135c-11.85598,6.65162 -17.65815,11.05621 -23.81015,25.35199c-6.15201,14.29579 -4.49552,155.45874 -4.49552,155.45874c0,0 0.12847,18.24631 2.32244,26.68213c1.97899,7.60918 18.15757,34.8776 33.34816,40.17712c19.19535,6.69665 43.22077,-3.09306 62.42146,3.17404c13.17719,4.30105 19.38737,8.26387 26.48485,18.94892c8.15443,12.27627 12.12432,31.97154 14.43416,37.56194c3.22503,7.80536 6.42812,17.86233 6.42812,17.86233l3.4807,18.08984c0,0 1.03251,15.13972 8.75099,18.80522c6.38845,3.03387 114.48707,3.64998 151.55195,3.77223c7.71664,0.02545 10.45146,1.27859 12.93151,-2.85614c1.26925,-2.11608 1.73211,-6.23932 -2.62668,-9.76101c-4.15809,-3.35953 -50.05552,-4.44025 -50.05552,-4.44025l8.83274,-34.13795c0,0 28.4294,-1.70463 51.65944,4.28594c23.23005,5.99057 28.02805,8.6783 34.85366,27.38878c4.72033,16.40398 10.64834,45.16217 -7.11765,45.35982c-60.58922,0.67405 -196.5872,1.94573 -217.63794,0.05149c-6.61359,-0.59513 -10.36459,-4.25214 -10.90643,-5.25027c-2.18537,-4.02565 -3.47544,-7.21102 -4.98448,-12.09238c-1.50902,-4.88135 -11.88057,-53.84601 -20.93852,-71.76255c-6.71889,-13.2899 -21.01689,-13.36816 -21.01689,-13.36816l-36.99995,-0.31926c0,0 -24.73763,1.62251 -39.7364,-10.8668c-11.6551,-9.70507 -19.2506,-18.21353 -27.99162,-32.54346c-8.74102,-14.32992 -9.25637,-22.76613 -12.14607,-33.25777c-2.88029,-10.45743 -3.43264,-33.62966 -3.43264,-33.62966c0,0 2.31202,-92.96558 1.9462,-152.4744c-0.07076,-11.51164 3.51657,-14.76709 6.12168,-20.3207c3.4054,-7.25967 10.81182,-13.80213 10.81182,-13.80213c0,0 19.26399,-15.40827 29.93019,-21.31454c10.50848,-5.81894 33.60085,-13.86497 33.60085,-13.86497l94.80812,-23.31008c0,0 15.46605,-4.62962 28.36495,-4.85435c11.96737,-0.2085 21.24293,3.77639 25.88139,8.78947c2.73367,2.95445 8.45832,9.73142 10.28464,14.53415c4.2386,11.14628 2.66852,21.78451 2.66852,21.78451v229.54004c0,0 -1.40764,17.5481 -0.50008,26.82662c0.34086,3.48486 4.70635,31.95634 21.05493,49.25219c15.8564,16.77515 51.49572,35.54486 51.49572,35.54486l-8.29877,33.81234c0,0 -16.52481,-0.78157 -32.88652,-13.95939c-14.69724,-7.65388 -27.17248,-17.57315 -36.41394,-27.55132c-16.40866,-17.71676 -22.39766,-35.61914 -24.07827,-41.35593c-5.39145,-18.40375 -8.51881,-62.56938 -8.51881,-62.56938z" fill="#414141" stroke="#000000"/> <path d="M219.05583,165.09336v-5.97191h38.14575v5.97191z" fill="#d2d2d2" stroke="#000000"/> <path d="M224.72917,199.44555v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M240.9985,199.47883v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M224.72915,169.62976v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M240.99849,169.66305v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M224.72915,184.69724v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M240.9985,184.73053v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M224.73546,228.96504v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M241.00479,228.99833v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M224.73546,214.21673v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M241.00479,214.25002v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/> <path d="M203.48125,23.23113l-0.09191,-5.49181c0,0 9.04848,-1.64122 13.01789,1.24562c2.86101,2.08074 4.05979,12.06922 4.05979,12.06922l-6.28979,0.0411c0,0 -0.42661,-5.56759 -3.14675,-7.23476c-2.27102,-1.39192 -7.54922,-0.62936 -7.54922,-0.62936z" fill="#bd0000" stroke="none"/> <path d="M207.96794,23.16086v-5.85189c0,0 2.70134,0.06002 4.01174,0.21819c1.25881,0.15192 3.70211,0.71279 3.70211,0.71279l-4.38891,5.71888c0,0 -1.13567,-0.40556 -1.69516,-0.53983c-0.5486,-0.13166 -1.62977,-0.25815 -1.62977,-0.25815z" fill="#bdbdbd" stroke="none"/><path d="M214.08583,31.1407l-0.66499,-3.85692l5.98488,-1.59597l0.93098,5.18691z" fill="#bdbdbd" stroke="none"/> </g> </g> </svg> </div> <div id="car"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="5.69151" height="13.00614" viewBox="0,0,5.69151,13.00614"> <g transform="translate(-237.15425,-173.49693)"> <g data-paper-data="{"isPaintingLayer":true}" fill-rule="nonzero" stroke-width="0" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" style="mix-blend-mode: normal"> <path d="M237.95271,176.91509v-0.36484h1.65836v0.36484z" fill="#7e7e7e" stroke="none"/><path d="M240.4616,177.96722l-0.10174,-0.19425l1.68345,-0.8818l0.10175,0.19425z" data-paper-data="{"index":null}" fill="#7e7e7e" stroke="none"/> <path d="M240.40631,176.94827v-0.36484h1.65836v0.36484z" data-paper-data="{"index":null}" fill="#7e7e7e" stroke="none"/> <path d="M237.87231,177.05225l0.10177,-0.19425l1.68345,0.8818l-0.10174,0.19425z" fill="#7e7e7e" stroke="none"/> <path d="M237.68777,185.93213l0.07908,-4.54285l0.04206,-0.67016l0.26596,-0.28733c0,0 0.87932,-0.26451 1.13707,-0.61548c0.38158,-0.51961 0.30716,-1.61303 0.30716,-1.61303l0.13902,-3.00375l-0.57115,-0.00965l-0.80751,0.2432l-0.79069,-0.00484v-1.58791h2.20561l0.33641,-0.34338l0.34463,0.34338h2.13582v1.58791l-0.66608,0.00627l-0.80156,-0.27803l-0.63165,-0.00276l0.13298,3.04754c0,0 -0.04796,1.08621 0.37004,1.67854c0.27203,0.38548 1.01745,0.57779 1.01745,0.57779c0,0 0.22801,0.19788 0.25867,0.29475c0.03066,0.09686 0.03601,0.63613 0.03601,0.63613l0.08511,4.54371z" fill="#000000" stroke="#000000"/> <path d="M237.15425,177.61095v-1.79988h0.82698v1.79988z" fill="#353535" stroke="none"/> <path d="M242.01878,177.65959v-1.79987h0.82697v1.79987z" fill="#353535" stroke="none"/> <path d="M237.15425,186.26759v-1.79987h1.0923v1.79987z" fill="#353535" stroke="none"/> <path d="M241.75344,186.31622v-1.79986h1.0923v1.79986z" fill="#353535" stroke="none"/> <path d="M238.35111,185.93798l0.0268,-1.54014l-0.65122,-0.69631l0.04014,-2.30639l0.04206,-0.67016l0.26596,-0.28734c0,0 0.87933,-0.26451 1.13708,-0.61549c0.38158,-0.51961 0.30716,-1.61302 0.30716,-1.61302l0.13902,-3.00375l0.03627,-1.35921l0.33641,-0.34338l0.34463,0.34338l0.03653,1.31338l0.13297,3.04753c0,0 -0.04796,1.08623 0.37004,1.67854c0.27203,0.38548 1.01745,0.57779 1.01745,0.57779c0,0 0.22801,0.19788 0.25867,0.29475c0.03066,0.09686 0.03602,0.63613 0.03602,0.63613l0.0426,2.27394l-0.64783,0.79572l0.06016,1.47404z" fill="#f30000" stroke="#000000"/> <path d="M238.82256,186.50307v-0.92868h2.35487v0.92868z" fill="#000000" stroke="none"/> <path d="M239.43365,180.99989v-1.46517c0,0 0.25408,-0.66824 0.56634,-0.65782c0.34514,0.01152 0.56635,0.65782 0.56635,0.65782v1.46517z" fill="#7e7e7e" stroke="none"/> <path d="M239.99999,180.68103c-0.17989,0 -0.32574,-0.16918 -0.32574,-0.37787c0,-0.20869 0.14583,-0.37787 0.32574,-0.37787c0.17989,0 0.32575,0.16918 0.32575,0.37787c0,0.20869 -0.14584,0.37787 -0.32575,0.37787z" fill="#f30000" stroke="none"/> </g> </g> </svg> </div> </div>
SVG text, tspan font-size and centered
I have an issue with font size on SVG as us can see in svg the font-size:16px different from paragraph font-size but the they have the same value 16px. I would like to have font size in svg such on paragraph. The second issue, it's how to center <tspan text-anchor="middle" class="tc-label-value">85</tspan> when I delete <tspan class="label-text" text-anchor="middle" x="0" y="50" dy="15">Text in SVG</tspan> I mean the is a case when I have Text in svg and have not https://codepen.io/palaniichukdmytro/pen/BaaKbze
SVG text, & span font-size and center solution body { margin: 0; } .wr { width: 180px; margin: 0 auto; } .label-text { font-size: 12px; text-align: center; } .tc-label-value { font-size: 12px; text-align: center; } .par { font-size: 16px; text-align: center; } <div class='wr'> <svg viewBox="0 0 100 100" width="100%" height="100%" style="display: block;"> <path d="M 95.5 50 A 45.5 45.5 0 1 1 11.315120324302569 26.047336589080288" stroke-width="9" stroke-dasharray="168.16760675098308" stroke-dashoffset="2.842170943040401e-14" stroke="#a3bfff" stroke-linecap="round" fill="none" style="transition: stroke-dashoffset 500ms ease-out 0s;"></path> <path d="M 11.315120324302569 26.047336589080288 A 45.5 45.5 0 0 1 95.5 49.999999999999986" stroke-width="9" stroke-dasharray="117.71732472568812" stroke-dashoffset="0" stroke="#66bb6a" stroke-linecap="round" fill="none" style="transition: stroke-dashoffset 500ms ease-out 0s;"></path> <text transform="translate(50)" x="0" y="50"> <tspan text-anchor="middle" class="tc-label-value">85</tspan> <tspan class="label-text" text-anchor="middle" x="0" y="50" dy="15">Text in SVG</tspan> </text> </svg> <p class='par'>Text Paragraph</p> </div>
The font size for the svg element should be 8.88px. Why? Because the svg's width is 100 units or px ( viewBox="0 0 100 100" ) and is scaled up to 180px ( .wr{width: 180px;} ). Since you need the font size inside the svg to look like 16px, the real font size should be 16 * 100 / 180 = 8.88 .wr { width: 180px; } .par{ font-size: 16px; } svg{font-size: 8.88px;} <div class='wr'> <svg viewBox="0 0 100 100" style="display: block;"> <path d="M 95.5 50 A 45.5 45.5 0 1 1 11.315120324302569 26.047336589080288" stroke-width="9" stroke-dasharray="168.16760675098308" stroke-dashoffset="2.842170943040401e-14" stroke="#a3bfff" stroke-linecap="round" fill="none" style="transition: stroke-dashoffset 500ms ease-out 0s;"></path> <path d="M 11.315120324302569 26.047336589080288 A 45.5 45.5 0 0 1 95.5 49.999999999999986" stroke-width="9" stroke-dasharray="117.71732472568812" stroke-dashoffset="0" stroke="#66bb6a" stroke-linecap="round" fill="none" style="transition: stroke-dashoffset 500ms ease-out 0s;"></path> <text transform="translate(50)" x="0" y="50"> <tspan text-anchor="middle" class="tc-label-value">85</tspan> <tspan class="label-text" text-anchor="middle" x="0" y="50" dy="15">Text in SVG</tspan> </text> </svg> <p class='par'>Text Paragraph</p> </div>
SVG property vector-effect="non-scaling-stroke" still scales stroke
In SVG, I need the PATH stroke width to remain as is while viewBox property is changing. The SVG property vector-effect="non-scaling-stroke" should accomplish that but it is not working as it suppose to. Can someone explain why in the code below (check the codepen.io) the stroke width still increases as viewbox changes? I would also appreciate a solution that makes strokes width constant regardless of viewbox. https://codepen.io/anon/pen/eKQrYL HTML <div class="Item"> <div class="Item-graphic"> <svg id='scaling-stroke' width="200" height="200" viewBox="0 0 50 50"> <circle cx="25" cy="25" r="20" fill="none" stroke="#fff" stroke-width="2"/> <path d="M25 15 L 25 35" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round"/> <path d="M15 25 L 35 25" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round"/> </svg> </div> <span> 50 x 50 view box<br> 200 x 200 dimensions<br> no vector effect </span> </div> <div class="Item"> <div class="Item-graphic"> <svg id='non-scaling-stroke' width="200" height="200" viewBox="0 0 50 50"> <circle cx="25" cy="25" r="20" fill="none" stroke="#fff" stroke-width="2" vector-effect="non-scaling-stroke"/> <path d="M25 15 L 25 35" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke"/> <path d="M15 25 L 35 25" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" vector-effect="non-scaling-stroke"/> </div> </svg> <span> 50 x 50 view box<br> 200 x 200 dimensions<br> vector effect </span> </div> CSS *, *::before, *::after { box-sizing: border-box; } body { display: flex; align-items: center; justify-content: center; width: 100vw; height: 100vh; background-color: #2196F3; font-family: Helvetica, sans-serif; font-weight: 300; line-height: 1.5; } svg { display: block; margin: 0 auto; } .Item { flex: 0 0 200px; padding: 0 1rem; color: rgba(#fff, 0.6); font-size: 11px; text-align: center; } .Item-graphic { display: flex; align-items: center; height: 220px; } JS n=1;inc=1; cvb = function(){ vb = '' + n vb += ' ' + n vb += ' ' + 2*(25-n) vb += ' ' + 2*(25-n) $('#non-scaling-stroke').attr('viewBox', vb) $('#scaling-stroke').attr('viewBox', vb) n += inc; if (n<=1 || n>=24) inc *= -1; setTimeout(cvb, 100); }; cvb()
It is a bug in Chrome. The bug report is here https://bugs.chromium.org/p/chromium/issues/detail?id=849080. It was fixed in Chrome version 68.0.3440.25.
Inverse transparent area in SVG
I have this SVG : <svg class="decor" height="100%" preserveAspectRatio="none" version="1.1" viewBox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg"> <path d="M0 0 L50 100 L100 0 L100 100 L0 100" stroke-width="0"></path> </svg> This works but I need to have transparent outer and black color inner. In my code this is currently inverse. How to generate this? DEMO
Just change the coordinates of your SVG path (d attribute) to form a triangle instead of the shape. The modified path (d="M0 0 L50 100 L100 0z") works as follow: M0 0 - Moves the pen to 0,0 (top left corner) L 50 100 - Draws a line from 0,0 to 50,100 (which is bottom center point) L 100 0 - Draws a line from 50,100 to 100 0 (which is top right corner) z - Closes the path by drawing a line from the last point (100,0) to the first point (0,0) SVG path elements by default get a black colored fill and hence the triangle gets colored black whereas the outside remains transparent. * { background: #e1e1e1; } .decor { height: 80px } <div class="decor"> <svg class="decor" height="100%" preserveAspectRatio="none" version="1.1" viewBox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg"> <path d="M0 0 L50 100 L100 0z" stroke-width="0"></path> </svg> </div> Clip Image using Path: If the need is to use the path to clip background image into the required shape then it would be better to use clipPath element and clip-path CSS property like in the below snippet: * { background: #e1e1e1; } .decor { height: 80px; background: url(http://lorempixel.com/200/80); -webkit-clip-path: url(#clipper); clip-path: url(#clipper); } <div class="decor"> <svg height="0" preserveAspectRatio="none" version="1.1" viewBox="0 0 100 100" width="0" xmlns="http://www.w3.org/2000/svg"> <defs> <clipPath id="clipper" clipPathUnits="objectBoundingBox"> <path d="M0 0 L.5 1 L1 0z"></path> </clipPath> </defs> </svg> </div> Putting all the pieces together, the below code should achieve the output that was provided in the image. .div-1 { position: relative; height: 500px; width: 100%; } .decor-top { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: url('http://lorempixel.com/550/500'); -webkit-clip-path: url(#clipper); clip-path: url(#clipper); } .div-2 { position: absolute; bottom: 0; left: 0; height: 50%; width: 100%; background-image: url('http://kinderhtml.themerex.net/img/bg/texture_2.png'); background-color: green; -webkit-clip-path: url(#clipper2); clip-path: url(#clipper2); } <div class="div-1"> <div class="decor-top"> <svg height="0" preserveAspectRatio="none" version="1.1" viewBox="0 0 100 100" width="0" xmlns="http://www.w3.org/2000/svg"> <defs> <clipPath id="clipper" clipPathUnits="objectBoundingBox"> <path d="M0 0 L.5 .1 L1 0 1,1 0,1z"></path> </clipPath> </defs> </svg> </div> <div class="div-2"> <svg height="0" preserveAspectRatio="none" version="1.1" viewBox="0 0 100 100" width="0" xmlns="http://www.w3.org/2000/svg"> <defs> <clipPath id="clipper2" clipPathUnits="objectBoundingBox"> <path d="M0 0 L.5 .25 L1 0 1,1 0,1z"></path> </clipPath> </defs> </svg> </div> </div> The original path (d="M0 0 L50 100 L100 0 L100 100 L0 100") worked as follows: M0 0 - Moves the pen to 0,0 (top left corner) L 50 100 - Draws a line from 0,0 to 50,100 (which is bottom center point) L 100 0 - Draws a line from 50,100 to 100 0 (which is top right corner) L 100 100 - Draws a line from 100,0 to 100,100 (which is bottom right corner) L0 100 - Draws a line from 100,100 to 0,100 (which is bottom left corner) Thus the above path ends up a forming a shape which looks like a rectangle with a triangle cut-out at the top.
rotate svg fill path box
I design box border using svg like this : HTML: <svg class="decor" height="100%" preserveaspectratio="none" version="1.1" viewbox="0 0 100 100" width="100%" xmlns="http://www.w3.org/2000/svg"> <path d="M0 0 L100 100 L0 100" stroke-width="0"></path> </svg> CSS: .decor { fill: #F00; stroke: #e74c3c; } result: Now i need to rotation to this: How do generate this?! DEMO FIDDLE
Add transform="rotate(180, 50, 50)" to the path .decor { fill: #F00; stroke: #e74c3c; } <svg class="decor" height="100%" viewBox="0 0 100 100" width="100%" preserveAspectRatio="none" > <path transform="rotate(180, 50, 50)" d="M0 0 L100 100 L0 100"></path> </svg>
Just do this: .decor { fill: #F00; stroke: #e74c3c; -webkit-transform: rotate(180deg); transform: rotate(180deg); } This will rotate it to be the way you want. Fiddle: http://jsfiddle.net/jkvp1x8m/