how to adjust width of first cell of a table using CSS - css

I have a html structure as shown below.
<style>
.divcontainer
{
width:100%
}
.left_menu {
background: none repeat scroll 0 0 #333333;
border-radius: 5px 5px 5px 5px;
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
font-weight: bold;
padding: 5px;
width: 200px;
}
</style>
<div class="divcontainer">
<table width="100%">
<tr>
<td valign="top">
<div class="left_menu">
1
</div>
</td>
<td>
<div>
2</div>
</td>
</tr>
</table>
</div>
I need to create a structure as in the picture below
but i dont want to apply styles to TD. The width of td should be adjusted through the classes applied to the child div. In short my first td should occupied 25% of tr and the second should occupy the remaining 75%.Can anyone throw some light on how to do this?

You may set for second td a hudge width. It will then take max-width avalaible and first td will shrink to its content.
http://jsfiddle.net/f5q3E/
basicly here you need to set :
td {
background:red;
}
td+td {
width:100%;
background:blue;
}
First td will adjust to its content and sized div if any , second td will use remaining space.

There are so many ways to handle this - here is one - FIDDLE - and it's not better than any other approach.
I'm just a little confused about the coloring of your tds and the coloring of the divs that goes into them.
If you can tell us the goals of what you want to do maybe we can make some other suggestions, such as not using table for layout - divs? floated divs?
CSS
table tr td:nth-child(1) {
width: 25%;
background-color: red;
}
table tr td:nth-child(2) {
width: 75%;
background-color: blue;
color: white;
}

Related

how to make responsive table with bootstrap

need help to make table responsive.
On this size everything is ok:
but when screen size is reduced im getting smth like this:
table is displayed on col-md-7:
<div class="row">
<div class="col-md-7">
<div class="ritekhela-fancy-title-two">
<h2>Turnyrinė lentelė</h2>
</div>
<div class="rs-point-table sec-spacer">
<div class="tab-content">
<table>
<tr>
<td>Vieta</td>
<td class="team-name">Komanda</td>
<td>Sužaista</td>
<td>Perg.</td>
<td>Lyg.</td>
<td>Laim.</td>
<td>Įm.</td>
<td>Pr.</td>
<td>+/-</td>
<td>Taškai</td>
</tr>
<tr>
<td>01</td>
<td class="team-name">Banani FC</td>
<td>60</td>
<td>35</td>
<td>08</td>
<td>16</td>
<td>02</td>
<td>04</td>
<td>11</td>
<td>95</td>
</tr>
</table>
</div>
</div>
</div>
EDITED:
If i trying to add max and min width, marked place is reducing too much:
I've had a look into your second example.
the troubling part is obviously your title bar, whose elements are inside the class ritekhela-fancy-title-two
And you have a wrapping div around this class, named row, this div needs to get set to adapt its width to the nested content.
Since fit-content is experimental and not available at all browsers, you'll need set width to auto and make it behave as an inline block
Then you must set the width of your ritekhela-fancy-title-two class to auto and remove the float:left, or set it to float:none and it will neither overflow on larger screens or not expand to the width of table on smaller screens.
that's it, check the fiddle with above changes implemented
these are the two css styles which were changed/added:
.row {
width: fit-content; /*works with Chrome, but not with FF*/
width: auto;
display: inline-block;
}
.ritekhela-fancy-title-two {
float: none;
width: auto;
padding: 12px 20px 12px 60px;
border-top: 7px solid;
background: url(/css/images/transparent-pattren.png);
position: relative;
margin-top: 30px;
background-color: #6c757d;
}
edit: as above changes also affect the lower title bars, which is easy to correct, adding some height to the second row:
.ec-nextmatch {
border: 1px solid #f3f3f3;
border-top: none;
background-color: #fff;
margin-bottom: 60px;
float:none;
height:90px;
width:auto;
}
also remove .ec-nextmatch from this css, so it looks now:
.ec-team-matches, .ec-match-countdown, .ec-match-countdown .countdown-row, .ec-ticket-button {
float: left;
width: 100%;
}
If you want to avoid the hassle of reducing font sizes, table cells widths, etc. I would recommend using the Bootstrap responsive table utility, basically makes the table scroll horizontally. Can be achieved like so...
...
<div class="tab-content table-responsive">
<table class="table">
...
</table>
</div>
...

