Given the following HTML
<div id="field-filter-TIPO" class="css-1hqm095 container">
<svg
aria-hidden="true"
role="img"
class="octicon octicon-x-circle-fill css-djuh4e"
viewBox="0 0 12 12"
width="12"
height="12"
fill="currentColor"
style="
display: inline-block;
user-select: none;
vertical-align: text-bottom;
overflow: visible;
"
>
<path
fill-rule="evenodd"
d="M1.757 10.243a6 6 0 118.486-8.486 6 6 0 01-8.486 8.486zM6 4.763l-2-2L2.763 4l2 2-2 2L4 9.237l2-2 2 2L9.237 8l-2-2 2-2L8 2.763l-2 2z"
></path>
</svg>
<div style="font-size: 16px; width: auto" class="css-1bmhiq9">
<svg viewBox="25 25 50 50" width="1em" height="1em" class="css-1bez47e">
<circle
cx="50"
cy="50"
r="22"
fill="none"
stroke="currentColor"
stroke-width="6"
stroke-miterlimit="10"
class="css-frwtbx"
></circle>
</svg>
</div>
<div
title="ColumnFilter"
kind="ColumnFilter"
id="columnfilter--fetching"
name="Fetching"
class="css-utvy5"
>
<button class="css-m8wrzs">
<svg
stroke="currentColor"
fill="currentColor"
stroke-width="0"
viewBox="0 0 24 24"
font-size="16"
class="css-1cx02qk"
height="1em"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M21 3H5a1 1 0 0 0-1 1v2.59c0 .523.213 1.037.583 1.407L10 13.414V21a1.001 1.001 0 0 0 1.447.895l4-2c.339-.17.553-.516.553-.895v-5.586l5.417-5.417c.37-.37.583-.884.583-1.407V4a1 1 0 0 0-1-1zm-6.707 9.293A.996.996 0 0 0 14 13v5.382l-2 1V13a.996.996 0 0 0-.293-.707L6 6.59V5h14.001l.002 1.583-5.71 5.71z"
></path>
</svg>
</button>
</div>
</div>
why this selector
.container div > svg {
margin-right: -8px;
}
is not affecting the first svg (the X icon)?
Should't the selector pick all the svg whose parent is a div inside the elements with the .container class? My goal is to create a selector to apply to the X icon (svg) and the second svg (the circle icon).
jsfiddle
Should't the selector pick all the svg whose parent is a div inside the elements with the .container class? My goal is to create a selector to apply to the X icon (svg) and the second svg (the circle icon).
Well the first svg is not inside div... it's in a container... try adding it ina div and check
For now, there is no parent selector in CSS (only child selector). However, you can use the JS property .parentNode
Related
so i have a little problem with a svg, this svg is align on left side, but i want make it to the right side, I've tried using x and y but its not working, please help me
<svg width="498" height="99" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M0 36C0 2.863 26.8629-24 60-24
h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D"/>
</svg>
You can use an outer div like this:
<div class='outer-div' >
<!-- SVG Element -->
<svg></svg>
</div>
And in the CSS file:
.outer-div{
display:flex;
flex-direction: row-reverse;
}
There could be a number of options depending on the context. Here I present:
CSS float
CSS text-align
CSS position
CSS flexbox
and SVG viewBox
CSS float
A bit old-school I guess. It works, but the downside is that the SVG takes up 0 px height.
svg {
float: right;
}
<svg width="498" height="99" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M0 36C0 2.863 26.8629-24 60-24
h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D"/>
</svg>
CSS text-align
The SVG is displayed as an inline element, so it behaves like a text.
.parent {
text-align: right;
}
<div class="parent">
<svg width="498" height="99" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M0 36C0 2.863 26.8629-24 60-24
h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D"/>
</svg>
</div>
CSS position
If the parent is positioned relative (or absolute) and the SVG is positioned absolute the property right can be used for aligning the SVG.
.parent {
position: relative;
}
svg {
position: absolute;
right: 0;
}
<div class="parent">
<svg width="498" height="99" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M0 36C0 2.863 26.8629-24 60-24
h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D"/>
</svg>
</div>
CSS flexbox
The more modern version of the above examples.
.parent {
display: flex;
justify-content: flex-end;
}
<div class="parent">
<svg width="498" height="99" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M0 36C0 2.863 26.8629-24 60-24
h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D"/>
</svg>
</div>
SVG vieBox
And lastly, by using the viewBox attribute instead of the width and the height attributes, the <path> can be positioned in the right side of the SVG itself (the transform attribute). The SVG will take up 100 % of the width at all times and the <path> will therefore also "float" to the right. This will make the SVG scale up and down depending on the width available.
<svg viewBox="0 0 700 99" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path transform="translate(262 0)" d="M0 36C0 2.863 26.8629-24 60-24
h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D"/>
</svg>
Like this?
<svg width="498" height="99" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 36C0 2.863 26.8629-24 60-24h438V99H60C26.8629 99 0 72.1371 0 39v-3Z" fill="#2D2D2D" transform="scale (-1, 1)" transform-origin="center" />
</svg>
Cann't find the way to make it works:
I marked up pathes of SVG inside symbols with classnames
In outer CSS I made styling rules for those pathes
SVG inserted in HTML using mark up
On hover event I want to change styling of path with current classname
<style>
body>svg{display:none}
.st2,.st2_1{fill:#b0b2b4}
svg:hover .st2_1{fill:#f47456}
</style>
<a href="#">
<svg clacc="ico_vk">
<use xlink:href="#ico_vk" />
</svg>
</a>
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="ico_vk" viewBox="0 0 24 24">
<path class="st2" d="M20.9 10.51c0 .31-.24.57-.55.57s-.55-.25-.55-.57c0-.31.24-.57.55-.57s.55.26.55.57zm0 0"/>
<path class="st2" d="M20.38 8.29c.25 0 .45-.21.45-.47V5.96c0-.79-.62-1.43-1.38-1.43H4.36c-.41 0-.78.19-1.05.51a.8.8 0 00-.13.13c-.15.24-.23.51-.23.8V18.4c0 .79.62 1.43 1.38 1.43h15.09c.76 0 1.38-.64 1.38-1.43v-5.28c0-.26-.2-.47-.45-.47a.46.46 0 00-.45.47v5.28c0 .28-.22.5-.48.5H4.33c-.27 0-.48-.23-.48-.5V5.88c0-.04.02-.08.04-.12.01-.01.02-.01.03-.02.12-.15.37-.27.55-.27h14.98c.27 0 .48.22.48.5v1.86c0 .25.2.46.45.46z"/>
<path class="st2_1" d="M9.47 14.43c-.24-.48-.48-1.04-.72-1.68s-.47-1.34-.69-2.1h1.09c.05.19.1.39.16.61s.13.44.19.66.13.44.2.65c.07.21.13.4.2.57.06-.17.13-.36.19-.57s.14-.43.2-.65.13-.44.19-.66c.06-.22.12-.42.16-.61h1.06c-.22.76-.45 1.46-.69 2.1-.24.64-.48 1.2-.72 1.68h-.82zM13.3 12.01c.1-.11.21-.23.31-.36.11-.12.21-.25.31-.37l.29-.35c.09-.11.17-.2.23-.29h1.22c-.24.29-.48.57-.71.83-.23.27-.49.54-.76.82.14.13.28.28.43.46s.29.37.43.56c.14.19.26.38.38.57.11.19.21.37.29.53h-1.18c-.07-.13-.16-.26-.25-.41-.09-.15-.19-.3-.3-.45-.11-.15-.22-.3-.33-.44s-.23-.26-.35-.35v1.66h-1.03v-5.4l1.03-.17v3.16z"/>
</symbol>
</svg>
Example here https://codepen.io/sPoul/pen/oNLPrMg
Is it passable to make it works with CSS only?
So I find the answer by myself
body>svg{display:none}
.st2{fill:#b0b2b4}
use{color:#b0b2b4}
a:hover use{color:#f47456}
.st2_1{fill:currentColor}
<a href="#">
<svg clacc="ico_vk">
<use xlink:href="#ico_vk" />
</svg>
</a>
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="ico_vk" viewBox="0 0 24 24">
<path class="st2" d="M20.9 10.51c0 .31-.24.57-.55.57s-.55-.25-.55-.57c0-.31.24-.57.55-.57s.55.26.55.57zm0 0"/>
<path class="st2" d="M20.38 8.29c.25 0 .45-.21.45-.47V5.96c0-.79-.62-1.43-1.38-1.43H4.36c-.41 0-.78.19-1.05.51a.8.8 0 00-.13.13c-.15.24-.23.51-.23.8V18.4c0 .79.62 1.43 1.38 1.43h15.09c.76 0 1.38-.64 1.38-1.43v-5.28c0-.26-.2-.47-.45-.47a.46.46 0 00-.45.47v5.28c0 .28-.22.5-.48.5H4.33c-.27 0-.48-.23-.48-.5V5.88c0-.04.02-.08.04-.12.01-.01.02-.01.03-.02.12-.15.37-.27.55-.27h14.98c.27 0 .48.22.48.5v1.86c0 .25.2.46.45.46z"/>
<path class="st2_1" d="M9.47 14.43c-.24-.48-.48-1.04-.72-1.68s-.47-1.34-.69-2.1h1.09c.05.19.1.39.16.61s.13.44.19.66.13.44.2.65c.07.21.13.4.2.57.06-.17.13-.36.19-.57s.14-.43.2-.65.13-.44.19-.66c.06-.22.12-.42.16-.61h1.06c-.22.76-.45 1.46-.69 2.1-.24.64-.48 1.2-.72 1.68h-.82zM13.3 12.01c.1-.11.21-.23.31-.36.11-.12.21-.25.31-.37l.29-.35c.09-.11.17-.2.23-.29h1.22c-.24.29-.48.57-.71.83-.23.27-.49.54-.76.82.14.13.28.28.43.46s.29.37.43.56c.14.19.26.38.38.57.11.19.21.37.29.53h-1.18c-.07-.13-.16-.26-.25-.41-.09-.15-.19-.3-.3-.45-.11-.15-.22-.3-.33-.44s-.23-.26-.35-.35v1.66h-1.03v-5.4l1.03-.17v3.16z"/>
</symbol>
</svg>
The solution for me is to pass color information through the CurrentColor variable and use the color property of the USE tag.
I have 2 SVG elements: (Material Design Icons)
<svg xmlns="http://www.w3.org/2000/svg" height='24' viewBox="0 0 24 24" width='24'><path d="M0 0h24v24H0z" fill="none" /><path fill='#fff' d="M19 7v2.99s-1.99.01-2 0V7h-3s.01-1.99 0-2h3V2h2v3h3v2h-3zm-3 4V8h-3V5H5c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2v-8h-3zM5 19l3-4 2 3 3-4 4 5H5z" /></svg>
<svg xmlns="http://www.w3.org/2000/svg" height='24' viewBox="0 0 24 24" width='24'><g><rect fill="none" height="24" width="24" /><path fill='#fff' d="M21.9,21.9l-8.49-8.49l0,0L3.59,3.59l0,0L2.1,2.1L0.69,3.51L3,5.83V19c0,1.1,0.9,2,2,2h13.17l2.31,2.31L21.9,21.9z M5,18 l3.5-4.5l2.5,3.01L12.17,15l3,3H5z M21,18.17L5.83,3H19c1.1,0,2,0.9,2,2V18.17z" /></g></svg>
I put them in a container like so:
<div style="display: flex; justify-content: center; align-items: center;">
<svg>#1 element</svg>
<svg>#2 element</svg>
</div>
As, you can see, both width and height of the elements are set to 24 and yet the output on the DOM shows different dimentions:
I'm no expert when it comes to SVG and the rules about sizes relative to it's container etc..
Is there a way I can set the same size for both SVG elements and get the proper result ?
I've done some searching but have been unable to figure things out. I was hoping I would be able to place and <a> tag in between two svg tags to make a button but it has thus far not worked. What I was thinking was doing:
<svg class="triangle-animation" width="85" height="85">
<polygon points="0,25 25,50, 50,25" fill="rgba(255,255,255,.1)"/>
<polygon points="0,12.5 25,37.5, 50,12.5" fill="rgba(255,255,255,.5)"/>
<polygon points="0,0 25,25, 50,0" fill="rgba(255,255,255.8)"/>
</svg>
but no luck. I also tried putting some text inside of the a tag but it didn't even appear. The guides I have looked for have not thus far been very helpful. I'm brand new to web design and I'm just trying to get my personal webpage going.
The svg draws three triangles on top of one another pointing down. The behaviour I'm looking for is that they draw the eye down and when clicked the page jumps down to main content. Thanks for the help!
try wrapping your tags around the svg instead.
<a href="about.html">
<svg class="triangle-animation" width="85" height="85">
<polygon points="0,25 25,50, 50,25" fill="rgba(255,255,255,.1)"/>
<polygon points="0,12.5 25,37.5, 50,12.5" fill="rgba(255,255,255,.5)"/>
<polygon points="0,0 25,25, 50,0" fill="rgba(255,255,255.8)"/>
</svg>
</a>
Use the to wrap the svg and style it
.SvgButton{
padding: 5px;
border: 1px solid red;
display: flex;
width: 50px;
}
<a class="SvgButton" href="#"><svg class="triangle-animation" width="85" height="85">
<polygon points="0,25 25,50, 50,25" fill="rgba(255,0,0,.3)"/>
<polygon points="0,12.5 25,37.5, 50,12.5" fill="rgba(0,255,255,.5)"/>
<polygon points="0,0 25,25, 50,0" fill="rgba(255,0,255,.8)"/>
<path d="M27 64c0 1.654-1.346 3-3 3s-3-1.346-3-3 1.346-3 3-3 3 1.346 3 3zm9-.449s-4.252 8.449-11.985 8.449c-7.18 0-12.015-8.449-12.015-8.449s4.446-7.551 12.015-7.551c7.694 0 11.985 7.551 11.985 7.551zm-7 .449c0-2.757-2.243-5-5-5s-5 2.243-5 5 2.243 5 5 5 5-2.243 5-5z"/>
</svg></a>
A better solution would be to use svg symbol definition -> look
You can manage icons more easily.
.icon {
width: 50px;
height: 50px;
}
.animation {
display: flex;
}
.mail {
background-color: #dc4e41;
fill: #fff;
}
<svg xmlns="http://www.w3.org/2000/svg" style="display:none">
<symbol id="triangle-animation" viewBox="0 0 50 50">
<path fill="rgba(255,0,0,.3)" d="M0 25l25 25 25-25z" />
<path fill="rgba(0,255,255,.5)" d="M0 12.5l25 25 25-25z" />
<path fill="rgba(255,0,255,.8)" d="M0 0l25 25L50 0z" />
</symbol>
<symbol id="share-icon-mail" viewBox="-7 -6 42 42">
<path
d="M26 23.5v-12a8.408 8.408 0 0 1-1.078 1.031c-2.234 1.719-4.484 3.469-6.656 5.281-1.172.984-2.625 2.188-4.25 2.188h-.031c-1.625 0-3.078-1.203-4.25-2.188-2.172-1.813-4.422-3.563-6.656-5.281A8.411 8.411 0 0 1 2.001 11.5v12c0 .266.234.5.5.5h23c.266 0 .5-.234.5-.5zm0-16.422C26 6.687 26.094 6 25.5 6h-23c-.266 0-.5.234-.5.5 0 1.781.891 3.328 2.297 4.438a980.43 980.43 0 0 1 6.266 4.953c.828.672 2.328 2.109 3.422 2.109h.031c1.094 0 2.594-1.437 3.422-2.109a946.207 946.207 0 0 1 6.266-4.953c1.016-.797 2.297-2.531 2.297-3.859zm2-.578v17c0 1.375-1.125 2.5-2.5 2.5h-23A2.507 2.507 0 0 1 0 23.5v-17C0 5.125 1.125 4 2.5 4h23C26.875 4 28 5.125 28 6.5z">
</path>
</symbol>
</svg>
<a href="about.html">
<svg class="icon animation">
<use xlink:href="#triangle-animation"></use>
</svg>
</a>
<svg class="icon mail">
<use xlink:href="#share-icon-mail"></use>
</svg>
This question already has answers here:
inline-block boxes not fitting in their container [duplicate]
(2 answers)
Closed 6 years ago.
Codepen here.
As the snippet shows, the first element and second one have no spacing between them, but the third one have, I don't know if it's a CSS problem or a SVG problem. I got same result on Chrome and MS Edge.
CSS here:
.controls-inline {
display: inline-block;
}
HTML here:
<div id="ctrl-panel">
<div class="controls-inline controls-btn" id="play-btn-wrapper">
<svg id="play-btn" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 58 58" xml:space="preserve" width="50px" height="50px">
<circle style="fill:#EBBA16;" cx="29" cy="29" r="29"></circle>
<g>
<polygon id="play-btn-polygon" style="fill:#FFFFFF;" points="44,29 22,44 22,29.273 22,14 "></polygon>
<path style="fill:#FFFFFF;" d="M22,45c-0.16,0-0.321-0.038-0.467-0.116C21.205,44.711,21,44.371,21,44V14
c0-0.371,0.205-0.711,0.533-0.884c0.328-0.174,0.724-0.15,1.031,0.058l22,15C44.836,28.36,45,28.669,45,29s-0.164,0.64-0.437,0.826
l-22,15C22.394,44.941,22.197,45,22,45z M23,15.893v26.215L42.225,29L23,15.893z"></path>
</g>
</svg>
</div>
<div class="controls-inline" id="progressbar-wrapper" style="margin-right: 0px;">
<svg id="progressbar" width="675" height="50" preserveAspectRatio="none">
<g>
<path d="M25,1 a23,23 0 1,0 0,48 l625,0 a23,23 0 0,0 0,-48 z" stroke="#EBBA16" stroke-width="2px" fill="white">
</path>
</g>
</svg>
</div>
<div class="controls-inline controls-btn">
<svg version="1.1" id="volumn-btn" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="50px" height="50px" viewBox="0 0 58 58" style="enable-background:new 0 0 58 58;" xml:space="preserve">
<circle style="fill:#EBBA16;" cx="29" cy="29" r="29"></circle>
<path style="fill:white;" d="M16.427,20H8.104C6.942,20,6,20.942,6,22.104v12.793C6,36.058,6.942,37,8.104,37h8.323
c0.375,0,0.743,0.1,1.067,0.29L30.83,49.706C32.232,50.531,34,49.52,34,47.893V9.107c0-1.627-1.768-2.638-3.17-1.813L17.494,19.71
C17.17,19.9,16.802,20,16.427,20z"></path>
<path style="fill:white;" d="M41.541,42.042c-0.256,0-0.512-0.098-0.707-0.293c-0.391-0.391-0.391-1.023,0-1.414
c6.238-6.238,6.238-16.39,0-22.628c-0.391-0.391-0.391-1.023,0-1.414s1.023-0.391,1.414,0c7.018,7.019,7.018,18.438,0,25.456
C42.052,41.944,41.796,42.042,41.541,42.042z"></path>
<path style="fill:white;" d="M38,38c-0.256,0-0.512-0.098-0.707-0.293c-0.391-0.391-0.391-1.023,0-1.414
c4.297-4.297,4.297-11.289,0-15.586c-0.391-0.391-0.391-1.023,0-1.414s1.023-0.391,1.414,0c5.077,5.077,5.077,13.337,0,18.414
C38.512,37.902,38.256,38,38,38z"></path>
</svg>
</div>
</div>
Elements have by default some spacing inbetween them.
You can fix this when trying to make layouts through display: inline-block in at least a few different ways:
font-size: 0 on the parent .ctrl-panel in your case.
Negative margin-left on every inline block element (f.e. margin-left: -.25rem; seems to work on your layout on that third element)
Remove empty spaces on the html markup (this is why your first two elements are together and the third one is not, if your markup is like </div><div> there won't be any spacing).
Use an alternative method for layouts like float which will not take into account these in-between element spacings.
Remove the white space in the code between your divs. Inline elements are sensitive to that spacing.
</div><div
codepen example