How to keep Google from putting material-icons text in site links? - html

Many of my links have material icons in tags inside the link. Now, Google has indexed my page with site-links that include the text/ligature from that material-icons tag, so a link might say "shopping_cart Shop Now" for example.
Everything already displays correctly when browsing the site, but it's just in google's search results that the page titles look ridiculous.
<li>
<a href="/feed.php">
<i class="material-icons icon">shopping_cart</i>
<span>Shop Now</span>
</a>
</li>
I would not expect the text "shopping_cart" to appear when Google indexes these page titles for site-links. How can I tell Google to stop doing that?

You can't tell Google to stop indexing that. What you can do is remove what you don't want Google to index. For example, if you don't want it indexing the material icon text then remove the material-icons class and text from the HTML.
What you can do instead is add it via CSS with a pseudo class, here's a pen for example: https://codepen.io/MatthewRader/pen/VNZxdo
your HTML and CSS would look like this:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<li>
<a href="/feed.php">
<span>Shop Now</span>
</a>
</li>
li {
list-style:none;
}
a {
text-decoration: none;
color: PeachPuff;
padding: 10px;
background: SaddleBrown;
}
a::before {
font-family: 'Material Icons';
content: "shopping_cart";
-webkit-font-feature-settings: 'liga';
}

Related

How can I use HTML & CSS to create a link image hover?

I would like a line of text to show a pop up of an image when hovered. Preferably just by using html and/or css. I am using ecommerce templates shopping cart software. When I try coding this, my image is automatically already shown on my webpage. It shouldn't show until the text is hovered.
I have tried code that I have found by doing google searches. I am unsure if the template is the reason why the code isn't working correctly.
a img {
display: none;
}
a:hover img {
display: block;
}
<li>
<a href="#">Hover
<img src="https://via.placeholder.com/150"/>
</a>
</li>
I expect to be able to hover the text and have an image pop up until I am no longer hovering over the text.
you need to set the image inside the element you want to hover with display none, than set display block using this selector a:hover .onlyHover, thats mean: set display block on element inside an hovered url, you can change the a:hover with a specific class like .youClass:hover .onlyHover
Check the code snippet:
.onlyHover{
display:none;
}
a:hover .onlyHover{
display:block;
}
<a href="#">HOVER TO SEE
<div class="onlyHover">
<img src="https://placeimg.com/640/480/any">
</div>
</a>

Use inline SVG instead of font-awesome webfont in pure CSS

