For some reason <div class="h-screen bg-gradient-to-br from-green-400 to-indigo-600"> appears with a white line on the top on desktop:
it also looks like this on repl (see below_, although can't reproduce using chrome.
My initial assumption would be that you're getting caught out by margin collapsing. There's an unintuitive situation that occurs with the margins on the first and last child of an element.
In your case, I'd assume that your immediate child element has a top margin which is creating that white gap at the top of the page.
You can solve that problem by setting your container to display: flow-root. Tailwind gives you the .flow-root class for that.
<div class="flow-root h-screen bg-gradient-to-br from-green-400 to-indigo-600">
Related
I encountered something very strange today. When adding the style overflow: hidden to a div, if its content has a header, it gets some extra blank space which seems like margin or padding. The amount is small, so I usually would not have even noticed, or cared, but the problem is that I'm making an animation, and that margin/padding is messing it up. For hours I thought it was the animation which was wrong, but I finally managed to narrow it down to this.
Here's the code with overflow:
<div style="overflow:hidden">
<ng-content select="wizard-step"></ng-content>
</div>
The ng-content renders this:
<h5><strong>testing bootstrap header</strong></h5>
<search-select #select [placeholder]="'Busca audiencias...'" (selected)="onSelected($event); select.text = ''" [template]="template" property="name" [items]="catalogAudiences | filterAudiences:audiences"></search-select>
<div class="mt-3">
<div *ngIf="!audiences?.length" class="alert alert-primary">
No has agregado audiencias.
</div>
<audiences-list (remove)="onRemove($event)" [readOnly]="true" [audiences]="audiences"></audiences-list>
</div>
And it looks like this:
I want you to notice the arrows which show the extra space I'm talking about. To compare, this is what it looks like if I remove style="overflow:hidden":
I know it might be hard to tell, but it's almost like if the "testing bootstrap header" is getting some unwanted margin whenever that div has overflow: hidden, which messes up my animation. How can I fix this?
I'm using Bootstrap 4 and Angular 5 if that's of any help.
Chances are, the h5 (the "testing bootstrap header") has a top margin either from browser defaults or Bootstrap, that's being affected by the div's overflow: hidden (which causes it to establish a block formatting context that blocks child margins from collapsing with their parent margins). See collapsing margins in the spec.
If removing the top margin fixes this, that's your answer.
I am currently developing a site and have encountered a strange problem with getting two of my divs to stay on the same line. The page in question is here: http://bit.ly/13QE7Zi and the divs I'm trying to fix are the text div in the middle and the small image beside it. In the CSS, I have these divs set to take up 1000px (20+640+20+300+20) which is the width of the container element, but if I do this, the second div gets pushed onto the next line. It only works if I decrease the width of the text div by 3 px, which is undesirable because then the edge of the image is not aligned with the right side of the page properly. This occurs in Chrome and Firefox. I'd prefer not to use floats because that breaks other aspects of the page. How do I get these two divs to stay on the same line and still fill the full 1000px of width?
The reason this is happening is because you have a 'space' character between your two inline blocks.
HTML doesn't really ignore all white space. You can have 1000 spaces and new lines between two elements and HTML would condense all those down into 1 single space when displaying.
Your inline blocks are setup in such a way that they there widths add up to be exactly 1000px, however you have a new line in between your two containing elements which condenses down to 1 space. Your precise measurement doesn't account for this extra space and so your inline blocks wrap to the next line.
Instead of decreasing your text's width by 3 px, decrease the padding-right on .looktrai-text it won't change the way it looks but will give enough room for both to fit.
You can use border-box box-sizing. That way the width of the elements will include the padding and the borders.
You can simplify your code, and even implement text wrapping around the image by doing the following.
Disclaimer: This is a suggestion based on the results you are trying to achieve.
Remove the .looktrai-text and .looktrai-sidediv divs
Format the HTML inside of #looktrai-content like this:
<div id="looktrai-content" class="clear">
<img src="content/looktrai_side.jpg" alt="" class="align-right" />
<p>My paragraph text</p>
<p>My second paragraph</p>
</div>
Add the following CSS:
img.align-right {
float: right;
margin: 0 20px 20px;
}
The result will look something like this: http://codepen.io/anon/pen/yjdxh
This is a cleaner, simpler approach that allows you to reduce code, and maximize flexibility.
I would use float: left for the text div, and float: right for the image div and remove the display: inline-block property. This creates a clearing issue for the footer, but this is easily fixed using one of the many 'clearfix' hacks. My preferred method is using a .group class on the parent container div, as per this article on CSS Tricks. In your case this would be <div id="looktrai-content" class="group">
I tried to make two sections to my structure, one is a top section and another is a body section.
I'm trying to make the mainbody divs break away from the top section. For some reason when I add the color purple to a main body div it's coloring in everything else!
I added overflow:hidden to the wrapper and it did something, am I on the right path?
You can see my example here.
Thats because you used floating elements and didn't clear after them. Add
.mainbody{clear:both;}
But why do you have .topsection{float:left;}? If mainbody has width: 100%, it does nothing.
And overflow:hidden did somethink because if you have a block element with some floating elements before him, and you set overflow different than visible to him, you are creating columns. So then mainbody wasn't under topsection.
Edit:
Even if you remove the nonsense .topsection{float:left;}, it won't work because topright and topleft are not cleared floating elements too. So you have to add .mainbody{clear:both;} too, or change your topsection into:
<div class="topsection">
<div class="topright">...</div>
<div class="topleft">...</div>
<div class="clear"></div>
</div>
And then
.clear{clear:both;}
I'm having problems with the following (example) code. What I'm trying to achieve is the following: div#id1 is a container div. This contains a div with an optional image and a div for body text. Div#id2 is similar. Div#id3 is a container div for the menu. It should be located to the topleft of #container. Now in case there is an image in #id1 the div#id3 will be pushed down. This works in FF, Chrome, etc. It works in IE too but only with div#id1, as soon as I add div#id2 it seems IE uses it to clear the div#id1.
<div id="container" style="background:red;width:800px;min-height:500px;margin:0 auto;">
<div id="id1">
<div style="width:200px;float:left;"><!-- this div has optional content and therefore might or might not push the purple div down --></div>
<div style="background:yellow;width:600px;float:right;">This is the top right div</div>
</div>
<div id="id2">
<div style="background:green;width:600px;float:right;">This is the bottom right div</div>
</div>
<div id="id3">
<div style="background:purple;width:200px;">This should be the top left div but is not the case in IE</div>
</div>
Try the code above in both FF and IE and you'll see the difference. IE messes up. Then remove div#id2 and it's contents and try again. Here IE shows things just fine.
Any clues as to how to fix this?
Cheers,
Bartezz
The blank div seems to have a minimum height meant for containing text, which causes it to be pushed down -- in Fx empty divs are not shown at all, and don't save any space for content inside them, cause there isn't any. Try modifying the 2nd inside of #id1 and the div #id2's width to lower and you'll see that the purple div gets pushed up a line-height -- I'm guessing the widths cause them to get so close to each other, that IE (but not other browsers) doesn't know how to make room for it so it pushes it down.
Dunno if this fits with your ideas, but why don't you just have one left div, and one right div, and fit divs inside them?
When I specify a height in the style for any element inside of this, IE makes the entire thing 100% width, rather than keeping it "autosized" for width.
Other browsers display it fine, but not IE. How do I fix this?
<div style="position:absolute;top:50px;left:50px;background:green;">
<div>
<div>test</div>
<div style="height: 20px;">this makes it 100% width in IE. why?</div>
</div>
</div>
Thanks!
Here's something that may work for you. It's a little hacky, but if you're trying to find a good width for some text, this is the only way besides javascript that I know of. We're basically forcing the width by not allowing the line to break. You can put in <br/>s if you need line breaks.
<div style="position:absolute;top:50px;left:50px;background:green;width:0px">
<div>
<div>test</div>
<div style="height:50px; white-space:nowrap">This is normally sized in IE6</div>
</div>
</div>
On second thought, don't check out the link. It's old and doesn't work as advertised.
Old answer:
http://snippets.dzone.com/posts/show/216
I believe that non-absolutely positioned DIVs automatically expand to fill their container horizontally. Since you haven't specified any container size for this div, it expands to fill the whole page.
I find it odd that Firefox doesn't expand the div... I'm not sure which of them actually has it "right".
At a guess, I would say it's something to do with the hasLayout bug in IE6. My suggestions:
1. Give the containing div (the one with the absolute positioning) a set width.
2. Post an example of what you are trying to achieve. We might be able to suggest a more all-browser friendly way of doing what you want.