I have some html as given in code below.
I am using display:table
and display:table-cell
for laying out the divs in a table-like manner without using html table
. This works fine except that the widths of left and right cells are much bigger than the width of their contents.
A demo for this question is at following URL: http://js.do/sun21170/87371
Question: What CSS I can use to make the left and right cells automatically resize to their contents? I do not want to specify the widths of these cells.
I tried to solve this problem by setting the center div width to 100% which did what I was after but then the margins of left and right divs are not respected. So may be there is a better solution that I am missing!
HTML Markup
<script></script>
<style>
#rgcmd {
width:100%;
display:table;
position:relative;
border:solid 1px green;
}
.leftCell {
margin-right: 5px;
height:100%;
display:table-cell;
vertical-align:middle;
border-right:solid 1px red;
}
.rightCell {
margin-left:
5px;height:100%;
display:table-cell;
vertical-align:middle;
border-left:solid 1px red;
text-align:right;
}
</style>
<div id="rgcmd">
<div class="leftCell"><a href="#" onclick="alert('Go Left');">Go Left</a></div>
<div style="display:table-cell; vertical-align:top;">
<span id="status">Your status is offline</span>
</div>
<div class="rightCell"><a href="#" onclick="alert('Go Right');">Go Right</a></div>
</div>