How can I fully fill the parent div with its child elements? - html

I have a div called #menu which is 800px wide. Inside of it, I have 8 navigation links. The elements in it should be as long as possible and should all be of the same width, but they should, together, fill the parent div on a single row (i.e. without wrapping).
Between each element, there should be a 1px border (or perhaps a 1px side-margin). All links, except the current page link (whichever link #current is applied to) should have a 1px solid #505050 bottom border. While the current page link should not have a visible bottom border (so that the navigation tab "merges" with the content div).
My current code does almost what I want already, but it's missing the border/margin between the links... If I add borders/margins to the sides, obviously, the current 12.5% width (see CSS code below) becomes inaccurate, and I can't fine-tune it so that it does fill the #menu div cross-browser (either the elements will overflow the #menu div, or they won't fill it - in at least one browser).
CSS:
#menu {
border:1px solid #505050;
border-bottom:none;
width:800px;
}
#menu a {
display:inline-block;
outline:none;
text-align:center;
width:12.5%;
padding-top:12px;
padding-bottom:10px;
background-image:url(/img/menu.gif);
border-bottom:1px solid #505050;
color:#D9D9D9;
font-weight:bold;
font-size:13px;
font-family:Verdana, sans-serif;
text-shadow:1px 1px #505050;
}
#menu #current {
background-image:url(/img/menu_current.gif);
color:#505050 !important;
border-bottom-color:#D9D9D9;
text-shadow:none;
}
HTML:
<div id="menu">
Link 1
Link 2
Link 3
Link 4
Link 5
Link 6
Link 7
Link 8
</div>
Two requirements:
The solution should work in IE6 and later IE versions, as well as recent versions of Firefox, Chrome, Safari and Opera
No use of JavaScript, please
It's a big plus if:
The solution works so that links can be added without having to re-adjust the width for the elements
You may of course rewrite the CSS/HTML completely. No need to re-use any of the code above, I'm just showing my own approach. Also, I am aware that the text-shadow rule isn't supported in IE6, but it isn't a requirement.
How it currently looks
The expected result

hi i think u want to this Demo
add some css in you stylesheet as like this
#menu{
font-size:0;
}
#menu a {
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
#menu a + a{
border-left:solid 2px black; // depent your design .
}
Live demo
Change color or border according your design .

Another way is to use a html table instead of divs.
#menu {
width:800px;
border-collapse:collapse;
}
#menu td.other {
border:1px solid black;
}
td a {
display:inline-block;
outline:none;
text-align:center;
width:100%;
padding-top:12px;
padding-bottom:10px;
background-image:url(/img/menu.gif);
color:#D9D9D9;
font-weight:bold;
font-size:13px;
font-family:Verdana, sans-serif;
text-shadow:1px 1px #505050;
}
#menu#current {
background-image:url(/img/menu_current.gif);
color:#505050 !important;
border-bottom-color:#D9D9D9;
text-shadow:none;
border-left:1px solid black;
border-right:1px solid black;
border-top:1px solid black;
border-bottom:1px solid #D9D9D9;
}
<table id="menu" border="0">
<tr>
<td id="current">Link 1</td>
<td class="other">Link 2</td>
<td class="other">Link 2</td>
<td class="other">Link 2</td>
<td class="other">Link 2</td>
<td class="other">Link 2</td>
<td class="other">Link 2</td>
<td class="other">Link 2</td>
</tr>

Related

Why does my table not scale within the div?

