1

In this Question, I followed w3d user answer but didn't get divs under the top divs.

CSS

div.demo {
    display:table;
    width:100%;
}
div.demo span {
    display:table-cell;
    text-align:center;
}
#under {
    width:100px;
    height:2px;
    background-color:blue;
}

HTML

<div class="demo">
    <span>Span 1</span>
    <span>Span 2</span>
    <span>Span 3</span>
</div>
<div class="demo">
    <span><div id='under'></div></span>
    <span><div id='under'></div></span>
    <span><div id='under'></div></span>
</div>

JSFiddle

Community
  • 1
  • 1
Lonely
  • 613
  • 3
  • 6
  • 14

2 Answers2

1

Try this css for under id

#under {
    width:100px;
    height:2px;
    background-color:blue;
    margin:0px auto; /*ADDED*/
}

Note: Use class instead of ID because you are using under id many times in single page.

Here is a valid HTML

<div class="demo">
    <div>Span 1</div>
    <div>Span 2</div>
    <div>Span 3</div>
</div>
<div class="demo">
    <div><span class="under"></span></div>
    <div><span class="under"></span></div>
    <div><span class="under"></span></div>
</div>

And here is CSS

div.demo {
    display:table;
    width:100%;
}
div.demo div {
    display:table-cell;
    text-align:center;
}
.under {
    width:100px;
    height:2px;
    background-color:blue;
    margin:0px auto;
    display:block;
}

DEMO HERE

Love Trivedi
  • 3,899
  • 3
  • 20
  • 26
1

I know you've already accepted an answer, but maybe consider using border-spacing and border-bottom?

JSFiddle

CSS

div.demo {
    border-spacing: 75px 0;
    display: table;
    width: 100%;
}

div.demo span {
    border-bottom: 2px solid blue;
    display: table-cell;
    text-align: center;
}

HTML

<div class="demo">
    <span>Span 1</span>
    <span>Span 2</span>
    <span>Span 3</span>
</div>
thgaskell
  • 12,772
  • 5
  • 32
  • 38