SVG Doesn't show up in button element - html

I'm using inline SVG ( as JSX ) on my website, I'm trying to display a hamburger menu button but it isn't showing up. Here is my code:
import Link from "next/link"
function Nav() {
return (
<nav>
<button > /// SVG is here
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-172 -12 210 50" stroke="#000000">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16m-7 6h7" />
</svg>
</button>
<ul className="">
<li>
<Link href="/">
<a>Main</a>
</Link>
</li>
<li>
<Link href="/resume">
<a>Resume</a>
</Link>
</li>
<li>
<Link href="/projects">
<a>Projects</a>
</Link>
</li>
<li>
<Link href="/blog">
<a>Blog</a>
</Link>
</li>
<li>
<Link href="/contact">
<a>Get in touch</a>
</Link>
</li>
</ul>
</nav>
);
}
export default Nav;
The Icon is only visible when it's outside the button tag, how do I view it while preserving the viewBox attribute?

In your case you need to adjust the viewBox for your svg element, that way when you set your svg's height and width, your svg scales properly and you get the desired result. Here's your code which I tweaked:
<button>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="2 1 20 20" stroke="#000000" height="50px" width="50px">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16m-7 6h7" />
</svg>
</button>
See it work on codepen here.
You can learn about how viewBox works at CSS tricks and MDN.

Related

I seem to be having an issue with navigation bar turning in-to random colors that I've not set

Alright, so my navigation bar used to be looking like this a few days ago:
But once I try to center the navigation bar to the middle, it turns in-to random colors and the spaces between the interactable buttons disappeared as shown in this picture:
I just tried to debug it and apparently it only happens when I put the display to inline-block. Am I doing anything wrong?
My CSS for the navigation bar:
.topnav {
background-color: #ffffff;
overflow: hidden;
}
.topnav a {
float: center;
color: #000000;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
My HTML for the navigation bar:
<div class="topnav">
<i class="fab fa-facebook-square" style="font-size: 30px"></i>
<i class="fa-solid fa-book" style="font-size: 30px"></i>
<i class="fa-solid fa-pen-to-square" style="font-size: 30px"></i>
<i class="fa-solid fa-user-graduate" style="font-size: 30px"></i>
<i class="fa-solid fa-house-chimney" style="font-size: 30px"></i>
</div>
I removed the links for security reasons.
this happens because the <svg> if nested inside <a> will behave like a link...
you know that a link with a text inside is always blue and with an underline
just color the SVG to the color you want, to solve the bug
I created a demo in a jfiddle, so you can try and learn :)
I hope it will help you, and learned something new
body svg {
width: 5em;
}
/* color the svg, for not having this bug */
.with-success svg {
color: black;
}
<div class="with-error">
<h2>with error</h2>
<!-- 1 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
<!-- 2 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
</div>
<hr>
<div class="with-success">
<h2>success</h2>
<!-- 1 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
<!-- 2 link -->
<a href="#">
<!-- stackoverflow SVG -->
<svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="stack-overflow" class="svg-inline--fa fa-stack-overflow" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M290.7 311L95 269.7 86.8 309l195.7 41zm51-87L188.2 95.7l-25.5 30.8 153.5 128.3zm-31.2 39.7L129.2 179l-16.7 36.5L293.7 300zM262 32l-32 24 119.3 160.3 32-24zm20.5 328h-200v39.7h200zm39.7 80H42.7V320h-40v160h359.5V320h-40z"></path></svg>
</a>
</div>

SVG image within an object tag overlys website content

