I try to use hover for button element and for SVG within button. But in here piece of code https://codepen.io/asssel/pen/wvrojOd It doesn't work for SVG. Help me how to implement it.
.tag {
width: 120px;
padding: 6px 12px;
border: 1px solid #1F1F1F;
border-radius: 18px;
cursor: pointer;
color: #1F1F1F;
background-color: white;
&_label {
font-size: 12px;
line-height: 12px;
letter-spacing: 1.2px;
text-transform: uppercase;
}
&_remove {
border: none;
background-color: transparent;
}
&:hover, &_icon path {
background-color: #1F1F1F;
color: white;
stroke: white;
}
}
<div class='tag'>
<span class='tag_label'>default tag</span>
<button class='tag_remove'>
<svg class='tag_icon' width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.5 1.5L1.5 8.5M8.5 8.5L1.5 1.5" stroke="#404040" stroke-width="2" stroke-linecap="square"/>
</svg>
</button>
</div>
First of all I changed your CSS to plain CSS to make it work in the snippet.
I guess that the main problem is the hover effect. To change the stroke of the <path> your CSS selector need to start from the element that is hovered. So, replace &_icon path with &:hover &_icon path.
And then you also make sure that you use fill and stroke properties for SVG elements.
.tag {
width: 120px;
padding: 6px 12px;
border: 1px solid #1F1F1F;
border-radius: 18px;
cursor: pointer;
color: #1F1F1F;
background-color: white;
display: flex;
align-items: center;
}
.tag_label {
font-size: 12px;
letter-spacing: 1.2px;
text-transform: uppercase;
white-space: nowrap;
}
.tag_icon path {
stroke: #1F1F1F;
}
.tag_remove {
border: none;
background-color: transparent;
}
.tag:hover,
.tag:hover .tag_icon path {
background-color: #1F1F1F;
color: white;
stroke: white;
}
<div class='tag'>
<span class='tag_label'>default tag</span>
<button class='tag_remove'>
<svg class='tag_icon' width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.5 1.5L1.5 8.5M8.5 8.5L1.5 1.5" stroke-width="2" stroke-linecap="square"/>
</svg>
</button>
</div>
Related
I have a react project which used an svg filter for rendering:
#use 'sass:math';
#import '../Theme.scss';
$borderW: 5px;
$borderR: 5px;
$numOfBlobs: 4;
.blob-btn {
z-index: 1;
position: relative;
padding: 20px 46px;
margin-bottom: 30px;
text-align: center;
text-transform: uppercase;
font-size: 16px;
font-weight: bold;
background-color: transparent;
outline: none;
border: none;
transition: color 0.5s;
cursor: pointer;
border-radius: $borderR;
color: $primary;
&:before {
content: '';
z-index: 1;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border: $borderW solid $primary;
border-radius: $borderR;
}
&:after {
content: '';
z-index: -2;
position: absolute;
left: $borderW * 1.5;
top: $borderW * 1.5;
width: 100%;
height: 100%;
transition: all 0.3s 0.2s;
border-radius: $borderR;
}
&:hover {
color: #ffffff;
border-radius: $borderR;
&:after {
transition: all 0.3s;
left: 0;
top: 0;
border-radius: $borderR;
}
}
&__inner {
z-index: -1;
overflow: hidden;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border-radius: $borderR;
background: #ffffff;
}
// additional container created, because in FF blobs are breaking overflow:hidden of element with svg gooey filter
&__blobs {
position: relative;
display: block;
height: 100%;
filter: url('#goo');
}
&__blob {
position: absolute;
top: $borderW;
width: math.div(100%, $numOfBlobs);
height: 100%;
background: $primary;
border-radius: 100%;
transform: translate3d(0, 150%, 0) scale(1.7);
transition: transform 0.45s;
#supports (filter: url('#goo')) {
transform: translate3d(0, 150%, 0) scale(1.4);
}
#for $i from 1 through $numOfBlobs {
&:nth-child(#{$i}) {
left: ($i - 1) * math.div(120%, $numOfBlobs);
transition-delay: ($i - 1) * 0.08s;
}
}
.blob-btn:hover & {
transform: translateZ(0) scale(1.7);
#supports (filter: url('#goo')) {
transform: translateZ(0) scale(1.4);
}
}
}
}
.blob-btn-secondary {
#extend .blob-btn;
color: $secondary;
&:before {
border: $borderW solid $secondary;
}
}
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.1"
style={{ display: 'none' }}
>
<defs>
<filter id="goo">
<feGaussianBlur
in="SourceGraphic"
result="blur"
stdDeviation="10"
></feGaussianBlur>
<feColorMatrix
in="blur"
mode="matrix"
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 21 -7"
result="goo"
></feColorMatrix>
<feBlend in2="goo" in="SourceGraphic" result="mix"></feBlend>
</filter>
</defs>
</svg>
<button
class='blob-btn'}
style={{
padding: '15px',
margin: '15px',
width: '100%',
zIndex: 10,
filter: isHovered ? 'blur(2px)' : 'none',
// color: color,
}}
>
Coming Soon
<span className="blob-btn__inner">
<span className="blob-btn__blobs" style={{ filter: `url(#goo)` }}>
<span
className="blob-btn__blob"
style={{ background: color }}
></span>
<span
className="blob-btn__blob"
style={{ background: color }}
></span>
<span
className="blob-btn__blob"
style={{ background: color }}
></span>
<span
className="blob-btn__blob"
style={{ background: color }}
></span>
</span>
</span>
</button>
It works well when running withing snopack, but as soon as I try to bundle it looses the connection to goo svg. Trying with webpack, as well as the native snowpack bundler I get:
[16:56:29] [snowpack] Build failed with 1 error:
build/dist/components/PositionAwareButton.css:10837:14: error: Could
not resolve "/dist/components/#goo"
Any pointers on where I need to start looking are highly appreciated
I am facing difficulty in stretching a SVG in the X-axis, so that there is no white space visible on either side. Also, I want the point (marked in red circle in the attached picture) to touch the starting of the second div with background color of black. I have tried changing the viewbox values, but I am not able to achieve the desired result.
The below is my code.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.5%
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.example {
width: 100%;
height: 100vh;
}
svg {
width: 100%;
height: 100%;
}
.section-two {
width: 100%;
height: 100vh;
background-color: black;
}
<div class="example">
<svg viewbox="0 0 3000 1750">
<path d="M2987.34,2.895l-2984.74,-0l0,1224.16l671.731,426.733l2313,-426.733l0,-1224.16Z" style="fill:#f8be46;"/>
</svg>
</div>
<div class="section-two">
</div>
enter image description here
For that to happen, you need to do two things:
Make sure that your viewBox is correct. It needs to match the dimensions of your <path>. It currently doesn't.
Add the following attribute to your SVG to turn off the automatic aspect-ratio-preserving scaling that SVG does.
preserveAspectRatio="none"
If we check the bounding box of your path, we get the values:
x: 2.600
y: 2.895
width: 2984.740
height: 1650.893
So that is what your viewBox needs to be set to, if you want the path to touch all four sides of the SVG's parent container.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.5%
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.example {
width: 100%;
height: 100vh;
}
svg {
width: 100%;
height: 100%;
}
.section-two {
width: 100%;
height: 100vh;
background-color: black;
}
<div class="example">
<svg viewbox="2.6 2.9 2984.7 1650.9" preserveAspectRatio="none">
<path d="M2987.34,2.895l-2984.74,-0l0,1224.16l671.731,426.733l2313,-426.733l0,-1224.16Z" style="fill:#f8be46;"/>
</svg>
</div>
<div class="section-two">
</div>
I'm using the vis.js library and most things work. Like when I manually style the elements with the "style" tag however when I use the class attribute the styles are not applied.
The SVG element
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="420px" height="165px">
<foreignObject x="0" y="0" width="100%" height="100%">
<div xmlns="http://www.w3.org/1999/xhtml" style="background-color: #fff;height: 100%, width: 100%; display: flex; padding: 8px; border-radius: 10px; box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.37); box-sizing: border-box;">
// This doesn't work
<div style="flex: 1;">
<h1 class="testyh1">Report Id</h1>
<h2 style="margin: 0; font-size: 14px; font-weight: 400; line-height: normal;">1</h2>
</div>
// This works
<div style="flex: 1;">
<h1 style="color: #0481E2; margin-top: 0; margin-bottom: 3px; font-size: 12px; line-height: normal;">Report Name</h1>
<h2 style="margin: 0; font-size: 14px; font-weight: 400; line-height: normal;">Medicine-Stock</h2>
</div>
</div>
</foreignObject>
</svg>`;
CSS
.testyh1 {
color: #0481E2;
margin-top: 0;
margin-bottom: 3px;
font-size: 12px;
line-height: normal;
}
I use style tag and update these in HTML page with script tag:
<style type="text/css">
#mynetwork {
margin: auto;
width: 1000px;
height: 800px;
border: 1px solid lightgray;
}
</style>
hi guys i need some help i need to create a tooltip with an image inside it however this is for an svg map so i cant use divs like in css and html.I have managed to create an image tooltip .However only one image can appear when i hover on all elements how can i make different images appear for different svg elements ? this is the code i have used for my tooltip:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" onload="init(evt)" width="380" height="100">
<style>
.caption{
font-size: 14px;
font-family: Georgia, serif;
}
.tooltip{
font-size: 12px;
}
.tooltip_bg{
fill: white;
stroke: black;
stroke-width: 1;
opacity: 0.85;
}
</style>
<script type="text/ecmascript">
<![CDATA[
function init(evt)
{
if ( window.svgDocument == null )
{
svgDocument = evt.target.ownerDocument;
}
tooltip = svgDocument.getElementById('tooltip');
tooltip_bg = svgDocument.getElementById('tooltip_bg');
}
function ShowTooltip(evt, mouseovertext)
{
tooltip.setAttributeNS(null,"x",evt.clientX+11);
tooltip.setAttributeNS(null,"y",evt.clientY+27);
tooltip.setAttributeNS(null,"visibility","visible");
length = tooltip.getComputedTextLength();
tooltip_bg.setAttributeNS(null,"width",length+8);
tooltip_bg.setAttributeNS(null,"x",evt.clientX+8);
tooltip_bg.setAttributeNS(null,"y",evt.clientY+14);
tooltip_bg.setAttributeNS(null,"visibility","visibile");
}
function HideTooltip(evt)
{
tooltip.setAttributeNS(null,"visibility","hidden");
tooltip_bg.setAttributeNS(null,"visibility","hidden");
}
]]>
</script>
<text class="caption" x="10" y="35">Mouseover a square</text>
<text class="caption" x="10" y="50">to display a tooltip</text>
<rect id="rect1" x="160" y="10" width="60" height="60" fill="blue"
onmousemove="ShowTooltip(evt)"
onmouseout="HideTooltip(evt)"/>
<rect id="rect2" x="240" y="10" width="60" height="60" fill="green"
onmousemove="ShowTooltip(evt)"
onmouseout="HideTooltip(evt)"/>
<rect class="tooltip_bg" id="tooltip_bg"
x="0" y="0" rx="4" ry="4"
width="55" height="17" visibility="hidden"/>
<image xlink:href="Blooper-icon.png" class="tooltip" id="tooltip"x="0" y="0"height="50px"width="50px"visibility="hidden"/>
</svg>
in HTML
<div class="svgTooltip"></div>
<svg>
<path class="tempClass" .......>
</path>
</svg>
in CSS
.svgTooltip {
pointer-events: none;
position: absolute;
font-size: 15px;
text-align: center;
background: white;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
z-index: 5;
height: 30px;
line-height: 30px;
margin: 0 auto;
color: #21669e;
border-radius: 5px;
box-shadow: 0 0 0 1px rgb(122, 92, 92);
display: none;
}
.svgTooltip::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 0;
height: 0;
margin-left: -10px;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid rgb(122, 92, 92);
}
.active {
display: block;
}
in JS
$(function() {
$tooltip = $(".svgTooltip");
$(".tempClass").hover(
function() {
$tooltip.addClass("active");
$tooltip.html($(this).attr("title"));
},
function() {
$tooltip.removeClass("active");
}
);
});
$(document).on("mousemove", function(e) {
$tooltip.css({
left: e.pageX - 30,
top: e.pageY - 70
});
});
In Chrome, the website bmr1.com shows the search widget with a magnifying glass as the submit buttons background image. In order to get the submit button to move I added Float:Right and Margin-top, to get it into the correct position. I also had to add position:relative, so that the button would be positioned on top of the text box. Issue is the same margin-top: of 31px that fixes Chrome, makes IE9's submit button way too high and out of place.
bmr1.com
<div id="search-2" class="widget widget_search"><h4 class="widgettitle"><cufon class="cufon cufon-canvas" alt="Search" style="width: 64px; height: 22px; "><canvas width="80" height="28" style="width: 80px; height: 28px; top: -4px; left: -1px; "></canvas><cufontext>Search</cufontext></cufon></h4><form role="search" method="get" id="searchform" action="http://bmr1.com/">
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" placeholder="" widdit="on" autocomplete="off">
<input type="submit" id="searchsubmit" value="">
</form><div id="predictad_div" class="predictad"></div></div>
#sidebar1 { position: relative; }
#search-2.widget.widget_search {z-index:0; background-color: #363636; margin-right:15px; margin-bottom:25px; padding: 10px 10px 10px 10px; color:#363636; max-width:231px;}
#search-2.widget.widget_search #s{width:94%; padding: 5px;position:relative;}
#search-2.widget.widget_search h4 {font-size:140%; background-color: #84c4e7; padding: 5px 10px 5px 10px; border: 1px solid #fff; margin-bottom:10px;}
.widget_search .screen-reader-text {margin-bottom:-20px;float:right;}
#mp_cart_widget-3.widget.mp_cart_widget { background-color: #cdcdcd; margin-right:15px; margin-bottom:25px; padding: 10px 10px 10px 10px; max-width:231px;}
#mp_cart_widget-3.widget.mp_cart_widget h4 { font-size:140%; background-image:url('http://technickconsulting.com/testblog/wp-content/themes/BoatMotorRecyclers/images/greysliver.png'); background-repeat: repeat-x; padding: 5px 10px 6px 10px; margin-bottom:10px; color:#fff; }
#mp_categories_widget-3.widget.mp_categories_widget { background-color: #363636; margin-right:15px; margin-bottom:20px; padding: 10px 10px 10px 10px; color:#fff; max-width:231px;}
#mp_categories_widget-3.widget.mp_categories_widget h4 { font-size:140%; background-color: #84c4e7; padding: 5px 0px 5px 10px; border: 1px solid #fff; margin-bottom:10px; color:#363636;}
#mp_categories_widget-3.widget.mp_categories_widget a {text-decoration:none; color:#fff; margin-left: 30px; }
#sidebar ul {font-size:18px; font-weight:bold; }
ul#mp_category_list {padding-right:10px;font-size:18px; }
ul#mp_category_list .children {text-align:left;list-style: none;margin-left:10px; font-size:15px !important;}
.widget_search #searchsubmit {
background-image:url('http://technickconsulting.com/testblog/wp-content/themes/BoatMotorRecyclers/images/magglass.png');
background-color:transparent;
border:none;
background-repeat:no-repeat;
color:transparent;
height: 28px;
width:30px;
cursor: pointer;
float:right;
padding: 8px 16px;
margin-top:-31px;
position:relative;
}
Try this:
.widget_search #searchsubmit {
background-image: url('http://technickconsulting.com/testblog/wp-content/themes/BoatMotorRecyclers/images/magglass.png');
background-color: transparent;
border: none;
background-repeat: no-repeat;
height: 28px;
width: 30px;
cursor: pointer;
position: absolute;
z-index: 10;
top: 3px;
right: 0;
}
#search-2 form {position: relative;}
Also, I highly recommend to use a css reset! This will make every slight difference in lay-out between browsers go away. You will need to overwrite some of these values, but it saves you a lot of frustration in the long run!
An example: http://meyerweb.com/eric/tools/css/reset/
I agree with the previous commenter, use a reset.css! Different browsers has different default margin, padding etc values for everything and it makes your webpage look different in each of them.
To fix the problem you should do the followings.
First, give a fixed height for your text input field:
#search-2.widget.widget_search #s{width:94%;height:20px; padding: 5px;position:relative;}
Change is that I have applied a 20 pixel height for the element
Then apply the following to the submit button:
.widget_search #searchsubmit {
background-image:url('http://technickconsulting.com/testblog/wp-content/themes/BoatMotorRecyclers/images/magglass.png');
background-color:transparent;
border:none;
background-repeat:no-repeat;
color:transparent;
height: 28px;
width:30px;
cursor: pointer;
float:right;
bottom:31px;
position:relative;
}
You should use shortcodes like background: url('http://technickconsulting.com/testblog/wp-content/themes/BoatMotorRecyclers/images/magglass.png') no-repeat; to make your code shorter and cleaner
I hope this will fix your issue.