- This topic has 13 replies, 2 voices, and was last updated 1 year, 11 months ago by Ying.
-
AuthorPosts
-
May 18, 2022 at 3:30 pm #2224528Halil
Hi,
I’ve created a secondary menu and used SVG images in that menu, showing that menu in the upper right corner.I’m trying to add little animation and changing the fill color of that SVGs but I couldnt do it.
For example, to change the fill color, I’ve used this code
.menu-item ._svg:hover { fill: #111; background-color:red; }
I’ve added background color just to check I’m referencing the correct element. Background color works, fill color does not work!
I also want to add little animation with a nice transition to that SVG icon, such as making it a little bit bigger when I hover over it.
Could you pls help with the css
May 18, 2022 at 3:49 pm #2224558YingStaffCustomer SupportHi Halil,
The svg will inherits the hover color set to the menu items, you can set that color in customizer > colors.
So the CSS is not needed.But if you only want the hover color for the svg, not other menu items, you can try this CSS:
/*add hover color to svg*/ .main-navigation .main-nav ul li.menu-item-14197:hover a { color: red; } /*add hover effect to enlarge svg*/ .main-navigation .main-nav ul li.menu-item-14197:hover a svg { transform: scale(1.5); } /*add transition to svg*/ .main-navigation .main-nav ul li.menu-item-14197 a svg { transition: all 0.2s ease; }
May 18, 2022 at 4:00 pm #2224576Halilthanks for the quick response Ying but neither hover settings in color customizer, nor this css works.
Colom customizer changes the hover color links, not the SVGs.
May 18, 2022 at 4:09 pm #2224582YingStaffCustomer SupportI’m not seeing the CSS on your site, it should work:
https://www.screencast.com/t/uu2RIqFoaknJCan you make sure cache is cleared?
May 18, 2022 at 4:17 pm #2224586HalilI mean the links / SVGs on the upper right sections Ying, not the home icon, sorry for misleading you
here is the link to SVGs https://ibb.co/bHxx5zKMay 18, 2022 at 4:31 pm #2224606YingStaffCustomer SupportAh sorry for the misunderstanding.
The icons in the secondary navigation are added using different method?
CSS won’t work as they are inserted as static image.
Can you insert them using the same method that the home icon is using?
May 18, 2022 at 4:58 pm #2224627Halilyes, via plugin! I see the problem now! I have changed the URL, pls check the link in the private area.
Could you pls help me again make this SVGs, aligned well with the link (padding etc), vertically middle, on hover a little bit bigger look with nice animation?
I’ve a lot to learn about these things, so frustrating for a novice user like me !
May 18, 2022 at 5:07 pm #2224634YingStaffCustomer SupportTry this CSS :
.secondary-navigation .main-nav ul li a svg { transition: all 0.2s ease; margin-right: 10px; } .secondary-navigation .main-nav ul li:hover a svg { transform: scale(1.5); } .secondary-navigation .main-nav ul li a { line-height: 1em; display: flex; }
May 18, 2022 at 5:19 pm #2224644Halilalmost perfect,
I’ve added these.secondary-navigation .main-nav ul li a svg { transition: all 0.2s ease; margin-right: 5px; vertical-align: middle; }
but the vertical align is not perfect! may be it’s because the initial size of the SVGs are a bit small, how do I increase the inital size of SVGs?
May 18, 2022 at 5:28 pm #2224649YingStaffCustomer SupportHave you added the 3rd CSS in my reply?
https://generatepress.com/forums/topic/change-fill-color-of-svg-icon-in-secondary-menu/#post-2224634May 18, 2022 at 5:39 pm #2224659Halilyes, I’ve added now, can we make the initial size of SVGs just a little bit larger?
I tried font size settigns, but it changes only the font size of the text links.
May 18, 2022 at 8:43 pm #2224788YingStaffCustomer SupportIt’s because your SVG is using fixed height and width instead of viewBox.
You can use a tool like this to convert the SVG to use viewBox, toggle the
Prefer viewBox to width/height
option. https://jakearchibald.github.io/svgomg/Then you should be able to use:
.secondary-navigation .main-nav ul li a svg { height: 25px; width: 25px; }
Or
You can directedly edit the SVG code, change its width and height.
May 19, 2022 at 4:34 am #2225253Halilhuge thanks Ying
May 19, 2022 at 9:17 am #2225759YingStaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.