If it works in the codepen and not on your page, there must be some difference between the two. Without seeing the non-working version, we canât possibly know where the problem lies.
Did you just copy the CSS from the codepen without noticing itâs SCSS? If you use the CSS from the âDirect code linkâ (under the âChange Viewâ menu) it should work OK.
I am only interested in the triangle, and not the circle, so I have eliminated some of the code and have tried to line up the triangle with some text, inline, without success (tried many things). see attached image. Here is the code currently:
as you can see from the attached image the triangle appears above the TEXT.
Any help with lining up the triangle with the text horizontally (side-by-side) will be appreciated.
If you build and post a âworking pageâ, we can tell how you have tested your code. I still recommend drawing outlines around boxes to see how they fit within the layout. Separate CSS (not inline CSS) is easier to follow. It is your obligation to center the svg within its viewbox.
Sorry for my delay. Sometimes Iâm not the most observant turnip in the patch.
This is where an understanding of the very basics of HTML and CSS would be remarkably helpful - read: essential. Yes, you tried to apply my code elsewhere, BUT you changed the HTML so the CSS no longer targets the HTML where it is needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="css/stylesheet.css">
<title>vertically center text and svg</title>
<style>
html {
box-sizing:border-box;
}
*,*::before,*::after {
box-sizing:inherit;
}
.parent-container { /* ADDED. Previously classed "text-center". Needed to center align inline and inline-block child elements. The effect is the same as assigning "text-align:center" to a paragraph to center align the words/sentences in the paragraph. */
text-align:center;
outline:1px dashed blue;
}
svg {
vertical-align:middle;
outline:1px dotted purple; /* Outline for TESTING purposes */
}
.triangle {
/* JS comment marks must not be used within CSS. They invalidate at least the next line of the CSS, perhaps more.
//stroke: #000;
*/
stroke: #f96262;
stroke-dasharray: 240;
stroke-dashoffset: 480;
transform: translateY( 0 );
transition: all 0.7s ease-in-out;
}
.playBut {
display:inline-block;
/* transition: all 0.5s ease; */
text-decoration:none; /* removes default anchor underline */
outline:1px dashed red; /* Outline for TESTING purposes */
}
.playBut:hover .triangle,
.playBut:active .triangle {
stroke: #865050;
stroke-dashoffset: 0;
opacity: 1;
animation: nudge 0.7s;
}
.one {
display:inline-block;
vertical-align:middle;
color:#6d6d6d;
font-size:1.5em; /* added, optional */
font-weight:400;
font-family:"open sans","sans-serif"; /* "open sans" is not a "universal" font family. A URL to this font family is needed or a fall-back should be included such as "sans-serif" */
opacity:0.5;
outline:1px dotted green; /* Outline for TESTING purposes */
}
@keyframes nudge {
0% {
transform: translateX( 0 )
}
30% {
transform: translateX( -5px )
}
50% {
transform: translateX( 5px )
}
70% {
transform: translateX( -2px )
}
100% {
transform: translateX( 0 )
}
}
</style>
</head>
<body>
<div class="parent-container"> <!-- Parent container ADDED to your code so inline and inline-block children can be centered. -->
<a href="#" class="playBut">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="45" height="45" viewBox="0 0 210 210">
<polygon class="triangle" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="73.5,62.5 148.5,105.8 73.5,149.1"/>
</svg>
<span class="one">TEXT</span> <!-- span WAS outside of the anchor in previous example. You have moved it inside the anchor. Necessitates several CSS changes. -->
</a>
</div>
</body>
</html>
Applying âtext-align:centerâ to a parent container is not the only way to center inline and inline-block elements, but it is the most fundametal and probably the easiest.
Iâm unclear what youâre trying to achieve, but that is already a link. Surely you just need to replace the # with the correct URL?
How would you expect that to work? You are nesting one link with destination inside another. How can a button link to two different resources at the same time?
I suggest you get into the habit of using the W3C Validator regularly, to pick up such errors.
<a class="playBut" href="#"> is already an anchor. In the last code example that I wrote, the svg and the text are both between the open and close anchor tags so they will both be clickable. What is the problem?
Since you did not respond specifically about that last code example (good or bad - hit or miss- works or doesnât and how), I donât mind hounding you for an explanation of your rather odd question.