I am using a SVG image within an object tag on a web page. I cannot use the img-tag, because I need to interact with CSS classes within the SVG and have a navigation option which is used on clicks within the SVG.
I used to have the SVG inline, but now I wanted to rework the page to be adaptive/responsive and thus I’m trying to use the object-tag to make it scalable. It works fine with Chrome, Firefox and Opera. When it comes down to IE I ran into problems.
Other than the other browsers IE overlays everything with a white background. This includes the navigation div I use to show when the user clicks on certain elements. I simplified everything to show the effect:
This is how it should be
What IE makes of it
I tried to fiddle with Z-index on the object, wrapping the object in a different div and applying z-index on it. I also tried CSS on the SVG and the object tag, trying to set the background to transparent, none and similar things. All to no avail. The background stays white and the content hidden.
Then I found this:
http://solidlystated.com/scripting/place-div-over-iframe-in-internet-explorer/
Which leads to IE showing the content, but makes the element inactive, since the iframe prevents the links within to be clicked:
The simplified HTML so far:
<body>
<div class="wrapper">
<h1>System</h1>
<div class="contentItem">
<div class="aroundSVG" style="height: 530px">
<object type="image/svg+xml" data="/img/sys2.svg" id="svgObject" style="width: 100%; height: 100%; background: transparent;"></object>
</div>
<div id="showNav">
<ul>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/index.htm';
return false;">Line 1</a></li>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/event.htm';
return false;">Line 2</a></li>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/error.htm';
return false;">Line 3</a></li>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/index.htm?reset=true';
return false;">Line 4</a></li>
</ul>
<!-- <iframe id="fake" src="about:blank" style="width: 100%; height: 100%; position: absolute; top: 1px; left: 1px; border: none;"></iframe> -->
</div>
</div>
</body>
The SVG file:
<head>
<meta http-equiv="content-type" content="image/svg+xml"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</meta>
<link rel="stylesheet" type="text/css" href="/css/svgStyle.css" media="all" />
<script type="text/javascript" src="/js/jquery_min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
parent.svgObj = document
parent.svgModules = $(parent.svgObj).find(".modules");
parent.setModClick();
$(parent.svgObj).click(function (e)
{
var container = parent.navContainer;
var optDiv = $(".classB");
if (!container.is(e.target)
&& container.has(e.target).length === 0
&& !optDiv.is(e.target)
&& optDiv.has(e.target).length === 0)
{
container.hide(250);
}
});
})
</script>
</head>
<svg viewBox="0 0 923 500">
<g class=„classA classB“ id="gvg" transform="translate(300,250)">
<circle class=„circle“ cx="150" cy="0" r="40" stroke="black" stroke-width="3" fill="red" />
</g>
<g class=„classA classB“ id="dr" transform="translate(300,300)">
<circle class=„circle“ cx="150" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</g>
<g class=„classA classB“ id="hur" transform="translate(300,350)">
<circle class=„circle“ cx="150" cy="100" r="40" stroke="black" stroke-width="3" fill="red" />
</g>
</svg>
Is there any way to keep the toggled menu active and shown within IE/Edge (I guess there will be problems, too), or am I using the object-tag/SVG file the wrong way?
There seems no way to resolve this with CSS within IE, while the other browser keep the SVG background transparant.
After some experimenting and researching I found a solution. I needed to make the <ul> element absolute in positioning and remove it from the fake <iframe>. Now the navigation is visible and clickable. I needed to add some CSS and fiddle with height and width in javascript/jQuery due to variable heights, but that's irrelevant.
So it worked for me like this:
<div id="showNav">
<ul style='position: absolute'>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/index.htm';
return false;">Line 1</a></li>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/event.htm';
return false;">Line 2</a></li>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/error.htm';
return false;">Line 3</a></li>
<li><a href=„LinkTarget“ onclick="location.href = this.href + fncTarget + '/index.htm?reset=true';
return false;">Line 4</a></li>
</ul>
<iframe id="fake" src="about:blank" style="width: 102%; height: 103%; border: none;"></iframe>
</div>
You may need to vary height, width and border of the iFrame to match your case, since you need to adjust this to make all formatting of the parent <div> visible.
I hope this will help someone who stumbles over the same issues.

Sidebar is in the wrong place when desktop, but not when mobile

