Issue with applying dotted border to cells in table design

后端 未结 9 1060
不知归路
不知归路 2021-01-12 07:48

Here\'s my fiddle:

http://jsfiddle.net/gFA4p/84/

In this screenshot, the green lines represent where I\'m trying to apply dotted lines.

相关标签:
9条回答
  • 2021-01-12 08:22

    With jQuery, you can:

    • find all elements in that wanna-have-geen-borders column
    • give them all dotted green lef
    • give them all dotted bottom green border
      • use the :last to remove the undesired bottom border from the last element

    You can find all rows in that column by doing something like:

    $(td[class*="greenBorder"]).addClass("green_borders");
    $(td[class*="greenBorder"]).last().css('border-bottom','')
    

    Note im saying something like because im not very good with jQuery and don't have the right syntax/grasp of how selectors are used. But I've seen examples where similar things are done. You can find tonnes of examples of this site, or consult the original documentation (which is kinda bad, imho).

    Ok, I did it:

        <!DOCTYPE HTML>
        <html lang="en">
        <head>
        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
        <title>Green Border</title>
    
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
        <style type="text/css">
        .geniusPicks {}
        .geniusPicks table {width:100%; font-size:12px;}
        .geniusPicks table tr#picksHeading {border:0px solid; height:30px;}
        .geniusPicks table tr#picksHeading th {background:darkRed; color:white; font-weight:bold;}
        .geniusPicks table tr.pickHeading {border:0px solid;}
        .geniusPicks table tr.pickHeading td {background:red; padding-left:10px;}
        .geniusPicks table tr.pickConsensusBody td {border:1px solid; background:grey;}
        .geniusPicks table tr.pickBody td {border:1px solid;}
        .bigGap td {height:19px;}
        .smallGap td {height:10px;}
        .geniusPicks table th,
        .geniusPicks table th+th+th+th+th+th,
        .geniusPicks table .pickHeading+tr td,
        .geniusPicks table .pickHeading+tr td+td+td+td+td+td+td {text-align:center;}
        .geniusPicks table th+th+th,
        .geniusPicks table .pickHeading+tr td+td+td {text-align:left;}
        .borderLeftRadius {
            border-radius:15px 0 0 0;
            -moz-border-radius:15px 0 0 0;
            -webkit-border-radius:15px 0 0 0;
            -khtml-border-radius:15px 0 0 0;
        }
        .borderRightRadius {
            border-radius:0 15px 0 0;
            -moz-border-radius:0 15px 0 0;
            -webkit-border-radius:0 15px 0 0;
            -khtml-border-radius:0 15px 0 0;
        }
        </style>
        <script type="text/javascript">
    $(document).ready(function() {
        var green = jQuery("td[name='green']");
        green.each(function(){
    
            var cl = $(this).attr('class');
            var prev = $(this).prev();
            $(this)
                .css('border-color','#aeaeae')
                .css('border-style','dotted')
                .css('border-right-style','solid')
                .css('border-right-color','black')
                .addClass(function(i,currentClass){ return "dotted"; });
    
            if (prev.attr('class') == "dottedRightBorder") {
                prev.css('border-right-style','dotted')
                    .css('border-right-color','#aeaeae')
            }
    
            if (cl=="top") {
                $(this)
                    .css('border-top-style','solid')
                    .css('border-top-color','black')
            } else 
    
            if (cl=="bottom"){
                $(this)
                    .css('border-bottom-style','solid')
                    .css('border-bottom-color','black')
            }
        });
    });
        </script>
        </head>
        <body>
        <div class="geniusPicks">
            <table cellpadding="1" cellspacing="0">
    
                <thead>
                    <tr id="picksHeading">
                        <th class="borderLeftRadius">Sport</th>
                        <th>Status</th>
                        <th colspan="2">Pick</th>
                        <th>Genius</th>
                        <th>Genius Credential</th>
    
                        <th class="borderRightRadius">Result</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="bigGap">
                        <td colspan="7"></td>
                    </tr>
                    <tr class="pickHeading">
    
                        <td colspan="7" class="borderLeftRadius">blah</td>
                    </tr>
                    <tr class="pickConsensusBody">
                        <td rowspan="4">moo</td>
                        <td rowspan="4">flah</td>
                        <td rowspan="4" class="dottedRightBorder">glah</td>
                        <td name="green" class="top">vlah</td>
    
                        <td>mlah</td>
                        <td>nlah</td>
                        <td rowspan="4">jlah</td>
                    </tr>
                    <tr class="pickConsensusBody">
                        <td name="green" >clah</td>
                        <td>dlah</td>
    
                        <td>xlah</td>
                    </tr>
                    <tr class="pickConsensusBody">
                        <td name="green" >plah</td>
                        <td>slah</td>
                        <td>klah</td>
                    </tr>
    
                    <tr class="pickConsensusBody">
                        <td name="green" class="bottom">qlah</td>
                        <td>wlah</td>
                        <td>zlah</td>
                    </tr>
    
                    <tr class="smallGap">
                        <td colspan="7"></td>
    
                    </tr>
    
                    <tr class="pickHeading">
                        <td colspan="7" class="borderLeftRadius">blah</td>
                    </tr>
                    <tr class="pickBody">
                        <td rowspan="4">moo</td>
                        <td rowspan="4">flah</td>
    
                        <td rowspan="4" class="dottedRightBorder">glah</td>
                        <td name="green" class="top">vlah</td>
                        <td>mlah</td>
                        <td>nlah</td>
                        <td rowspan="4">jlah</td>
                    </tr>
    
                    <tr class="pickBody">
                        <td name="green" >clah</td>
                        <td>dlah</td>
                        <td>xlah</td>
                    </tr>
                    <tr class="pickBody">
                        <td name="green">plah</td>
    
                        <td>slah</td>
                        <td>klah</td>
                    </tr>
                    <tr class="pickBody">
                        <td name="green" class="bottom">qlah</td>
                        <td>wlah</td>
                        <td>zlah</td>
    
                    </tr>
    
                    <tr class="smallGap">
                        <td colspan="7"></td>
                    </tr>
                </tbody>
            </table>
        </div>
    
    0 讨论(0)
  • 2021-01-12 08:23

    This works if I add inline styles to the HTML and get rid of the class names.

    http://jsfiddle.net/jasongennaro/xWSKD/1/

    EDIT

    This also works if I add the styles to the css with an !important declaration

    .dottedRight{border-right:2px dotted black !important;}
    
    .dottedBottom{border-bottom:2px dotted black !important;}
    

    http://jsfiddle.net/jasongennaro/xWSKD/2/

    Note

    The fiddles show the dotted line as red only to point out the change. See above code for correct use.

    Also, see the comment below re implications of using !important ( What are the implications of using "!important" in CSS? )

    0 讨论(0)
  • 2021-01-12 08:23

    Here we go http://jsfiddle.net/gFA4p/86/

    0 讨论(0)
提交回复
热议问题