css div image information for search engines - css

I have a website and in the main page a I have a div with an image where with a very nice design says "contact us by calling 1 800 blabla..". so I was thinking if the only place where the phone number of my company, is on a div with an image background, how the search engines are going to recognize or find my company's number,
so my question is basically how can I add information to this div which is :
<div id="phone"></div>
and any other div that i need to put information for robots and stuff

It's pretty easy using an image replacement technique.
<div id="phone"><span>11-1111-1111</span></div>
And the CSS.
(change your phone div to be whatever you need it to be, but you'll need to define a width and overflow: hidden to hide the text.
#phone
{
position: relative;
width: 200px;
height: 100px;
overflow: hidden;
}
#phone span
{
position: absolute;
left: -999em;
}
Alternatively, without using extra markup (I read somewhere that google disapproved of using text-indent in this way which is why I didn't use this first, but I can't find the source for that).
<div id="phone">11-1111-1111</div>
And the CSS.
#phone
{
width: 200px;
height: 100px;
overflow: hidden;
text-indent: -999em;
}
Additionally: http://css-tricks.com/css-image-replacement/ looks like a fairly decent resource.

You might want to look into hCard microformat specification and create an HTML code something like this:
<div class="call-us vcard">
<span class="tel">
<span class="type">business</span>
<span class="value">+1.800.blabla</span>
</span>
</div>
Where the call-us classname formats the div by setting its dimensions, visually hiding the span.tel tag and adding the image as a background. Search engines would recognize that this is a contact card (note the vcard classname), and they would correctly parse the phone number.

You have to use this approach
#ContactInformation {/* your image and restof padding */}
#ContactInformation h2 { display: none; visibility: hidden; }
<div id="ContactInformation">
<h2>Phone:</h2>
<label>1 800 blah blah</label>
</div>
Actually Search Engines See and check h2 tag and it's value but your user wont see the h2 text.

Related

CSS :after or :before reading dynamic values from HTML. No JS. Pure CSS

Hello and thank you for reading this.
First off, I have to say that I can't use JavaScript. I am not aloud to any code that needs 'upkeep' because we run hundreds of sites for hundreds of clients in-house clients. Any code that needs maintenance is highly discouraged. I've tried to push back and it's not working. I don't have the power.
With that said, I have a client that would like to have icons to represent topics and when you roll over the icon, there is an overlay over said icon with the text saying what the topic is.
For example, if there is the topic 'Fruit' there would be a photo representation of a fruit (say, a banana). When the mouse rolls over the banana pic, an overlay would appear with the word fruit in the middle.
This isn't about the overlay or the icon.
What I would like to know is if I can read read the topic name in and have that displayed in the :after pseudo element.
In pretend code, this is what I'm tryin to do:
<div class="topic-icon><img src="icon-image"></div>
<div class="topic-label>Fruit</div>
Pretend CSS:
.topic-icon:after {content: '[Topic Label]'};
I'm working in Drupal and can set up the HTML as needed. Would I be able to pull in the topic label like this:
<div class="topic-icon" topic="Fruit"><img src=....></div>
With the CSS something like:
.topic-icon:after {content: '[Topic]'};
I hope I am making my self clear.
Let me know if something like this is even possible.
You may set up the pseudo class with :hover::after selector, with the content of attr(topic)
.topic-icon {
position: relative;
display: inline-block;
}
.topic-icon:hover::after {
content: attr(topic);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(0, 0, 0, 0.5);
color: white;
}
<div class="topic-icon" topic="Fruit">
<img src="https://cdn.iconscout.com/icon/free/png-256/banana-1624204-1375362.png" width="64" height="64">
</div>

Add a simple footer to Squarespace Cover Page template "Premier"

I don't know if you guys have messed with Squarespace Cover Pages but man they're hard to navigate code-wise. I'm doing a standalone promotional site that only requires a cover page and a video so I'm using the "Premier" cover page. However, for legal reasons I've got to have a footer with copyright info and a link to our privacy statement. My original idea was to use header injection with css ::after to include a full width div but I want the cover page to still take up the full screen and for the user to be able to scroll down to see the footer.
One example I tried to modify was https://answers.squarespace.com/questions/109923/adding-footer-text-on-cover-page-code-injection.html using this code:
<style>
#collection-559df309e4b026e5cd65a4b4
[data-slide-id="559df309e4b026e5cd65a4b5"]
.sqs-slice-group.group-social::after {
content: "some general text";
padding: 5px 0;
margin: 0 auto;
text-align: center;
font-size: 10px;
color: #fff;
}
</style>
I swapped out my collection ID and data-slide-id into this code but it put the "general text" block on top of the play button as well as in the upper-right corner of the screen. I've tried changing elements around to no avail - any help would be appreciated.
Here's what I would do, if I preferred to avoid the use of Javascript. Insert the following HTML into the "Code Injection" header area for the cover page. This will add a div that appears below the main content area, so that the user must scroll down to see it.
<div id="coverFooter">
<a id="coverPP" href="/privacy-policy/">Privacy Policy</a> <span id="coverCR">© 2016 Your Company, LLC</span>
</div>
<style>
#coverFooter {
position: absolute;
z-index: 1;
top: 100%;
width: 100%;
padding-top: 20px;
padding-bottom: 20px;
background-color: white;
box-sizing: border-box;
text-align: center;
padding-right: 30px;
padding-left: 30px;
/* Use this for right aligned text instead.
text-align: right;
padding-right: 60px;
padding-left: 60px;
*/
}
#coverPP {
white-space: nowrap;
}
#coverCR {
margin-left: 10px;
white-space: nowrap;
}
</style>
Here is a working example, which I will keep online for a week.
You will of course want to modify the href link, the copyright text, and perhaps the CSS rules such as colors and padding values.
Keep in mind that this is injecting the coverFooter div into the top of the body element, though CSS is making it appear at the bottom. This could encourage search engines to index the text inside the div as your page description in SERPS. Be sure to add a "Search Engine Description" under Settings -> Basic in order to help mitigate this, and keep an eye on your page description in SERPS. If this becomes a problem, keep the CSS in the header injection area, but replace the div HTML with Javascript which inserts the div at the bottom of the body element.
Finally, you'll either be linking to a privacy policy on another domain or you'll have to select "Add more pages" and add the privacy-policy page to the "not linked" section.