I have a very simple webpage for homework. The body just consists of various sections div /divbr. The effect is various boxes for each part. Most of my students don't have a computer, they only have a mobile phone. So I am trying to make the webpage display better on mobile phones. I put:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
in the header.
I set all divs to width:95%;
Everything displays nicely on my phone now. The text is a good size, everything is within the confines of the mobile phone screen, no need to magnify with 2 fingers.
EXCEPT my table.
.div-table
{
width:95%;
border:3px;
border-style:solid;
border-color:#FF0000;
text-align:center;
background-color:#32d140;
}
table
{
margin:0 auto;
width:90%;
text-align:center;
background-color:whitesmoke;
border-collapse: separate;
border: 2px solid black;
}
table td {
/*border: 2px solid black;*/
border-style:dotted;
border-width:3px;
border-collapse:separate;
padding: 10px;
}
<div class="div-table">
<p>
<table>
<tr> <td>A watches</td> <td>B cinema</td> <td>C weird</td> <td>D doesn't</td> <td>E like</td> </tr>
<tr> <td>F games</td> <td>G talking</td> <td>H guy</td> <td>I unusual</td> <td>J teaches</td> </tr>
</table>
</p>
</div>
The table spills over its div. You can scroll right a bit to see the last columns. The table was 2 rows of 5 cells. I changed it to 5 rows of 2 cells to get around this now, but I prefer 2 rows 5 columns.
Why does my table not shrink to fit its div? Could you please help me tweak the css to shrink the table?
Basically your table is overflowing, to make it neat and clean you can make it responsive. You can either make the table responsive by adding a horizontal scroll, so users can scroll and see the content. You just have to add following styles in media query, You can see it here
#media (max-width: 767px){
.div-table{
overflow-x: auto;
}
.div-table table{
width: 100%;
}
}
Or, Other option is stacking it vertically which is bit more user friendly, you can see it here
I'm not sure you can confine the table within the div and successfully display it at every resolution.
An alternative solution would be to allow the table to overflow, thereby making it scrollable:
Adding overflow-x: auto; to div-table should work for you:
CSS
.div-table {
width:95%;
border:3px;
border-style:solid;
border-color:#FF0000;
text-align:center;
background-color:#32d140;
overflow-x:auto;
}
.div-table {
width:95%;
border:3px;
border-style:solid;
border-color:#FF0000;
text-align:center;
background-color:#32d140;
overflow-x:auto;
}
table {
margin:0 auto;
width:90%;
text-align:center;
background-color:whitesmoke;
border-collapse: separate;
border: 2px solid black;
}
table td {
/*border: 2px solid black;*/
border-style:dotted;
border-width:3px;
border-collapse:separate;
padding: 10px;
}
<div class="div-table">
<p>
<table>
<tr> <td>A watches</td> <td>B cinema</td> <td>C weird</td> <td>D doesn't</td> <td>E like</td> </tr>
<tr> <td>F games</td> <td>G talking</td> <td>H guy</td> <td>I unusual</td> <td>J teaches</td> </tr>
</table>
</p>
</div>

Hide table header <th> existence fully and on hover display it

i want to hide <th> such a way that happens when we give display:none but if i use this property i can't display it on mouse hover.i placed an up arrow inside the th to point something on hovering the table;
** When my table is not in hovered state those th remain hidden but there remain blank space which i do not want.**
I have tried using like this margin-top:-555px; and on hover margin-top:0 but does not work.
i do not want the red mark area but hover state on given link is ok for me.
please help.
jsfiddle
<div class="existing_items">
<table cellspacing="0">
<th class="pointer"colspan="2"><span>^</span></th>
<tr><th class="" colspan="2">Title</th></tr>
<tr><td class="leftname">name</td><td>name</td></tr>
<tr><td class="leftname">type</td><td>type</td></tr>
</table>
</div>
.existing_items{
background-color:green;
}
.existing_items table td{
text-align:center;
border-top:1px solid #eaeaea;
}
table:hover th.pointer{
visibility:visible;
}
table th.pointer{
color:red;
visibility:hidden;
font-size:20px;
}
.leftname{
border-right:1px solid #eaeaea;
}
I add position:inherit; in your table:hover th.pointer and it works;
You can try here:
http://jsfiddle.net/gkiwi/t7eecbzp/
Or
.existing_items{
background-color:green;
}
.existing_items table td{
text-align:center;
border-top:1px solid #eaeaea;
}
table:hover th.pointer{
visibility:visible;
top:-10px;
left:20px;
position:inherit;
}
table th.pointer{
color:red;
visibility:hidden;
font-size:20px;
overflow:hidden;
position:absolute;
top:-20px;
}
.leftname{
border-right:1px solid #eaeaea;
}
<div class="existing_items">
<table cellspacing="0">
<th class="pointer"colspan="2"><span>^</span></th>
<tr><th class="" colspan="2">Title</th></tr>
<tr><td class="leftname">name</td><td>name</td></tr>
<tr><td class="leftname">type</td><td>type</td></tr>
</table>
</div>
I would suggest to not use an extra (useless) <th> for this purpose. You could instead use a pseudo-element on your title <th>, as they seems highly related. See my example below:
.existing_items{
background-color:green;
}
.existing_items table td{
text-align:center;
border-top:1px solid #eaeaea;
}
table th.with-arrow {
position: relative;
}
table:hover th.with-arrow:after{
content: "^";
position: absolute;
left: 10px;
top: 0;
color: red;
font-size:20px;
}
.leftname{
border-right:1px solid #eaeaea;
}
<div class="existing_items">
<table cellspacing="0">
<tr><th class="with-arrow" colspan="2">Title</th></tr>
<tr><td class="leftname">name</td><td>name</td></tr>
<tr><td class="leftname">type</td><td>type</td></tr>
</table>
</div>

