473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating a grid overlay over an image in CSS

Hey there,

I have a large image in a browser window, and I would like a way to
overlay grid lines on top of the image, so a user can show the grid or
hide the grid lines. The grid would cover 100% of the image, and all I

would need is a set of horizontal and vertical lines over the image to
create a grid overlay.

Two requirements would be to:

1) show/hide the grid
2) change the spacing between the grid lines
Is there a way I can leverage some functionality in CSS to do
this? I can't use any server side 3rd party components, and I would
rather not do this using something on the server side like GDI+ through

ASP.NET.
Thanks,
Christian

Aug 3 '06 #1
3 7559
Hi Christian,

I think we can get what you want. For starters, between the <headand
</headtags of your HTML page, add this:
<style type="text/css">
..gridbox{position:relative;float:left;width:auto; }
#grid{background:transparent url(grid.gif)
repeat;width:100%;height:100%;position:absolute;to p:0;left:0;display:none;}
</style>
<script type="text/ecmascript">
function showHideGrid() {
var grid = document.getElementById('grid');
if (grid) {
if (grid.style.display == 'block') {
grid.style.display = 'none';
} else {
grid.style.display = 'block';
}
}
return false;
}
</script>
and then between the <bodyand </bodytags, something like this:
<a href="#" onclick="return showHideGrid()">Show / hide grid</a>
<div class="gridbox"><img src="test.jpg" /><div id="grid"></div></div>
I put an example up for you to see:
http://homepage.mac.com/denodell/examples/grid/grid.htm

You'll notice in the <headsection, I've specified 'grid.gif', this is
a transparent gif image which is repeated to give the appearance of a
grid. In the <bodysection, you should replace 'test.jpg' with your
own image.

If you explain in more detail how you'd like the grid spacing part of
it to work, I'll see if we can't help out with that bit too..

Good luck
Den
ka******@hotmail.com wrote:
Hey there,

I have a large image in a browser window, and I would like a way to
overlay grid lines on top of the image, so a user can show the grid or
hide the grid lines. The grid would cover 100% of the image, and all I

would need is a set of horizontal and vertical lines over the image to
create a grid overlay.

Two requirements would be to:

1) show/hide the grid
2) change the spacing between the grid lines
Is there a way I can leverage some functionality in CSS to do
this? I can't use any server side 3rd party components, and I would
rather not do this using something on the server side like GDI+ through

ASP.NET.
Thanks,
Christian
Aug 7 '06 #2
I should mention, I've only tested my solution on Safari/Mac, but it
should be fine elsewhere.

ka******@hotmail.com wrote:
Hey there,

I have a large image in a browser window, and I would like a way to
overlay grid lines on top of the image, so a user can show the grid or
hide the grid lines. The grid would cover 100% of the image, and all I

would need is a set of horizontal and vertical lines over the image to
create a grid overlay.

Two requirements would be to:

1) show/hide the grid
2) change the spacing between the grid lines
Is there a way I can leverage some functionality in CSS to do
this? I can't use any server side 3rd party components, and I would
rather not do this using something on the server side like GDI+ through

ASP.NET.
Thanks,
Christian
Aug 7 '06 #3
Den-

Thank you very much for your help in this. I should note a couple of
things:

1) The user will probably get an option to spcify the size of the grid
in pixels. ie, if they choose 20px, the length of each side of a grid
square would be 20 pixels.

I'm still working out some possible design problems. For example, we
have sizable regions on a page with icons that the user can position
withing the region. If I set the z-index of the grid to show over
these regions so the user can see the grid and thus align the icons, we
will lose our onclick() events, which we need.

Thanks again for your help and I hope this gives you more information.

Christian

Den Odell wrote:
Hi Christian,

I think we can get what you want. For starters, between the <headand
</headtags of your HTML page, add this:
<style type="text/css">
.gridbox{position:relative;float:left;width:auto;}
#grid{background:transparent url(grid.gif)
repeat;width:100%;height:100%;position:absolute;to p:0;left:0;display:none;}
</style>
<script type="text/ecmascript">
function showHideGrid() {
var grid = document.getElementById('grid');
if (grid) {
if (grid.style.display == 'block') {
grid.style.display = 'none';
} else {
grid.style.display = 'block';
}
}
return false;
}
</script>
and then between the <bodyand </bodytags, something like this:
<a href="#" onclick="return showHideGrid()">Show / hide grid</a>
<div class="gridbox"><img src="test.jpg" /><div id="grid"></div></div>
I put an example up for you to see:
http://homepage.mac.com/denodell/examples/grid/grid.htm

You'll notice in the <headsection, I've specified 'grid.gif', this is
a transparent gif image which is repeated to give the appearance of a
grid. In the <bodysection, you should replace 'test.jpg' with your
own image.

If you explain in more detail how you'd like the grid spacing part of
it to work, I'll see if we can't help out with that bit too..

Good luck
Den
ka******@hotmail.com wrote:
Hey there,

I have a large image in a browser window, and I would like a way to
overlay grid lines on top of the image, so a user can show the grid or
hide the grid lines. The grid would cover 100% of the image, and all I

would need is a set of horizontal and vertical lines over the image to
create a grid overlay.

Two requirements would be to:

1) show/hide the grid
2) change the spacing between the grid lines
Is there a way I can leverage some functionality in CSS to do
this? I can't use any server side 3rd party components, and I would
rather not do this using something on the server side like GDI+ through

ASP.NET.
Thanks,
Christian
Aug 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy | last post by:
Is there a way to overlay a Red X on top of a .jpg image so the image still is visible but X'd out? function XitOut{ if(document.me.Quantity.value == 0) { Put a X over the .jpg image(Okay, I...
1
by: sendhil | last post by:
hi, Iam doing some graphics programming with C#. I have to create a Windows MetaFile from a base64 encoded string. How do i create the file. I want to Overlay this Windows MetaFile on a image...
5
by: Brian Lowe | last post by:
My web site accepts uploaded photos and stores them in a SQL table as BLObs so they never touch the filesystem. I have a way to create a thumbnail version of the uploaded image and store that in...
2
by: Carl Gilbert | last post by:
Hi I have to following code which sets up a new bitmap. 'set up a transparent 16x16 bitmap Dim bm As New Bitmap(16, 16) Dim g As Graphics = Graphics.FromImage(bm)...
10
by: kaczmar2 | last post by:
Hey there, I have a large image in a browser window, and I would like a way to overlay grid lines on top of the image, so a user can show the grid or hide the grid lines. The grid would cover...
1
by: Frijoles | last post by:
Hello, I have a function that accepts an Image as the input. Currently, I load a bitmap in the calling class and pass that in. I'd like to create an overlay with another image and then pass the...
0
by: ameshkin | last post by:
Hi, Im pretty new at PHP and need help with something very simple. I wrote a function which watermarks an image. The function works, but i can't figure out how to output the image into a file. ...
9
by: Chuck Anderson | last post by:
Is it possible to overlay a transparent watermark on an image - dynamically? I'd like the result to look like this example: <http://www.cycletourist.com/temp/photo.php> That is a bit of...
6
by: Romulo NF | last post by:
Greetings again to everyone, Im back to show this grid componenet i´ve developed. With this grid you can show the data like a normal table, remove the rows that you need, add rows, import data,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.