I am trying to create a grid struture with div of equal height and width but I am unable to apply the border
CSS
.Container {
width:1000px;
position:relative;
margin:0 auto;
}
.RowContainer {
overflow:hidden;
position:relative;
height:200px;
clear:both;
}
.RowContainer .Cell {
position:relative;
float:left;
height:100%;
width:200px;
border:1px solid Black;
}
HTML
<div class="Container">
<div class="RowContainer">
<div class="Cell"><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum</p> </div>
<div class="Cell"><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></div>
<div class="Cell"><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum
</p> </div>
<div class="Cell"><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></div>
</div>
<div class="RowContainer">
<div class="Cell"><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum
</p></div>
<div class="Cell"><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></div>
<div class="Cell"><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></div>
<div class="Cell"><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></div>
</div>
<div style="clear:both"></div>
</div>
I have two issues
1.
border is not showing in the last row.
2.
As well as the border width seems unequal despite of applying same border property to all.
If you're trying to create something that is table-like, why not just use tables?
<table class="container">
<tr>
<td><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum</p></td>
<td><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></td>
<td><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum</p></td>
<td><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></td>
</tr>
<tr>
<td><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum</p></td>
<td><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></td>
<td><h1>lorum ipsum lorum ipsum</h1><p>lorum ipsum epsum</p></td>
<td><h1>lorum ipsum</h1><p>lorum ipsum epsum</p></td>
</tr>
</table>
Bottom border is not showing in either row because you have height: 100% on the .Cell and overflow: hidden on the .Container. What you are seeing under the first row is the top border for the second row.
If you set height: 100%; on the child of an element of height: 200px that has overflow: hidden and then you set a border of 1px to that child, then that border adds up on all sides.
It makes that child element take up 202px vertically. That's 1px from top border + 200px from height + 1px from bottom border.
But the parent element has a height of only 200px and overflow: hidden, which means that vertically, from the child element, what you see is the 1px top border and 199px of the child's height. There is still 1px of its height and the 1px bottom border which are hidden.
Second vertical border is thicker than the first, because you have there both the right 1px border of the first cell and the left 1px border of the second cell.
This would solve the issue http://dabblet.com/gist/3145644
The overflow:hidden on .RowContainer is hiding the border on the .Cell divs, because border is drawn outside the .Cell's box, which is set to 100% height. Removing the overflow:hidden should reveal it again.
As for the unequal border, I can't say for sure since you didn't provide a jsfiddle to look at, but I'm guessing you mean the borders between the cells is thicker than it should be -- that's because each .Cell has a border all the way around, resulting in the left/right borders sitting next to each other, giving the appearance of a 2px border.
You can fix this by only setting border on the top and left sides of each .Cell, and then setting border on the bottom and right sides of the .Container.
remove your overflow:hidden
like this
.Container {
width:1000px;
margin:0 auto;
}
.RowContainer {
height:200px;
clear:both;
}
.RowContainer .Cell {
position:relative;
float:left;
height:100%;
width:200px;
border:1px solid Black;
}
The CSS Overflow
Every single element on a page is a rectangular box. The sizing, positioning, and behavior of these boxes can all be controlled via CSS. By behavior, I mean how the box handles it when the content inside and around it changes. For example, if you don't set the height of a box, the height of that box will grow as large as it needs to be to accommodate the content. But what happens when you do set a specific height or width on a box, and the content inside cannot fit? That is where the CSS overflow property comes in, allowing you to specify how you would like that handled.
There are four values for the overflow property: visible (default), hidden, scroll, and auto. There are also sister properties overflow-y and overflow-x, which enjoy less widespread adoption.
Related
I've made 3 examples of what I'd like to achieve.
I have 2 divs side by side in a wrapper that has 100% as width, the left div has a width of 100% minus the width of the righter div, the righter div has an auto width.
When the left div text isn't long enough to hit the righter div, the left div should extend till the righter div.
When the content in the left div is too long, it should overflow to a new line, the righter div will keep it's width.
When the content increases in righter div, the left div should adjust its width and overflow if needed.
Is there a way to do this without javascript and preferably without flex?
You can use flex for that:
.wrapper {
background: red;
display: flex;
align-items: flex-start;
}
.left {
background: gray;
flex: 1;
}
.right {
background: green;
width: 150px;
}
<div class="wrapper">
<div class="left">
Lorem ipsum
</div>
<div class="right">
Lorem ipsum
</div>
</div>
Just assign display: flex; to the wrapper DIV - that should do what you want
You can use Flexbox to do this, you just need to set flex: 1 on left div so it takes free width. Also to remove white-space when text wraps you can use word-break: break-all so it breaks on each letter and to make items keep its own height you can add align-items: flex-start Fiddle
.content {
display: flex;
align-items: flex-start;
}
.left {
background: lightblue;
word-break: break-all;
flex: 1;
}
.right {
background: lightgreen;
}
<div class="content">
<div class="left">Lorem ipsum dolor sit amet, consectetur.</div>
<div class="right">loremipsum</div>
</div>
hope this is what your are looking for.
.leftdiv {background: green;flex: 1;}
.container {display: flex;align-items: flex-start;}
.rightdiv {background: red;}
<div class="container">
<div class="leftdiv">
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
</div>
<div class="rightdiv">
hello world
</div>
</div>
</br>
<div class="container">
<div class="leftdiv">
Lorem ipsum Lorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsumLorem ipsum
</div>
<div class="rightdiv">
Lorem ipsum Lorem ipsum Lorem
</div>
</div>
This image shows desired layout:
"Lorem ipsum" div is placed on top and "Dolor sit" div sits under it. Right "P" div sets minimal height (first part) of whole main wrapper section unless "Dolor sit" div increases height (second part).
Implementation is shown in this Plunker:
Plunker demonstration
<section id="wrapperMain" style="display:table; width:100%">
<div style="background-color:#2e3338; display: table-cell; min-width:50px; width:50px;">
<h1 style="margin-left:25%; margin-right:25%">P</h1>
</div>
<div style="background-color:dodgerblue; display: table-cell;">
<!--This section should fill its parent: dodgerblue div-->
<!--So no blue color could be seen above "Lorem ipsum" div-->
<section style="display:table; width:100%; background-color:crimson; margin-top:0;">
<div style="display:table-row">
<div style="background-color:darkslategray;">Lorem ipsum</div>
</div>
<div style="background-color: #1c1e22; border-style: none; resize: none; width: 100%;">Dolor sit Dolor sit Dolor sit Dolor sit Dolor sit Dolor sit </div>
</section>
</div>
And with any combination of setting margins, heights, displays I wasn't able to dock 2nd table section inside table cell without margin on top. Right now I'm not sure if this is correct approach.
I think this is what you are after, you just need to add vertical-align:top to the table cell on the right
I have also fixed your second table styles as you had block mixed with table-rows and no table-cells which may cause issues for some browsers:
<section id="wrapperMain" style="display:table; width:100%">
<div style="background-color:#2e3338; display: table-cell; min-width:50px; width:50px;">
<h1 style="margin-left:25%; margin-right:25%">P</h1>
</div>
<div style="background-color:dodgerblue; display: table-cell; vertical-align:top"> <!-- add vertical align:top here -->
<!--This section should fill its parent: dodgerblue div-->
<!--So no blue color could be seen above "Lorem ipsum" div-->
<section style="display:table; width:100%; background-color:crimson; margin-top:0;">
<div style="display:table-row">
<div style="background-color:darkslategray; display:table-cell">Lorem ipsum</div>
</div>
<div style="background-color: #1c1e22; border-style: none; resize: none; width: 100%;display:table-row;">
<div class="display:table-cell">Dolor sit Dolor sit Dolor sit Dolor sit Dolor sit Dolor sit</div>
</div>
</section>
</div>
</section>
We have a fix set of CSS rules, but when we modify the HTML markup to include a canvas, a weird padding appears on the neighboring cell. Here is the CSS:
.wrap{
width:100%;
display: table;
}
.row {
display: table-row;
}
.left{
width: 100px;
display: table-cell;
background-color: #0f0;
}
.right{
background-color: #f00;
display: table-cell;
}
Normal case:
See the fiddle here. Note the position of the text in the red cell: top, aligned with the top of the cell.
<div class="wrap">
<div class="row">
<div class="left">
Lorem<br>Lorem<br>Lorem<br>Lorem<br>Lorem
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
Canvas case:
See the fiddle here. We swapped the Lorem text in the left cell for a 90x90 canvas. See how the text on the red cell is now aligned with the bottom of the canvas and a padding is applied to the cell.
<div class="wrap">
<div class="row">
<div class="left">
<canvas width='90px' height='90x'></canvas>
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
</div>
</div>
Question: Could you explain why this padding appears on the left cell, and if this is an expected behavior? Also, could you propose a solution that gets rid of this 'bug'?
Then i add some text in my absolute block inner div it dosn't expand.
I know that exapanding forbids a parent container width: <div class="main_wrap"></div>.
But I can't remove it from him.
So i want to find a solution how i can correct it without a js. How can i do this? It must to expand in width, not in height, talking about this element: <div class="abs">. IF you remove a width from .main_wrap it's correct view, but i need to reach results like this without removing width, because it's just little part of huge grid.
HTML:
<div class="block">
<div class="abs">
<table class="whf table">
<tr>
<td>
<div class="image">
<div class="shadow"></div>
<img src="http://boardingarea.com/blogs/deltapoints/files/2012/07/test.jpg" width="77" />
</div>
</td>
<td class="vamid">
<div class="text">
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum
</div>
</td>
</tr>
</table>
</div>
Here is full example:
http://jsbin.com/uqafuq/6/edit
Thanks in future.
I don't know if I understood you correctly and your construction looks quite strange, but is this what you wanted to achieve? http://jsbin.com/uqafuq/11/edit
Just remove the height: 100% from .abs
Just delete your height: 100% from .abs your setting your height from the elements parent which dont have height at all
Add display: inline-block; to .block
I want to expand my div height by 100%, but it is not working:
So far, my code is:
.add{
border:1px solid #ddd;
display:block;
float:right;
margin:0 0 10px 10px;
padding:10px;
height:100%;
}
And the HTML:
<div>
<div class="add">
<div style="width:100px;height:400px;background:#ccc;"></div>
</div>
Lorem ipsum dolor sit amet... And a lot of text here
Lorem ipsum dolor sit amet... And a lot of text here
Lorem ipsum dolor sit amet... And a lot of text here
</div>
You should have specified the height of the outer div. Something like this will work:
<!doctype html>
<html>
<head>
<style>
.add
{
border:1px solid #ddd;
display:block;
float:right;
margin:0 0 10px 10px;
padding:10px;
height:100%;
}
</style>
</head>
<body>
<div style="height: 768px;">
<div class="add">
<div style="width:100px;height:400px;background:#ccc;"></div>
</div>
Lorem ipsum dolor sit amet... And a lot of text here
Lorem ipsum dolor sit amet... And a lot of text here
Lorem ipsum dolor sit amet... And a lot of text here
</div>
</body>
</html>
From the CSS 2.1 Spec:
percentage
Specifies a percentage height. The percentage is calculated with respect to the height of the generated box's
containing block. If the height of the containing block is not
specified explicitly (i.e., it depends on content height), and this
element is not absolutely positioned, the value computes to 'auto'.
So, since the containing block has no specified height, the floated element's height is auto.