Can I "freeze" an element inside a scrollable DIV with just CSS (or something that looks good on mobile)?

I'm going to guess the answer to this question will be "no," but it would be so nice, I'm going to ask anyways.
What I'm trying to do is freeze an element inside a scrollable DIV such that it stays in place vertically. This is to implement a frozen row feature in a table.
It's pretty easy to do with JavaScript and absolute positioning. Here's the HTML for a container and three inner DIVs (see here for the live version):
<div id="container">
<div id="background">
Content
</div>
<div id="absolutediv">
Absolute stays inside
</div>
<div id="fixeddiv">
Fixed escapes!
</div>
<div id="absolutediv2">
Stays put!
</div>
</div>
The relevant CSS:
#container {
position: fixed;
left: 20px;
width: 250px;
height: 250px;
top: 20px;
overflow: scroll;
}
#absolutediv {
position: absolute;
top: 30px;
width: 300px;
background-color: #CEC;
}
#fixeddiv {
position: fixed;
top: 100px;
width: 300px;
background-color: #ECC;
}
#absolutediv2 {
position: absolute;
width: 300px;
top: 120px;
background-color: #ECC;
}
And JavaScript that will hold #absolutediv2 in place:
var div = document.getElementById('absolutediv2');
var container = document.getElementById('container');
container.addEventListener('scroll', function() {
div.style.top = container.scrollTop + 120 + 'px';
});
So #absolutediv2 is behaving the way I want. But look at #fixeddiv. This gets close to what I'm after, and I suspect it looks nicer on mobile devices because the browser can hold it in place without waiting to run the script. Except that it (a) runs right over the borders, and (b) doesn't scroll horizontally.
Is there any way to get what I'm after with pure CSS, something that would run well on a mobile browser?
(In my page, one way to do this would be to place the frozen row above the container DIV, but the number of frozen rows changes depending on where the user has scrolled to, meaning that the container DIV would have to move around.)
Edit:
To sum up, I want a div that:
Scrolls horizontally with its container
Stays put when its container scrolls vertically
Looks like it belongs to its container
Looks nice on a mobile browser
The last one is the tricky bit. I can achieve #1, #2, and #3 with an absolute-position div and JavaScript, but it looks ugly on a mobile browser because it lags. Using a fixed-position div, I can get #2 and #4, and I can achieve #1 with JavaScript (the lag doesn't bother me so much horizontally), but not #3, because a fixed-position div suddenly sits on top of its container.
Google has a suggestion for this kind of thing, but it's a pretty extreme solution: https://developers.google.com/mobile/articles/webapp_fixed_ui
Ok, I haven't tested this but it should be along the right track. Basically this gives you the ability to create multiple "Sticker" items with the HTML5 data attribute I created for you data-special="sticker". The jQuery looks for these, then copies the data and appends it to another <div> element that is positioned where the original was, then it hides the original.
#container {
position: fixed;
left: 20px;
width: 250px;
height: 250px;
top: 20px;
overflow: scroll;
}
#original-element {
position: absolute;
top: 30px;
width: 300px;
background-color: #CEC;
}
.sticker {
position:absolute;
}
<div id="wrapper">
<div id="container">
<div id="background">
Content
</div>
<div id="original-element" data-special="sticker">
I want to stay put!
</div>
</div>
</div>
$("[data-special='sticker']").each(function () {
$('#wrapper').append(
$('<div/>').html($(this).html())
.addClass("sticker")
.css('top', parseInt($('#container').css('top')) + parseInt($(this).css('top')))
.css('left', $('#container').css('left'))
.css('width', $('#container').css('width'))
.css('background-color', $(this).css('background-color'))
);
$(this).css('display', "none");
});
Let me know how it works for you, also one downside to this is once the original element is hidden, the space it used to take up is then collapsed... I'll try to brainstorm a solution for that.
Edit:
Changed the JS to get the #container width instead of the original element width as the original element is larger that the container.
Edit:
Tested: jsfiddle
Some issues would be that the element will then also overlap the scroll bar, if you knew the width of that you could then subtract if from the value.
Also check the updated code above. There were some errors...
You might want to have a look at the following post:
How can I make a div stick to the top of the screen once it's been scrolled to?
As explained in this answer:
A script-free alternative is position: sticky, which is
supported in Chrome, Firefox, and Safari. See the article on
HTML5Rocks
and demo, and
Mozilla
docs.
As of today, the demo linked works for me in Firefox but not in Chrome.

