Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Style svg?

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 26 total)
  • Author
    Posts
  • #43543
    wragen22
    Member

    Hi folks,
    I have seen several posts on how to style svg’s, but i’m not quite understanding for my situation.

    I have some svg images that is simply text. I am exploring avoiding web fonts because of rendering issues. I am trying to style these svg’s by dropping them into the html and styling in css, but this is not working. Can someone help me achieve this?

    Here is what i’m trying – In my HTML:

    svg

    CSS:

    .style {
    margin: 40px auto 40px;
    width: 200px;
    height: 100px;
    fill: #e05f5a;
    &:hover {
    @include transition(#4a4a4a .1s ease);
    fill: #4a4a4a;
    }

    #129086
    Paulie_D
    Member

    Is it the transition not working or the color change?

    The transition won’t work I would assume because (I think) it should be

    transition: (fill .1s ease);

    No?

    #129150
    Paulie_D
    Member

    It’s also odd that the containing div AND the svg have the same class…isn’t it?

    #129154
    wragen22
    Member

    Yes, it is the color change I am having issues with. And for the containing div and the svg, I have been struggling with this as well. For some reason If I were to only leave one class, say for the containing div and nothing for the svg, nothing shows up. However, when I placed the class in both section the svg does show up properly…. :-/

    #129166
    Paulie_D
    Member

    So if you try

    svg.style {
    fill: xxxxxxx;
    }

    ** note…no spaces **

    nothing happens to the fill?

    #129206
    wragen22
    Member

    so you recommend in my css file changing to svg.style { } ?

    #129207
    Paulie_D
    Member

    Dunno…does it work if you do?

    svg.style /* no space */

    will only select svg elements that have a class of style…the div element won’t be selected at all.

    svg .style /* with space */

    will select elements with a class of style **inside** svg elements…and that’s not what you want.

    #129211
    Paulie_D
    Member

    >** img.style, since it’s an img element after all..

    Oops…you are right!

    In that case…it won’t work at all….it’s just an image.

    You can only apply the fill to SVG elements.

    Doh!

    This…

    svg

    is not the same as

    #129230
    wragen22
    Member

    Interesting… so how might I be able to apply css properties to the svg? Hover ease ect?

    #129232
    Paulie_D
    Member

    You have to use the SVG element…not an image element.


    fill=”red” stroke=”blue” stroke-width=”5″ />

    http://codepen.io/Paulie-D/pen/nxrCK

    #129239
    wragen22
    Member

    So styling directly in the svg code? I can’t use external css?

    #129248
    Paulie_D
    Member

    I **think** if you give each element a class or an ID, you can do it with CSS &/or JS.

    #129251
    Paulie_D
    Member
    #129254
    Paulie_D
    Member

    Hover…sure.

    Codepen updated.

    #129461
    wragen22
    Member

    Still unable to get this to work…

    I’m currently importing the svg code as background data in css

    and for my code, I am using

    .logo {
    background: url(data:image/svg+xml;base64,[data]);
    }

    with the codefish code in place of the “[data]”

    With my actual svg data before mobilefish




Viewing 15 posts - 1 through 15 (of 26 total)
  • The forum ‘CSS’ is closed to new topics and replies.