Two TD's next to eachother, one is taking up 100% width?

I've got two td's next to eachother (in a html5 email) and one is being pushed outside the table? I'm not sure why! I'm looking to have two columns next to eachother for text.
Thanks!
<tr>
<td bgcolor="#fdfcf8" style="padding:10px; padding-top:0; border-top: 0px solid #fdfcf8; font-family:arial, sans-serif; border-left:1px solid #fdfcf8; border-right:1px solid #fdfcf8; border-bottom:1px solid #fdfcf8;color: #003F6B;">hehe
</td>
<td bgcolor="#fdfcf8" style="padding:10px; padding-top:0; border-top: 0px solid #fdfcf8; font-family:arial, sans-serif; border-left:1px solid #fdfcf8; border-right:1px solid #fdfcf8; border-bottom:1px solid #fdfcf8;color: #003F6B;">hehe
</td>
</tr>
It's impossible to tell from your example code - look in other rows above/below for wide content which is pushing the width of that column.
Content widths in one row will affect the width of cells in other rows that are part of the same table.

Table unwanted padding

Introduction
I have this portion of HTML:
<!DOCTYPE HTML>
[...]
<table class="inv">
<tr>
<td id="i_1"></td><td id="i_2"></td><td id="i_3"></td><td id="i_4"></td><td id="i_5"></td>
<td class="dt" rowspan="5">
<div style="height:460px;position:relative">
<div class="st msg"></div>
<img src="content/images/site/inv.png"><br>
<a id="nm">USER INVENTORY</a><br>
<span class="desc">Contain tradable items of the user, click on an item on the left.</span><br>
<div style="text-align:right;padding-top:15px" class="bts"></div>
</div>
<div id="bot" style="display:none"><span class="bt i_b pp"><</span> <span class="bt i_b np">></span> <span style="font-weight:bold" id="pgs"></span></div>
</td>
</tr>
<tr>
<td id="i_6"></td><td id="i_7"></td><td id="i_8"></td><td id="i_9"></td><td id="i_10"></td>
</tr>
<tr>
<td id="i_11"></td><td id="i_12"></td><td id="i_13"></td><td id="i_14"></td><td id="i_15"></td>
</tr>
<tr>
<td id="i_16"></td><td id="i_17"></td><td id="i_18"></td><td id="i_19"></td><td id="i_20"></td>
</tr>
<tr>
<td id="i_21"></td><td id="i_22"></td><td id="i_23"></td><td id="i_24"></td><td id="i_25"></td>
</tr>
</table>
[...]
Linked to this CSS:
body{
font:16px Arial, Tahoma;
background-color:#222222;
margin:auto;
width:100%;
}
table{
border-collapse:collapse;
color:#FFF;
width:100%;
}
table td{
border:1px solid #FFFFFF;
vertical-align:top;
text-align:left;
padding:0px;
}
.inv{
table-layout:fixed;
}
.inv td:not(.dt){
width:100px;
height:100px;
text-align:center;
vertical-align:middle;
}
.inv td:not(.dt) > img{
max-width:100px;
max-height:100px;
cursor:pointer;
}
.inv td:not(.dt) > img:hover{
position:absolute;
z-index:100;
width:110px;
height:auto;
margin-top:-55px;
margin-left:-55px;
box-shadow:0px 0px 2px 1px #000000;
}
.inv .dt{
width:35%;
padding:10px;
}
.inv .dt img{
width:100%;
height:auto;
}
.inv .dt #desc{
font-size:12px;
color:#B8B6B4;
max-height:60px;
overflow:hidden;
display:inline-block;
}
.bt.i_b{
color:#FFFFFF;
}
.bt.i_b:hover{
background-color:#1B1B1B;
}
.det #nm{
font-size:20px;
font-weight:bold;
}
All the TDs inside the table are filled with images with this code:
for(var i = 0; i < ((inv.length < 25) ? inv.length : 25); i++){
$("td#i_"+(i + 1)).html('<img src="content/images/albums/'+inv[i]["song_id"]+'.png" title="'+inv[i]["song_name"]+'" id="'+(i+1)+'">');
}
The problem
Everything works fine, I get what I need (the table filled), but I get some sort of padding/margin at the bottom of every td with an image in it. Even if I have set width and height of the cells to 100px, in Firebug I can see a height of 103.5px, why this happens? I've read that it can be DOCTYPE causing it, but I can't remove it, id there an alternative solution?
Thanks.
"but I get some sort of padding/margin at the bottom of every td with an image in it."
Because img is an inline element, and thats why you see white space at the bottom, use this
table img {
display: block;
}
Now this will target all the images inside table element, so if you want the specific ones, use a class instead and assign like
table img.your_class {
display: block;
}
Demo
In the first image, I've used style="display: block;" and written inline, and not for the other two, so, you will see white space for the next two images but not the first one

