0

Alright i am trying not to use HTML tables at all possible now a days. But i am using CSS tables but i am wondering if there is an equivalent of colspan in CSS tables.

I have this code

#fleetTable{display: table;width: 360px;margin: 0 auto;margin-top: 20px;font-size:.875em;float:left;}
    .fleetRow{display: table-row;}
    .fleetCell{display: table-cell;}

And this HTML

<div id="fleetTable">
    <div class="fleetRow textright">
        <div class="fleetCell">Headline</div> <!-- I would like this to span both columns below but be centered -->
    </div>
    <div class="fleetRow textright">
        <div class="fleetCel;">Cell1</div>
        <div class="fleetCell">Cell2</div>
    </div>
</div>  

What selector would you use here to accomplish this?

4
  • possible duplicate of table-cell - some kind of colspan? Commented Sep 13, 2013 at 20:51
  • 1
    Don't go overboard. It's totally OK to use tables to lay out tabular data. If what you have really is a table of data, then for heaven's sake use a table. Don't use tables to do page layout. Commented Sep 13, 2013 at 20:52
  • Yeah it was duplicate but google didnt give me that result @Quentin but thanks for the link that will work. Commented Sep 13, 2013 at 20:57
  • @IanMcLaird it is such a battle of where to use them and where to not. I was taught to use them way back when and then after learning real CSS layouts i have tried to stay away Commented Sep 13, 2013 at 20:58

1 Answer 1

1

I am making an obvious assumption that your header will be the first cell of the first row and which having the .fleetCell class. So you can select this first element using :first-child pseudo selector like this.

CSS

.fleetCell:first-child{
   text-align:center;
}

JS Fiddle Example

Sign up to request clarification or add additional context in comments.

1 Comment

Interesting way of doing this. Your assumption is correct, this needs support for IE7 and IE8 uggghhhh but thanks for the answer. I really need to use pseudo elements more for things like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.