Fork me on GitHub

html magic?  Bottom

  • anyone know if it is possible to have a div that extends across multiple table cells? any idea how to accomplish it?
  • According to the W3C HTML Markup Validator, you cannot have a div inside a table structure that groups only td elements.

    In other words,

    Code

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
       <title>TITLE</title>
       
    </head>
    <body>

      <table>
        <tr>
          <div>
            <td>data</td>
            <td>data</td>
          </div>
          <td>data</td>
        </tr>
      </table>
         
    </body>
    </html>


    does not validate. It says that the div tag is not allowed to be there.

    What are you ultimately trying to accomplish?

    --
    - Robert

    Ohloh profile for Robert Burkhead

    Stack Overflow profile for RobertB at Stack Overflow, Q&A for professional and enthusiast programmers
  • Not a div, but a table may contain multiple tbody sections. With several different tbody elements you can divide your table structurally. Alternatively (or in addition) you might consider using classes for table rows.

    --
    Guite | ModuleStudio
  • Quote

    What are you ultimately trying to accomplish?

    something more like:

    Code

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
       <title>TITLE</title>
       
    </head>
    <body>

      <table>
        <tr>
            <td><div style='color:red;'>data that spans three cols</div></td>
            <td>data</td>
            <td>data</td>
        </tr>
      </table>
         
    </body>
    </html>
  • So the first column spans three table columns, then there's columns 4 and 5?

    Code

    <table>
      <tbody> <!-- optional -->
        <tr>
          <td colspan="3"><div style='color: red;' >data that spans three cols</div></td>
          <td>data r1 c4</td>
          <td>data r1 c5</td>
        </tr>
        <tr>
          <td>data r2 c1</td>
          <td>data r2 c2</td>
          <td>data r2 c3</td>
          <td>data r2 c4</td>
          <td>data r2 c5</td>
        </tr>
      </tbody>
    </table>


    The div used there is probably not the right tag, since it is a block-level tag. A span is probably the better (more correct) choice.

    If, on the other hand, you are trying to get the second and third cells to also be red, then you have two options. Use a class on each of the td tags and define the class' style in a style sheet, or use a style attribute on each of the td tags. In both cases, neither a div nor a span are needed (unless you want to style only a portion of each cell's contents. Something like this:

    Code

    <table>
      <tbody> <!-- optional -->
        <tr>
          <td style='color: red;' >data</td>
          <td style='color: red;' >data r1 c2</td>
          <td style='color: red;' >data r1 c3</td>
        </tr>
      </tbody>
    </table>




    edited by: rmburkhead, datetimebrief

    --
    - Robert

    Ohloh profile for Robert Burkhead

    Stack Overflow profile for RobertB at Stack Overflow, Q&A for professional and enthusiast programmers
  • Quote

    So the first column spans three table columns, then there's columns 4 and 5?

    no - this is more advanced than that. Think of a calendar (seven columns - days) and event that spans three days. I want the div to cover the span, but there will also be events that are only in the one day.
  • use a span tag instead of a div.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • craigh

    Think of a calendar (seven columns - days) and event that spans three days. I want the div to cover the span, but there will also be events that are only in the one day.


    Ahh... that's clearer. The only way I can think of to do it with a div is to play with combination of z-order and positioning. You'd have the table at a lower z order, and then position the div on top of it at a higher z order. Your mileage will vary wildly with different browser brands and versions.

    Another way to attack it is to split up one logical calendar "row" (continuing your example) into several structural table rows. You can style them appropriately to appear to the eye as one row on the calendar, but they'd be made up of several tr's behind the scenes. In this case, colspan with td's will work (without necessarily needing any span's or div's). You should be able to control the number of physical rows per logical (or visual) rows programmaticaly, and with a little bit of up-front calculation you should be able to make all the logical rows the same height (if that's desired) if you know the max number of events in any given day (including events that span into or across a day).

    --
    - Robert

    Ohloh profile for Robert Burkhead

    Stack Overflow profile for RobertB at Stack Overflow, Q&A for professional and enthusiast programmers
  • The biggest issue with either of those, Robert, would be if the span crosses rows, say starts on Friday and ends on the following Tuesday. I'd say give multi day events a class="multiday" and apply it to the text in the TD. You already have to figure out how to handle an event that spans multiple weeks anyway. Or use your own version of a div based grid instead of a table.



    edited by: HalbrookTech, datetimebrief

    --
    Home Page | Find on Facebook | Follow on Twitter
  • HalbrookTech

    The biggest issue with either of those, ... would be if the span crosses rows, say starts on Friday and ends on the following Tuesday.


    I can't think of any technique that auto-magically solves that issue an still gives you some semblance of control over the visual layout of the data items. That's a problem that has to be solved programaticaly until CSS and the browsers provide much more complex layout managers.

    --
    - Robert

    Ohloh profile for Robert Burkhead

    Stack Overflow profile for RobertB at Stack Overflow, Q&A for professional and enthusiast programmers
  • He's already got the basis of the idea in his head, just use a span for the muliday event instead of a div. Even with Divs he'd have to contend with a multi day event that wraps week. So it's just a matter of figuring out if the event goes to the next week, and modifying the number of days in the table coding. (IF the event is from Friday to Sunday, and Sunday is Day 1, then there should be a 2 col tablespan and a 1 col span, then span the info in the blocks to style it right.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • HalbrookTech

    just use a span for the multiday event instead of a div. ... (IF the event is from Friday to Sunday, and Sunday is Day 1, then there should be a 2 col tablespan and a 1 col span, then span the info in the blocks to style it right.

    You've lost me. Are you talking about a span tag, or are you talking about a colspan attribute on a td tag?

    --
    - Robert

    Ohloh profile for Robert Burkhead

    Stack Overflow profile for RobertB at Stack Overflow, Q&A for professional and enthusiast programmers
  • Both actually, based on how Craig presented it.

    Let's say we're dealing with a 5 day event running Monday to Friday, Sunday is the first day of the week, So the code for that particular event would be...

    Code

    <tr>
     <td>Normal empty day or event display</td>
     <td colspan="5"><span class="multidayevent>Event Title</span></td>
     <td>Normal empty day or event display</td>
    </tr>

    However as I type this, this isn't the ideal way to handle the multi-day event thing really. Since my currently most complex implementation of PostCalendar is for my Church's site, multiple groups in play. Let's say there's a week long youth conference that runs from Monday to Friday. You run in to a problem with this implementation because You create a 5 col span, but what about Wednesday when we have evening events to display weekly, Monday we host a special guest speaker for an event, and Friday the adult choir has a party on friday, then we totally mess up the appearance. things by having a 5 col span. I think the best thing to do, is to use a span on the title of the event to define it as a Multi day event. Then you still have two issues to deal with, one fairly easy to hand, the other more difficult. The easier of the two is making sure that multi day events are always first, and in the same order (so that if you've gotta Monday to Friday event and a Tuesday to Thursday event the same week, the 5 day event comes first and the 3 day one shows second to be visually coherent. The second is related to overlap, where one is Mon-Thurs and the other is Wed-Fri.. Then you end up with a display issue because if you put Monday's event first then Friday will be aligned with the earlier event, if you put the later one first, then you end up with Mon & Tues out of alignment with the rest of that event. Not sure the best way to handle that one, I'm sure there's CSS magic that can be used, but you have to figure out a way to detect what the absolute position the events and when they don't overlap, use the absolute position on the event. I know it CAN be done, just not how. Could be a case where an alternative method is called for using lists or a div based display rather than a table. A case can be made for using lists for the displayed events, and divs for each day as being used so you'd have a simplified version of a fluid grid (classes 1day 2 day 3day etc). But then you run in to the problem of week wrap and stacked events, both of which could conceivably be solved with some fancy math work in the code and div trickery, I can explain in plain english, but don't know how complex it will be to work out. In plain English what I am thinking is:

    Each week has 2 divs, Multi Day and One time, this takes care of putting single day events in the same area as multiday events.
    Then for displaying, check to see if the week as any multiday events. If yes, create the multi div. Each event would have it's own div, using the grid system (mevent1, mevent 2 etc) That way you can make sure multi day events line up with each other if there's the above overlap. For each day the event doesn't happen, put a blank day (so you get the Date and a a visible date separator with a border) For the days that are a part of the event, you determine how many of the days are in the current week, if any are in the next week, and do a multi day span to make the event day a single bar. So if the multi day event is tues-fri, and First day is Sunday. You end up with div class=1 div class=1 div class=4 div class=1 Which adds up to 7 days. If the event is Friday to Sunday you'd have div class=5 and div class=2 this week, then a div class=1 and div class=6. .
    keep the events in the same order each week they happen in. If a week has no multi-day events, with Smarty if statments you don't even have to render the main multi week div at all.

    Probably a bit complex to work out, hardest case I'd think would be an event that covers part of two weeks. may even be possible to do in a table never really done much with styling tables to that degree, but I know it can be done with divs, because nesting in that nature is how most grid systems work in the firstplace.

    --
    Home Page | Find on Facebook | Follow on Twitter

This list is based on users active over the last 60 minutes.