CSS table custom width

I've been recently working on a simple web page. I would like to place almost all style info in the CSS file. The main layout of the page is a table. I looks like this:
<body>
<table class="glowna">
<tr>
<td colspan="2">...</td>
</tr>
<tr>
<td id="glowna_top" colspan="2">
<ul class="menu_gorne">
<li>..</li>
</ul>
</td>
</tr>
<tr>
<td id="glowna_menu_lewe">
<ul class="menu_lewe">
<li>...</li>
</ul>
</td>
<td id="glowna_main">
...
</td>
</tr>
</table>
</body>
and the CSS is like:
ul.menu_lewe, ul.menu_gorne {
display:block; list-style:none;margin:0;}
ul.menu_lewe {
width:200px; padding:2px 20px 2px 2px;
background-color:#9ce;border:none; vertical-align:top;}
ul.menu_lewe li {
border-bottom:1px solid #9ce; }
ul.menu_lewe a:link, ul a:visited {
display:block;width:176px;text-decoration:none;padding:7px;font- weight:bold;background-color:#27c;color:#def;border-right:10px solid #25b;border-left:5px solid #25b; }
ul.menu_lewe a:hover {
width:176px;background-color:#28e;color:#fff;border-right:20px solid #26d; }
ul.menu_gorne {
position:absolute; }
ul.menu_gorne li {
float:left;padding:2px 2px 2px 2px;background-color:#9ce;border:none; }
ul.menu_gorne a:link, ul a:visited {
text-decoration:none;display:block;width:200px;text-align:center;padding:5px 0;font-weight:bold;background-color:#27c;color:#def;border-top:10px solid #25b; }
ul.menu_gorne a:hover {
background-color:#28e;color:#fff;border-top:20px solid #26d; }
ul.lista_dostawcow {
width:800px;}
table.glowna {
background-color:#9ce;table-layout:fixed;width:1024px;margin-left:auto;margin-right:auto; }
td#glowna_top {
height:55px; vertical-align:top;}
td#glowna_main {
width:824px; text-align:left;}
td#glowna_menu_lewe {
width:200px;}
The problem is:
1. that even I set all the widths I still get table cells: "glowna_menu_lewe" and "glowna_main" divided 50%:50%. I want cell "glowna_menu_lewe" to be only 200px or sth near and the other one may fill the rest of space.
2. I would like to place list "menu_lewe" on top of its cell. Now it is vertically centered even that I set the verical-align attribute to top.
Sorry for posting so much code but I didn't know what may be causing the problem.
1 - Change that :
table.glowna {
background-color:#9ce;
table-layout:fixed;
width:1024px;
margin-left:auto;
margin-right:auto;
}
td#glowna_main {
width:824px;
text-align:left;
}
to this :
table.glowna {
background-color:#9ce;
width:1024px;
margin-left:auto;
margin-right:auto;
}
td#glowna_main {
text-align:left;
}
2- use valign="top" attribute to td tag instead of vertical-align:top;