CSS background-image doesn't display

I am confused about using CSS to display an image using the an empty <a> element.
<a class="header" href="#"></a>
does create the clickable area as specified in the following css:
.header { width: 50px; height 50px; background-image:url('images/picture.png') }
however, will not display the picture. If I also include:
.header:hover { background-image:url('images/picture.png'); }
then it will display the picture. My aim is to use the CSS to employ this method of image-to-image replacement, but I don't have the basics understood yet it would seem.
Your on the right track with your css. You must add display:block to allow the anchor tag to pick up the hight.
.header { width: 50px;
height 50px;
background:url('images/picture.png');
display:block;
}

CSS text replace with image, need hyperlink

I am using the text-indent technique to replace my <h1/> tag with my website's image as so:
<h1 title="Homepage">My logo</h1>
CSS:
#header h1 {
float: left;
background: transparent url('../images/logo.png');
width: 214px;
height: 64px;
text-indent: -9999px;
}
The only problem is that I want to still have the new image act as a hyperlink. I tried doing:
<h1 title="Homepage">My logo</h1>
But since it is being indented, the link is too. I wanted to know if anyone had any suggestions on how to do this and still be valid XHTML.
EDIT I'd rather do it in a way that is accessible to users with screen readers, from what I read, doing a display:none will not work with some readers.
There are many ways to do this, this is the way that I prefer, it works well, and is easy to implement.
<div id="header">
<h1>Homepage</h1>
</div>
Then i do this css, this is also know as the "Leafy/Langridge image replacement" method
#header h1 a {
display: block;
padding: 22px 0 0 0;
overflow: hidden;
background-image: url(../images/sidebar/heading.png);
background-repeat: no-repeat;
height: 0px !important;
height /**/:22px;
}
The only thing you should have to edit is the height, and the padding-top. In this example it is 22px, this should be equal to your image-height.
Why are you mucking about with negative indents - just use the alt attribute of the img tag?
<h1 title="Homepage><img src="images/logo.png" alt="My logo"/></h1>
#Partrik Hägne: You should't use display:none, because some screen readers will ignore that...
You can see a list of Nine Techniques for CSS Image Replacement on http://css-tricks.com, which describes the cons and pros for each solution.
What you can do is remove the indent. And use a span to hide instead:
<h1 title="Homepage"><span>My logo</span></h1>
#header h1 span
{
display: none;
}
You might have to set the width and height of the A-tag also since nothing fills using this trick.

Resources