How do I get Html Table to respect margins when its width is set to 100%?
Tags: html,css
Problem :
I'm struggling to get an Html Table to fill the width of a container, and respect margins without overflowing.
This sample (see https://jsfiddle.net/v6o12u9o/) sets a table's width to 100%, but because of the margin, the table overflows its parent's borders. How do I fix this?
Html:
<div style="border: 1px solid red; margin:10px;">
<table border=1>
<tr>
<td>
First cell.
</td>
<td>
Second cell.
</td>
</tr>
</table>
</div>
Css:
table {
margin: 20px;
background-color: yellow;
width:100%;
}
td {
width: 50%;
}
Some other things I've tried:
- Setting margin-right to 40px. Margin-right is ignored.
- Setting padding-right instead. This makes the cells smaller, but the table stays at 100% width.
- Setting table's display to "block". This makes the table the correct size, but then cells are too small (I tried setting "block" on the cells, no luck)
Solution :
If you want table to be 100% you can do this and compensate for the margins on left and right by moving that to padding on the parent:
CSS:
.tableElement {
margin: 20px auto;
background-color: yellow;
width: 100%;
}
.tableCell {
width: 50%;
}
.tableWrapper {
border: 1px solid red;
margin: 10px;
padding: 0 20px;
}
HTML:
<div class="tableWrapper">
<table class="tableElement" border="1">
<tr>
<td class="tableCell">First cell.</td>
<td>Second cell.</td>
</tr>
</table>
</div>
Fiddle: https://jsfiddle.net/v6o12u9o/5/
CSS Howto..
You can change the display property for your form form { display:inline-block; } The demo http://jsfiddle.net/TT7BC/3/ Remember it will display side by side if they can fit into his parent...
css z-index is probably the solution you're after
If you wish to keep your floats you could use a clearfix on the container: Working demo #action:after { content: ""; display: table; clear: both; } If you wish to...
If I understand your question correctly <strike> tag could be used. The <strike> tag is not supported in HTML5. For HTML5 use <del> tag instead. If you meant horizontal lines...
Use jQuery clone() method to copy the menu and then change the css as per your needs.
May I suggest a little trick, css att(), to use a text in a pseudo and at the same time have it accessible in the DOM h4:after { content: attr(data-txt);...
<edit> to get li active overflowing over top of its parent, you need to set negative margins too : DEMO updated CSS from original answer (at bottom): .menu-holder{ height: 30px;...
Remove the second width: 50% and add overflow: auto.
For the text to be right-aligned, in you configuration positioning it absolutely based on <li> is the easiest way: .resultDiv { text-align: right; position: absolute; right: 0; } For that...
Bind the input component to the view via binding attribute. It'll become available as an UIInput component reference in EL, so that you can use UIInput#isValid() in styleClass attribute. <h:outputLabel...
Try playing with line-height: <html> <head> <title></title> </head> <body style="font-size:100%; margin:0; padding:0;"> <p style="border:1px solid red; font-size:10em; margin:0; line-height:0.5em"> test</p> </body> </html> ...
You cannot prevent it, and you probably shouldn't anyway. Despite the fact that IE and other browsers differ in the way that they report the value of <textarea> elements, all...
The css styles for these arrows are the following ones: .mm-prev:before, .mm-next:after, .mm-arrow:after { content: ''; border: 2px solid transparent; display: inline-block; width: 8px; height: 8px; margin: auto; position: absolute;...
.parent { display: table; table-layout: fixed; } .child { display:table-cell; vertical-align:middle; text-align:center; } table-layout: fixed prevents breaking the functionality of the col-* classes....
If I understood correctly. You can try if($('.content-visible').is(':visible')) { $('.content-hidden').show().appendTo('.content-visible') } DEMO References appendTo(). show(). ...
For that You can scan user Agent and find out which browser, its version. Including the OS for OS specific styles You can use various CSS Hacks for specific browser...
Here's a pure CSS option: td.cv-table-panel-element:not([align="center"]) This selector uses the :not functional notation and an attribute selector. Here's an example: /* td elements are red */ .cv-table-panel-element { background-color: red;}...
$("#box").append("<div style='background-color:" + randColor + "; height:10px; width:10px; float:left;'></div>"); You missed the closing "....
This can be done using CSS, as I showed in this answer. And here is the code part which make it happen. html, body { height:100%; margin:0; padding:0; } .chat-window{...
You absolutely position abs in the body tag. For reasons I won't go into body is the height of the window, not of the content. So when you set it...
Maybe you are after some of these methods: Method 1 body { margin: 0; background-color:#F8F8F8; } #header { background-color:#FFFFFF; height: 70px; } <body> <div id="header"> <h1>Welcome</h1> </div> <div> <h2>About Us</h2>...
You can simply add this line to bootstrap.min.css file, and this rule will work fine!
This is code is in regards to the link: http://postimg.org/image/no7gsn23z/ <!DOCTYPE html> <html> <head> <title></title> </head> <body> <style type="text/css"> body { background-color: #ddd; } .navBar { margin-left: 25px; margin-right: 25px;...
z-index will work but it only works on positioned elements. So you need to position your dropdown menus either by declaring the position property to be either absolute, fixed or...
One way is to use :after and :before to create elements with the color you want #header-Container:before, #header-Container:after{ content:''; position:absolute; z-index:-1; width:50%; top:0; bottom:0; } #header-Container:before{left:0;background-color:yellow;} #header-Container:after{right:0;background-color:green;} Demo at...
jQuery UI supplies a neat callback for when it's done creating the element. That's where you'd want to do the color change. $( ".selector" ).button({ create: function(event, ui) { $('.selector').css({'background-color':...
Try this. Check support calc() for u browser http://caniuse.com/#search=calc .input_one { position: absolute; left: 5px; right: 61%; width: calc(100% - 5px - 61%); box-sizing: border-box; } .input_two { position: absolute;...
You may need this: .image_carousel { margin-top: 20px; box-shadow: 0px 0px 3px #000; } .image_carousel img{ float:left; width: 60px; } .image_carousel p{ float:left; } .clear { clear: both; } <div...
Remove this line from your CSS: #wrapper { position: relative; } The map pan & zoom controls are in the upper left so be careful with placement or disable those...
Just use element:nth-child(1){ /*whatever*/ } or element:first-child { /*whatever*/ } You can also use element:nth-of-type(1){ /*whatever*/ }...