same length columns (with variable rows)?

I've searched around but can't find what I'm looking for. I'm attempting to do something rather specific, but I may just need direction in applying a more general solution.
I would like to create two columns, the left one being split into two rows, for a total of 3 internal divs. (Perhaps they shouldn't be divs; you'll let me know.) The width of both columns is predetermined, but the height of the 3 divs isn't. A little picture:
|---|
|A| |
|-|C|
|B| |
|---|
I would like the following conditions to be met:
height(A)+height(B)==height(C);
height(A)==height(B)
I created a jsfiddle, with A green, B yellow and C red; the background of the whole thing is blue. If the jsfiddle were to fulfil my requirements, the blue would always be hidden:
http://jsfiddle.net/266p3/1/
Can someone give me a hand or point me in the right direction, please?
You do not have to use a table for this. By positioning the parent #wrapper to relative and setting a height (could be 100% if your html and body is set to 100%, or a pixel value as I have in the fiddle), you can then position the columns and rows relative to the parent container. This allows you to set the rows' heights to 50%.
Here's a fiddle: http://jsfiddle.net/266p3/7/
The updated CSS:
#wrapper{
position: relative;
height: 300px;
}
#col1{
background-color: blue;
float: left;
width: 50%;
height: 100%;
}
#row1{
background-color: green;
height: 50%;
}
#row2{
position: relative;
background-color: yellow;
height: 50%;
}
#col2{
background-color: red;
float: left;
width: 50%;
height: 100%;
}
There is probably a better way to organize the CSS and even the markup for that matter, but I just added on/modified your existing fiddle.
LIVE EXAMPLE
<table>
<tr><td>A</td><td rowspan="2">C</td></tr>
<tr><td>B</td></tr>
</table>
table{
height:300px;
}
table td{
background:#eee;
padding:10px;
}
table td:first-child{
height:50%;
background:#eee;
padding:10px;
}
Using a <table> would be very usefull in this situation..
Following html can solve the problem
<table>
<tr class='equalRow'>
<td>row1 col1</td>
<td rowspan='3'>common col</td>
</tr>
<tr class='equalRow'>
<td>row2 col1</td>
</tr>
</table>
Check the Fiddle for demo

Div content alignment

I have a dynamically generated div.
I have to add a dynamically generated HTML table on it.
The problem is when I'm add the table, it display as left aligned.
But the div is center aligned for text contents.
Assuming you have your table as a fixed width element, you can set margin-left/right to auto to center a block element in it's container. (Fiddle here: http://jsfiddle.net/SWakJ/)
HTML
<div id="div1">
<table id="tab">
<tr>
<td>test</td>
</tr>
</table>
</div>
CSS
#tab {
border:solid 1px black;
width: 200px;
height: 100px;
margin:2px auto;
}
You may try to add some css to your outer div.
I actually wrote a similar answer here:
Position this div in the center of it's container?
Give your code or just go quick to your code and check this. Put a div above table and set text-align= center. or if your table is in any td then assign text-align:center.
Also you can put tag and put table between it.
If you want to just center the table column than also provide text-align:center
I dont know about your code but as per problem this could help you.
function makeTable() {
row=new Array();
cell=new Array();
row_num=12; //edit this value to suit
cell_num=12; //edit this value to suit
tab=document.createElement('table');
tab.setAttribute('id','newtable');
tbo=document.createElement('tbody');
for(c=0;c<row_num;c++){
row[c]=document.createElement('tr');
for(k=0;k<cell_num;k++) {
cell[k]=document.createElement('td');
cont=document.createTextNode((c+1)*(k+1))
cell[k].appendChild(cont);
row[c].appendChild(cell[k]);
}
tbo.appendChild(row[c]);
}
tab.appendChild(tbo);
document.getElementById('mytable').appendChild(tab);
}
the you can set allignment through CSS as below:
#newtable{
border:2px solid #999;
font-family:verdana,arial,helvetica,sans-serif;
font-size:18px;
margin:auto;
}
#newtable td{
width:50px;
line-height:50px;
border:1px solid #000;
text-align:center;
}
or see this link "http://www.webmasterworld.com/javascript/3614377.htm"
You can use like this
<div id="div1">
<table id="tab">
<tr>
<td>test</td>
</tr>
</table>
</div>
CSS
#div1
{
width:500px;
text-align:center;
}
#tab {
border:solid 1px black;
width: 200px;
height: 100px;
margin:2px auto;
}
#tab td
{
/* width: 200px;
text-align:center;*/
}
Running Demo Jsfiddle

