difficult HTML, JavaScript, CSS grid page

徘徊边缘 提交于 2019-12-03 07:33:31

Personally I think tables are the devil, so here is something more like what I would do that uses floated divs:

http://jsfiddle.net/gbcd6/11/

You could easily swap out the text content for images, or add background images through CSS, as well as call separate JS functions based on the one-nine class each "control" div has.

EDIT:

Here is the most current version of the solution, which does include an actual table rather than using display: table-cell, as well as additional example markup for images and wrapping, and a basic Javascript example. This was done to fix an issue with older browser support, and to meet KM's requirements. Though the overall structure is still pretty much the same as the original fiddle.

I'd go for a large table, indeed.

And it's not so very hard to accomplish, at least if this is more or less what you need:

http://jsfiddle.net/gNBSc/4/

(i'm a bit bored, today :-)

I just came up with this solution http://jsfiddle.net/LNw3G. It's a mix between the use of table and div elements.

I also added an image sprite, positioning through class names left, center, right, top and bottom (so you don't have to edit all the image positions in your css), and javascript for parsing specific calls depending on the anchor class.

This is an example of the HTML for a single cell. cell-wrap cell1 contains the elements and positions the background image sprite, the table vertically aligns the text, and cell contains the controlled positioned images wrapped into image divs.

<div class="cell-wrap cell1">
    <table class="content">
        <tr>
            <td>Connection is not correct</td>
        </tr>
    </table>
    <div class="cell hidden">
        <div class="image left top">
            <a href="#linkA" class="linkA"><img src="http://goo.gl/wNDMe"></a>
        </div>
        <div class="image right top">
            <a href="#linkB" class="linkB"><img src="http://goo.gl/wNDMe"></a>
        </div>
        <div class="image left bottom">
            <a href="#linkC" class="linkC"><img src="http://goo.gl/wNDMe"></a>
        </div>
    </div>
</div>

This is the significant javascript code, which filters anchors containing class names with link to the desired specific functions:

$(function() {
    $(".cell a").click(function(e) {
        if ($(this).attr("class").match(/link(.)(\\s[\\b]*)?/)) {
            var param = $(this).attr("class").replace(/(.*\s)*link(.).*$/, "$2");
            doThings(param);
        }
    });
});

function doThings(param) {
    switch (param) {
    case 'A':
        //specific 'A' functions
        break;
    case 'B':
        //specific 'B' functions
        break;
    default:
        //default functions
        break;
}

It has been tested IE7+, FF, Chrome, Safari and Opera.

Ps: There is a workaround for IE6 you can use for this example, consisting in adding an specific hover.htc file and the css line body { behavior: url(hover.htc); } (more detailed here) to simulate hover effect on non-anchor elements.

Ps: Be careful with the <!DOCTYPE declaration. If you leave empty spaces, maybe something like this <! DOCTYPE, IE7 may treat it as non valid jumping into quirks mode (while testing, it drove me nuts!).

Gave it a try, you can find the attempt here. Let me know if misunderstood something. Tested in FF5, newest Chrome, IE8 (and in IE7 compatibility mode). Uses no libraries, doesn't need to actually be a grid (depends on the width that you can set in CSS) and gives you the index of the image and the button that was clicked. Oh, and the grid should be easily generatable (based on your DB) in PHP etc.

EDIT: The text is now vertically-aligned also.

http://jsfiddle.net/F37qs/1/

Pretty much an example of what you would want with

  1. floating div's... Allowing custom "table sizes";
  2. Reactive rollover "abit randomized"; and lastly,
  3. Centralized content (see the centralized text in each grid);

Note : You can adjust the various number of rows / cols you want. =)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!