I have a problem with the website I'm currently making for my art
theyoungillustrations.com
I have absolutely no experience in coding, so please explain like I'm five
I'm altering a excisting code, but I experience a problem with the sidebar. Because I made a banner (at the top), the sidebar is currently under it and I can't find out how I can fix that without ruining the mobile-sidebar.
This here seems to be the target, but the style-ing part is the one I'm unsure of.
<div id="sidebar" class="{select:Header Text Case} ">
<div class="inner animated slow">
<div class="wrap">
<nav class="sidebar-navigation cl">
<ul>
{block:IfHomeLink}
<li>Home</li>
{/block:IfHomeLink}
{block:HasPages}
{block:Pages}
<li> {Label}</li>
{/block:Pages}
{/block:HasPages}
</ul>
</nav>
</div>
</div>
</div>
<div id="header" class="{select:Header Text Case} ">
<div class="wrap">
<div class="inner">
<div class="logo">
{block:ifnotlogoimage}
{Title}
{/block:ifnotlogoimage}
{block:iflogoimage}
<img src="{image:Logo}" alt="logo" />
{/block:iflogoimage}
</div>
<nav class="navigation cl">
<ul>
{block:HasPages}
{block:Pages}
<li> {Label}</li>
{/block:Pages}
{/block:HasPages}
</ul>
</nav>
</div>
</div>
<div class="sidebar-toggle">
Menu
</div>
<div class="close-mobile-modal">
<svg width="16px" height="20px" viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M7.172,10 L3.642,6.47 L0.102,2.93 L2.928,0.1 L10,7.173 L17.07,0.103 L19.9,2.93 L12.827,10 L19.897,17.07 L17.07,19.9 L10,12.827 L2.93,19.897 L0.1,17.07 L7.173,10 L7.172,10 Z"></path>
</g>
</svg>
</div>
</div>
</div>
</div>
Then I have this:
}
#sidebar h3 {
margin-bottom:20px;
color:{color:Header Text};
font-size:13px;
}
#sidebar-navigation {
color:{color:Header Text};
background:{color:Header Background};
font-size:{text:Header Size};
}
But I'm clueless. Thanks for helping.
This is because you need to add a breakpoint for various devices ,you can take help of this url :https://www.w3schools.com/css/css_rwd_mediaqueries.asp

SVG <text> element inside <a> element no underline in IE

Please check this plunker:
https://plnkr.co/edit/jqPx9qpN3W1Jrix2axPw?p=preview
<div width="100px">
<svg width="100px" viewBox="0 0 100 100">
<a xlink:href="#" class="node">
<text transform="translate(50 50)">hh2</text>
</a>
</svg>
</div>
a:hover {
text-decoration: underline;
}
On chrome you will see an underline on hover, but on IE there is no underline. I tried solving with css without success.
In SVG text-underline behaves a little differently than in HTML.
In SVG, the specification states that it shouldn't inherit.
It appears Chrome and FF have relaxed that restriction.
To get around this in IE, just alter the CSS rule to include the text element.
a:focus text, a:hover text {
color: #23527c;
text-decoration: underline;
}
<h1>Hello Plunker!</h1>
<div width="100px">
<svg width="100px" viewBox="0 0 100 100">
<a xlink:href="#" class="node">
<text transform="translate(50 50)">hh2</text>
</a>
</svg>
</div>

HTML/SVG: Download on click

Currently I'm using SVG for some animation and I want that when someone clicks on an image with SVG around it that it will start a download for that image.
<div class="box">
<svg width="100%" height="100%">
....
</svg>
<img src="chief.png" alt="Chief"/>
</div>
How do I change it so it starts a download on click?
Test this
<a href="http://www.w3.org/Graphics/SVG/">
<svg class="Orange" ... >
<use xlink:href="buttonB.svg#Root"/>
</svg>
</a>
and check this page > http://tavmjong.free.fr/SVG/BUTTON_TEST/button_test.html
When the SVG is wrapped with the anchor, a click event on the SVG will be sent up to the anchor. In this case that will trigger the download.
<div class="box">
<a href="chief.png" download="chief.png">
<svg width="100%" height="100%">
....
</svg>
</a>
</div>