Cannot get table to vertical-align in the middle

I have the following code, and my table(the table contains the two text lines next to the image) just does not want to align vertically in the middle of the div. What to do?
Please note that I used a table for my two text lines(laminin beauty and perfectly put together), since they have different styles and I want them justified, so I put align= center on their td tags... (justify text property only works when text is in the same tag...) . My website: http://lamininbeauty.co.za/index2.html
HTML:
<div id="header">
<img class="massage" src="images/massage.png" border="none" alt="face massage" />
<div class="headerDiv">
<table margin="0" padding="0">
<tr><td align="center" class="headerText1">Laminin Beauty</td></tr>
<tr><td align="center" class="headerText2">"Perfectly put together"</td></tr>
</table>
</div>
</div>
CSS:
#header{
width: 100%;
height: 100px;
background: #000000;
}
#header img{
margin-left: 50px;
vertical-align: middle;
display: inline-block;
float: left;
}
#header div.headerDiv{
display: table-cell;
margin-left: 80px;
vertical-align: middle;
}
.headerText1{
color: #fff;
font-family: impact;
font-size: 32px;
text-decoration: underline;
}
.headerText2{
color: #ee00ee;
font-family: century gothic;
font-size: 24px;
}
Thank You!
Make the div containing the table have a fixed height of 100px, since that's the height of your Wrapper div. Then, make the height of the table 100%. Here's a screenshot of what it did for me, not entirely sure if this is what you want: http://screencast.com/t/cbwcBbAoM3cZ
If the main header div will always be 100px high, remove the display property from the headerDiv element and add margin-top: 12px;.
Also it should have display: inline-block added and possibly the left margin decreased to compensate. The display property alteration will make it push off the image, not the left side of the document, as it should.
Also, if you want the two pieces of text to be aligned on the left, add text-align: left to the table tag.

Align contents of DIV always on one line

I have the following :
HTML
<th class="sort">
<div>
<div class="sort"></div>Last Name
</div>
</th>
css:
table.tablesorter thead th.sort
{
padding:0;
}
table.tablesorter thead th div.sort
{
margin:0;
width:15px;
height:30px;
float:left;
background: url("/Content/images/admin/sort.png") no-repeat;
background-position: 0px center;
cursor:pointer;
}
table.tablesorter thead tr th.sort a
{
cursor:pointer;
color:inherit;
vertical-align:middle;
float: left;
padding-top: 7px;
}
I want to display inner and inside vertically aligned middle and always on ONE line so that when a browser window is resized (small) it will not break and will not more underneath inner (which is what is happening now).
thanks
use the "display inline" command...
<div style="display:inline;float left;">First name</div>
<div style="display:inline;float right;">Last name</div>
Its not clear to me what "inner" and "inside" youre referring to (you mught want to update and elaborate a bit, as well as post the complete markup for the table) but it sounds like you basically want everything in the th to be in one continuous line regardless of avialable space. You can turn off the text from wrapping with whitespace: nowrap;. However your content is going to overflow the th because thats how table cells work, so you need to set overflow: hidden on something that wraps the text. Unless yo need more than one elemment inside the cells you dont need the float.
The markup might look like this:
<thead>
<th><div class="clip sort">First Name</th>
<th><div class="clip sort">Last Name</th>
</thead>
Whith the css like so:
.clip {width: 100%; overflow: hidden; whitespace: nowrap;}
th {vertical-align: middle; height: 30px;}

Resources