What is causing this random white space? - html

I ended up setting the display properties of some div's in one of my designs to table/table-cell respectively to take advantage of the vertical-align text support. However, I now have some white-space that I'm struggling to make sense of.
My code (JsFiddle: http://jsfiddle.net/p8zw2/):
HTML
<div class="container">
<p>Test</p>
<div class="mytable">
<div class="tablecell">test</div>
<div class="tablecell">test</div>
<div class="tablecell">test</div>
</div>
<p>Test</p> </div>
</div>
CSS
.container { width: 100%; background-color: #ff0000; }
.mytable { display: table; background-color: #4d4d4d; width: 94%; padding-left: 3%; padding-right: 3%; }
.tablecell { display: table-cell; width: 33%; }
As you'll see on the jsfiddle, the red background now leaks at the right edge where it shouldn't. The 'mytable' div padding is 3% each side (6% total), so setting the width to 94% should ensure it fills the container.
Setting the display property back to 'block' makes it work as I'd expect, but then I lose my vertical-align functionality - so this proves it's down to the table display mode in one way or another.
I've tried all manner of disabling all other padding, margins and borders that might be causing it but have failed. Firebug/Chrome dev tools doesn't shed any more light on the issue.
I'm not looking for work-arounds (like line-height etc for vertically aligning text, I'd like to try and find out what the issue is with this specific code).
Have I missed something obvious/any ideas?

Reset the Margins of the body to 0px, then you need to remove the padding-left and padding-right from the .mytable class and add it to the .tablecell directly, lastly set the width of mytable to 100%. Modified CSS below;
.container { width: 100%; background-color: #ff0000; }
.mytable { display: table; background-color: #4d4d4d; width: 100%; }
.tablecell {
display: table-cell; width: 33%;
padding-left: 4%;
padding-right: 4%;
}
body{
margin:0 auto;
padding:0;
}
Jsfiddle example

*{margin:0;padding:0;}
add these lines of code on top of your style.css file , it will solve your problem this is cross browsers solution ,this is called css reset have a look here for details

I've updated you fiddle to use border-collapse:collapse. You need to read more about paddings in tables(no offense, just to get an ideea how to work with display:table and display:table-cell). Here's the http://jsfiddle.net/p8zw2/3/ . You need to add padding to first and third cell contents.

Your div is now behaving like a table: you cannot put a padding, and by default the cells are "spaced" from each other. This is why with a div of width 94% it looks like it's more.
You need to make the border collapsed and set the width of your div to 100%.
.mytable { display: table; background-color: #4d4d4d; width: 100%; border-collapse: collapse; }
It should work.

Most browsers have default margin for body element. Depends on the browser. Some have just padding, some just margin for the body.
Can you try this,
*{
margin:0;
padding:0;
}
Demo: http://jsfiddle.net/p8zw2/5/
body{
margin:0;
padding:0;
}
Demo: http://jsfiddle.net/p8zw2/2/

.tablecell{width:33%} is causing the problem.
33% * 3 = 99%, 1%is the gap.
I have given grey background to .container instead of .mytable and red background to p.
Try:
.container{width:100%;background-color:#4d4d4d;}
.mytable{display:table;width:94%;padding-left:3%;padding-right:3%;}
p{background-color:#f00;margin:0;padding:10px 0;}
Updated fiddle here.

Related

Padding is not working in horizontal line css html

I want to add padding in my hr,
hr {
padding-left: 200px;
}
but it's not working. how to add padding in my hr ?
Padding does not work in hr.
You have to use margin instead:
hr {
margin-left: 200px;
}
And it'll work.
Before adding padding, you should have to set a width for your hr otherwise it will display in full width.
hr:first-of-type{
width: 100px;
padding-left: 10px;
}
hr:last-of-type{
width: 100px;
padding-left: 50px;
}
<hr>
<hr>
Thanks and best regards!
HR is slightly different from most HTML tags in its defined behaviour, as it tries to fill up the whole width of the containing element.
The only way I know to stop it expanding over any margins is to explicitly set a width attribute
hr {
width: 90%;
padding-left: 200px;
}
Even then, it seems to ignore the padding, so you should use a margin instead:
hr {
width: 90%;
margin-left: 200px;
}
It's still kind of scrappy and imprecise. If the ruled line needs to be in line with some other element, you're probably best ensuring that they are in the same DIV, so that the ruled line can start at the left margin of the div.
As Python mentioned, padding does not work with hr
A good solution would be to place the hr inside a div
Another workaround (not recommended, more like a band-aid) would be to create a div and apply styling to it to create a line, particularly add a single border to it
For example,
<div class="divider"></div>
And for the styling
.divider {
border-top: 1px solid #081521; /* Create the border, i.e. Divider */
margin: 1rem auto; /* Add a Margin and Center the divider */
}

How do I make an edge stuck to the screen?

I was trying to make a border glued to the sides of the screen how represents the picture below :
Picture of how i want
I have html code, but i don´t know if i´m doing in the best way. Can you guys help me?
DIV Rectangle HTMl
<div class="content">
This is a rectangle!
</div
DIV Rectangle CSS:
.content {
width:100%;
min-height: 150%;
border:1px solid #FFFF;
border-width: 100%;
background-color: #FFFF;
border-radius: 5px;
padding-bottom: 50%;
}
It is like this:
Picture of how it is
I want to remove this spacing between border and screen, is it possible to do that?
There are 2 solutions:
You can remove your parent block paddings (set it to 0)
You can wrap your .content with an additional block and set its margins to negative values (adjust numbers to fit your layout):
.wrapper { margin: 0 -5px; }
Divs are block-level elements and will take the full width that is available. So, the issue isn't actually the .content div. It's likely that the body has a margin still set on it. It will probably take care of it if you add:
body { margin: 0; }
This is just a guess that it's on the body, but really it's whatever parent or ancestor has margin or padding.
Same problem here
*,html {
margin:0;
padding:0;
}
Hope this helps, "*" will set the whole page to 0

div won't fill width with css

I'm trying to build a 'table' with CSS but I'm having trouble getting some of the <DIV>s to fill the width of the layout if the content is too short.
It's difficult to explain in words so here's a fiddle:
https://jsfiddle.net/fatmonk/r2sodp7p/
Basically I don't want to see the pink bit in the example - I want the light blue box to expand to fill the width regardless of how much or how little content is in it.
Using display: table-row does the right thing with regards filling the line, but doesn't allow a border to be set.
(The fiddle isn't the whole page - there are more 'rows' to add and the whole 'table' will be repeated with link sand link code and other bits and pieces.)
It's quote possible that in the process of trying to get this working I've over-complicated the HTML as well - I've ended up adding container <DIV>s to try to force the width, so it may be that the HTML needs trimming down as well, but I've run out of ideas.
Remove width:auto from the inline style tag of all .menuContentInPopup and add width: 100% to it in your css, so
<div id="poster2" class="menuContentInPopup" style="width: auto;">
would become
<div id="poster2" class="menuContentInPopup">
And the css:
.menuContentInPopup{
display: table;
height:auto;
border: 1px solid rgba(99,99,99,.75);
border-top: none;
background-color:rgba(235,245,255,1);
padding:5px;
font-size: 10pt;
text-align: justify;
left: 0px;
right: 0px;
float: none;
width: 100%;
}
Here a fiddle showing the result: Fiddle.
I have also adjusted the box-sizing of all elements so that adding padding to the elements does not make it overflow its parent when width is 100%, this is achieved by
* {
margin: 0;
padding: 0;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
box-sizing: border-box;
}
i might understood it wrong but here is how i would fix it.
[Fiddle][1]
I changed the width to 100% so it will fill your full div. Also removed the width: auto in the HTML.
[1]: https://jsfiddle.net/r2sodp7p/10/
FYI, another clean solution for your case here:
[http://jsfiddle.net/giaumn/f99ub6ro/]
You just need to care about 2 properties:
overflow: auto;
on .menu-content and
float: left;
on .poster-thumb
set your width:auto; to width:100%; and add width:100%; to menuContentInPopup class. remove width:auto from html inline styles.
fiddle

Why content won't take a different background color?

I have the whole page set to gray as the background color, but would like only the content area to be set to a different color. According to my CSS, this should be happening but it isn't. Why not?
html,
body {
background-color: #FAFAFA;
}
#page-wrapper {
margin: 0 auto;
padding: 0;
width: 1024px;
}
#content {
background-color: blue;
}
OK, well, I thought there might be an obvious answer, because this is a severly slimmed-down version of my code. Yes it has content and there are things in the page-wrapper.
The jsfiddle link is here: http://jsfiddle.net/2pzo80Lu/
Also, if anyone has critiques of the code otherwise, it would be much appreciated.
You need to add overflow:auto to your rules for #content because the children are floated. Floating them essentailly removes them from the normal flow and collapses the parent since it behaves as if there's no content. Adding the overflow rule restores the behavior you seek.
#content {
background-color: blue;
overflow:auto;
}
jsFiddle example
your elements inside #content div is floated right and left so the div has no height ( 0px ) , you can solve this in css by adding the following code
#content {
background-color: blue;
overflow:auto;
}
or in html by adding the following code before the close of the element of #content
<div style="clear:both;"></div>
this will clear any floating and you code should work very will. good luck

How do i make a fieldset `display: block; overflow: auto` show a scrollbar?

I want my <fieldset> elements to behave like vanilla <div>'s by filling their containing element and showing a scrollbar when they are set to overflow: auto.
For instance, I don't see why the fieldset in this
example is wider than its containing div:
<div class=outer>
<fieldset class=inner>
fooooooooooooooooooooooooooooooooooooo
</fieldset>
</div>
<div class=outer>
<div class=inner>
fooooooooooooooooooooooooooooooooooooooo
</div>
</div>
and corresponding css:
.outer {
width: 60px;
}
.inner {
overflow: auto;
display: block;
height: 60px;
border: 1px solid red;
}
It turns out the culprit (in some cases) was the user-agent stylesheet in webkit was setting:
fieldset {
min-width: -webkit-min-content;
}
setting min-width: 0; in the stylesheet corrected the issue in Chrome 27, Safari 6.0.2, and WebKit Nightly r146031. It fails to correct the issue in Chrome 25 and FireFox 19.0.2.
Either way this does not solve the problem.
<fieldset> does not inherit the width from the parent div. The .inner div does inherit the width and shinks. You can solve this just by adding width: inherit as a rule to .inner. Note that <fieldset> may also get some extra padding and margin.
http://codepen.io/anon/pen/fxjek
To fix your fieldset or make it like the div below it in your example, add the following css::
fieldset{
margin:0px;
padding:0px
}
you need to reset the margin and padding first to act like the div below it then add the width you want :
.inner {
width:60px;
}
The reason the Fieldset version is wider than the div version is because
fieldset has its own default padding unless you specify otherwise.
See: http://jsfiddle.net/RDVY7/
I added this to your CSS:
fieldset {
margin:0 ;
padding:0 ;
}
and it fixed the problem. If you want spacing between your fieldset version
and your div, just adjust the margin: element.