I am using a bulma-based template for a static site generator and I'm looking to remove any dependencies on Javascript and any resources hosted by third parties, as well as generally minimizing things.
The template utilizes font awesome for some of the icons involved, but it's really only around 5-10 icons total, so I was planning to inline them as SVGs rather than load an entire web font. However, I'm not sure how to get as close as possible to a drop-in replacement for these few icons through pure CSS.
Here is a minimal working example of the HTML:
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
<ul style="list-style: none">
<li>
<a href="https://example.com">
<span style="align-items:center; justify-content:center"><i class="fa fa-globe fa-fw"></i></span>
<span>Example</span>
</a>
</li>
<li style="font-size: 20px">
<a href="https://example.com">
<span style="align-items:center; justify-content:center"><i class="fa fa-globe fa-fw"></i></span>
<span class="link-text">Example</span>
</a>
</li>
<li style="font-size: 40px">
<a href="https://example.com">
<span style="align-items:center; justify-content:center"><i class="fa fa-globe fa-fw"></i></span>
<span class="link-text">Example</span>
</a>
</li>
</ul>
If I use this with the fontawesome CSS (see this JSfiddle) by prepending this:
<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
I get an icon that scales with the font size, has the same color as the font size and is centered vertically with respect to the text. If, however, I use an inline SVG (see this JSFiddle), with this CSS:
.fa-globe::before {
content: '';
display: inline-block;
height: 1em;
width: 1em;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48cGF0aCBkPSJNMzY0LjIxNSAxOTJoMTMxLjQzYzUuNDM5IDIwLjQxOSA4LjM1NCA0MS44NjggOC4zNTQgNjRzLTIuOTE1IDQzLjU4MS04LjM1NCA2NGgtMTMxLjQzYzUuMTU0LTQzLjA0OSA0LjkzOS04Ni43NDYgMC0xMjh6TTE4NS4yMTQgMzUyYzEwLjY3OCA1My42OCAzMy4xNzMgMTEyLjUxNCA3MC4xMjUgMTUxLjk5Mi4yMjEuMDAxLjQ0LjAwOC42NjEuMDA4cy40NC0uMDA4LjY2MS0uMDA4YzM3L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cuMzA1IDU5LjE5OCA4NC4wMjQgMjcuMjcxIDE2MGgxMjUuMzg1eiIvPjwvc3ZnPg==");
}
The icon is not centered vertically with respect to the text, and it is not the same color as the text. What is the best way to treat inline SVGs as replacements for font awesome glyphs without javascript? (I'm less concerned with the "icons are the wrong color" than the fact that they don't seem to be aligned well with the text, I just mention it because if there is an approach that solves both problems, I'd prefer that).
Perhaps this resource could be useful for you. IcoMoon has a decent selection of free icons, including the social networks, and if you click 'generate svg' you can then select 'get code' and copy/paste the html and css straight into your site.
To change icon color and layout you can simply change the css you just grabbed.
Something like:
`
.icon {
display: flex;
align-items: center;
color: #whatever-text-color;
}
`
Here is a JS-free example that you can play with. If you are using a sass variable for controlling font-size, you could also hook the image up to that to keep everything scaling together.
The only catch with using SVG over using font-awesome is a lack of svg support on old/ancient IE browsers. Everything else is a solid win - less http requests, less file size, less dependencies.
Hope this helps :)
EDIT
extra tip. For animations with inline svg, put a class or id onto the PATH tag and animate that. For rotations you might also need: transform-origin: center; since it defaults to rotating around the top-right.
If you have an svg with multiple paths, you can animate them individually and start getting really funky.
In your fiddle https://jsfiddle.net/ks392fzv/6/, if you set content to content to content: "\00a0\00a0" in the .fa-globe::before class, it will give the i content and that element can now align by the baseline.
.fa-globe::before {
content: '\00a0\00a0';
...
I forked your fiddle and made the small change here: https://jsfiddle.net/ndebellas/y4dLcqkx/.

Removing mime type icon from image using CSS, possible?

I'm currently using some CSS to append font-awesome icons as mime types for uploaded files and or links that end in .pdf, .xls, .docx, etc.
I should have prefaced this entire post with this comment I made:
Ok, I should have mentioned that this is a WordPress site where users are able to upload and link images via the Media Uploader. Trying to automate this process so that (once delivered) the editor won't have to add HTML code to the visual editor. That being said, all WP images have a class assigned to them that's ".wp-image-*", would it be possible to use that WP class to filter the icons?
My CSS looks like this:
a[href$=".pdf"]::after {
font-family: "fontawesome";
content: "\0020\f1c1";
color: inherit;
font-weight: 400
}
This solution works exactly as I want it to with one exception... it appends the mime type icon to images that LINK to a .pdf not just text links.
How to remove or not display the font-awesome icon on images only? That is the question. I have tried a number of different CSS solutions and have come up with either removing the entire image that is linked to the .pdf, or nothing at all.
Looking for some guidance here, would prefer the solution to be CSS but am open to whatever will work the best(php, js, jquery, etc).
HERES AN EXAMPLE:
(text link)
Example PDF
This works as expected.
This is the problem...
(image link below)
<a href="example.pdf">
<img src="example.jpg" alt="example pdf" />
</a>
When the link wraps an image, it appends the font awesome icon to the image. How to stop the font awesome icon on images wrapped in links only?
My page code looks like this (not verbatim), also, using BootStrap Library:
<div class="container">
<div id="main_content">
<!-- Then there are the usual basic tags found in WordPress content such as <p><h1><blockquote> etc but the containing div is "main_content", no <div>'s before image -->
<p>
<a href="http://example-document.pdf">
<img class="alignright size-medium wp-image-639 img-responsive" src="http://example-image.jpg" alt="Alt Title" srcset="http://example-image.jpg 232w, http://example-image.jpg 613w" sizes="(max-width: 232px) 100vw, 232px">
</a>
</p>
</div>
</div>
To solve it with the existing markup you'll need a parent selector, and those does not exist (yet).
A workaround could be to wrap the text in the text only links with a span and update the CSS rule with the :not(img) selector
a[href$=".pdf"] :not(img)::after {
content: " X";
color: red;
font-weight: 400
}
<span>Example PDF</span>
<br>
<a href="example.pdf">
<img src="http://placehold.it/100" alt="example pdf" />
</a>
Or add a data-* attribute on the links that contain an image
a[href$=".pdf"]:not([data-hasimg])::after {
content: " X";
color: red;
font-weight: 400
}
Example PDF
<br>
<a href="example.pdf" data-hasimg>
<img src="http://placehold.it/100" alt="example pdf" />
</a>
If you can't change markup, here is a script sample
var links = document.querySelectorAll('a[href$=".pdf"]');
for (var i = 0; i < links.length; i++) {
if (links[i].children.length == 0) {
links[i].classList.add('icon');
}
}
a[href$=".pdf"].icon::after {
content: " X";
color: red;
font-weight: 400
}
Example PDF
<br>
<a href="example.pdf">
<img src="http://placehold.it/100" alt="example pdf" />
</a>
Place your text in a span and give it a class name like this:
a[href$=".pdf"] .text:after {
font-family: "fontawesome";
content: "\0020\f1c1";
color: inherit;
font-weight: 400
}
<span class="text">Example PDF</span>
<a href="example.pdf">
<img src="example.jpg" alt="example pdf" />
</a>

Having trouble styling a span within an anchor tag in IE6 CSS

The company I work for still uses IE6 therefore I am required to make sure that my site works in IE6 browsers. I'm having trouble styling due to the constraints of the code design done through SharePoint 2007.
When you hover over a non-active tab, the text should change color from blue to orange.
<div class="webpartBody">
<div class="tabsWrapper">
<a class="quickLinkTabs activeTab" href="#">
<span class="tab0">Clinical</span>
</a>
<a class="quickLinkTabs" href="#">
<span class="tab1">Business Services</span>
</a>
<a class="quickLinkTabs" href="#">
<span class="tab2">Employees</span>
</a>
<a class="quickLinkTabs" href="#">
<span class="tab3">Projects</span>
</a>
<a class="quickLinkTabs" href="#">
<span class="tab4">Web Links</span>
</a>
</div>
<!-- links -->
</div>
jQuery is utilized to create classes for the quickLinkTabs so that the firstTab and lastTab are labeled as such and that the tab that is currently selected is the activeTab.
Using just this code outside of the SharePoint environment, I apply the following CSS to achieve the effect I'm looking for.
.quickLinkTabs:hover
{
color: #ff6600;
}
.quickLinkTabs span:hover
{
color: #ff6600;
}
As soon as I apply this to the development environment and try this on SharePoint generated code, it no longer works. I cannot figure out what the hindrance is - is it SharePoint? is it my CSS?
There is no purpose for the SPAN to be there in the first place. You should adjust the styling of the A-tag to perform the same functionality.
then use:
.tabsWrapper a { .... }
.tabsWrapper a:hover { ... }

html, displaying a link as normal text

I was wondering if you could display a link as normal text.
<a id="" href="" target="_parent"><img src="" width="121" height="20" alt="">
<div style="position:absolute;left:163px;top:1px;font-size: 12px; display: block">
<font color="white">Log in</font></a>
I'm trying to overlap an image that is also a button, with the text "Log in", it works as it is with the code above, but I was wondering if I can change the "log in" which displays as blue and underlined to appear as normal text.
In css:
a {
color: inherit;
text-decoration: inherit;
}
These values can also be stuck in your anchor tag's style attribute.
Should result in your anchor tags looking the same as the text color and decoration of the parent(s).
If you have a look at Cascading Style Sheets (CSS) you can change the colour and the text style of the link.
In your example, you could use
<a id="" href="" target="_parent" style="color: white; text-decoration: none;"><img src="" width="121" height="20" alt="">
<div style="position:absolute; sleft:163px;top:1px;font-size: 12px; display: block">
<font color="white">Log in</font>
</div>
</a>
However I would learn how to use external stylesheets and link them to your HTML through the <link> tag in the <head> of your html. You can then style up individual tags through the tag name, an id or a css class. So an updated example would be:
<link rel="stylesheet" href="link-to-your-css-file" />
in your css file have
a.imgLink{
color: white; text-decoration: none;
}
div.imgLink{
position: absolute; left: 163px; top: 1px; font-size: 12px; display: block;
}
Then your html would be
<a class="imgLink" id="" href="" target="_parent">
<img src="" width="121" height="20" alt="">
<div class="imgLink">
Log In
</div>
</a>
Not only does it make your HTML "dry" but it gives you greater control over the styles of your html by only changing the css file.
If you don't want the link to be underlined,
set " text-decoration:none"
use this code in your html file
<style>
a {
text-decoration: none;
color: #000; /* or whatever colour your text is */
}
</style>
Short answer: yes.
Longer answer:
Yes, here is a fiddle, but you probably don't want to hide links from your user.
stslavik makes a good point with "text-decoration: inherit". Here is another fiddle. On my browser the "blam" and "stslavic" both show with strike-through, but I'd go with the "inherit" versus the "none"; just seems better to me.
(P.S not advertising this and no spam. Click on 'Hate AI' to reach my project)
You can do this =>
<h1><a style="text-decoration: none; color: inherit;" href="https://obnoxiousnerd.github.io/hate-ai">Hate AI</a></h1>
<p>A personal assistant that hates you but still helps you.</p>
The logic here was adding a style to the a tag which contains the following:-
text-decoration: none;
color: inherit;
text-decoration for removing the underline under the text.
color: inherit for removing the usual purple color of links.
Sure - just adjust the CSS for 'a' elements on the page.
Just a simple snippit to show some size/coloring possibilities, to make your link fit thematically when the rest of your text a bit better.
Wow, Look at this website! It's called Website! It's a shame that this link looks horrible, though!
<h2><a style="color: #A52A2A;; text-decoration: none;" href="https://www.website.com/">Oh, boy! You can now click here to visit Website's website without the link looking bad!</a></h2>
<h2><a style="color: #A52A2A;; text-decoration: none;" href="https://www.bing.com/">Uh oh, the Website website is broken! Visit the pinnacle of innovation, Bing, instead!</a></h2>