Reputation: 10390
I want to have a table
that has the layout of a left floated cell a right floated cell and the middle cell to stay in the center.
Problem: When the data inside the middle cell increases it moves more to the left thus decreasing the margin I want between the cells.
Code:
.settings {
/*background: #636969;*/
width: 750px;
margin: 0 auto;
padding: 1em;
}
.settings h4 {
padding: 1em 0;
letter-spacing: 1px;
border-bottom: 1px solid #cacece;
}
.settings table {
width: 100%;
font-size: 0.9em;
letter-spacing: 1px;
font-weight: 200;
}
.settings tr {
border-bottom: 1px solid #cacece;
}
.settings td {
padding: 0.5em 0;
}
.settings .edit {
text-align: right;
}
<!-- start settings -->
<div class='settings'>
<h4>Account Settings</h4>
<table class='options'>
<tr>
<td class='name username'>Name</td>
<td class='value'>Robert Rocha</td>
<td class='edit'><a href='#'>Edit</a>
</td>
</tr>
<tr>
<td class='name email'>Email</td>
<td class='value'>[email protected]</td>
<td class='edit'><a href='#'>Edit</a>
</td>
</tr>
<tr>
<td class='name pword' colspan='2'>Password</td>
<td class='edit'><a href='#'>Edit</a>
</td>
</tr>
</table>
</div>
<!-- end settings -->
Upvotes: 1
Views: 136
Reputation: 1816
Use
.settings table{table-layout:fixed;}
or You can use width of each cell in percentages like
.settings td{word-wrap: break-word;}
td:first-child{width:30%;}
td:nth-child(2){width:40%;}
td:last-child{width:30%;}
Check Updated Fiddle
Upvotes: 0
Reputation: 3907
You've already done it for your edit column by doing so:
.settings .edit {
text-align: right;
}
This puts the content in your edit column straight to the right hand side. What you need to do is just to add the same rule for your other columns, obviously replacing right
through left
and center
. That being said your styling would look somehow like this:
.settings .name {
text-align: left;
}
.settings .value {
text-align: center;
}
.settings .edit {
text-align: right;
}
A live example can be seen here.
Upvotes: 0
Reputation: 67776
you can set a fixed width for the first column:
.name { width: 100px; }
see here: https://jsfiddle.net/dojprwzL/
Upvotes: 0
Reputation: 60563
simply add table-layout:fixed
to your table
.settings {
/*background: #636969;*/
width: 750px;
margin: 0 auto;
padding: 1em;
}
.settings h4 {
padding: 1em 0;
letter-spacing: 1px;
border-bottom: 1px solid #cacece;
}
.settings table {
width: 100%;
font-size: 0.9em;
letter-spacing: 1px;
font-weight: 200;
table-layout: fixed;
}
.settings tr {
border-bottom: 1px solid #cacece;
}
.settings td {
padding: 0.5em 0;
}
.settings .edit {
text-align: right;
}
<div class='settings'>
<h4>Account Settings</h4>
<table class='options'>
<tr>
<td class='name username'>Name</td>
<td class='value'>Robert Rocha</td>
<td class='edit'><a href='#'>Edit</a>
</td>
</tr>
<tr>
<td class='name email'>Email</td>
<td class='value'>[email protected]</td>
<td class='edit'><a href='#'>Edit</a>
</td>
</tr>
<tr>
<td class='name pword' colspan='2'>Password</td>
<td class='edit'><a href='#'>Edit</a>
</td>
</tr>
</table>
</div>
Upvotes: 1