Div Table Responsive - Header Repeats - html

I have a DIV table, it is fully responsive. The table's head should repeat in each section when we view it in a small screen. Right now it shows in the first section but the second section is missing the header.
How can I make the header show in each section on a small screen? that looks like this sample: https://codepen.io/geoffyuen/pen/FCBEg (this sample is a tr td table, my table is a DIV table)
Note: The browser needs to be minimized to see the table responsive.
DEMO: http://jsfiddle.net/w04g2qj9/2/
CSS
.header {
width: 100%;
float: left;
}
.header1 {
width: 33%;
float:left;
background: #bbb;
height: 25px;
}
.row1, .row2 {
width: 33%;
float:left;
background: #ddd;
height: 25px;
}
#media all and (max-width: 480px)
{
.header
{
width:40%;
height: 100%;
float:left;
background: red !important;
}
.header1, .row1, .row2 {width: 100% !important}
.row {
width: 60% !important; margin-bottom: 5px; float:left
}
}
HTML
<div class="table">
<div class="header">
<div class="header1">
Header 01
</div>
<div class="header1">
Header 02
</div>
<div class="header1">
Header 03
</div>
</div>
<div class="row">
<div class="row1">
row 01-1
</div>
<div class="row1">
row 02-1
</div>
<div class="row1">
row 03-1
</div>
</div>
<div class="row">
<div class="row2">
row 01-2
</div>
<div class="row1">
row 02-2
</div>
<div class="row1">
row 03-2
</div>
</div>
</div>

Div Table Image
If you run the code snippet you've provided, this is the result. I'm assuming that this is what you wanted, however, I do see a lot of redundancies in your css. For example, why have two classes row1 and row2 when they are the same thing? Unless you plan to change it so they are different at a later time.

Using Flexyou can achieve this> See Sample code below..Hope it helps
.footer_mainDIV {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.header {
width: 100%;
float: left;
}
.header1 {
width: 33%;
float: left;
background: #ccc;
height: 25px;
}
.row1,
.row2 {
width: 33%;
float: left;
background: #ddd;
height: 25px;
}
#media all and (max-width: 480px) {
.footer_mainDIV {
flex-direction: row;
flex-wrap: nowrap;
text-align: center;
}
.header {
height: 100%;
float: left;
background: red !important;
flex: 1;
/* Add other alignment related styles*/
}
.header1,
.row1,
.row2 {
width: 100% !important
}
.row {
flex: 1;
margin-bottom: 5px;
background: green !important;
}
}
<div class="footer_mainDIV">
<div class="header">
<div class="header1">
Header 01
</div>
<div class="header1">
Header 02
</div>
<div class="header1">
Header 03
</div>
</div>
<div class="row">
<div class="row1">
row 1-1
</div>
<div class="row1">
row 1-2
</div>
<div class="row1">
row 1-3
</div>
</div>
<div class="row">
<div class="row2">
row 2-1
</div>
<div class="row1">
row 2-2
</div>
<div class="row1">
row 3-3
</div>
</div>
</div>

Related

how to center the first item in a flexbox slider/carousel

I want to build a simple scroll slider with flexbox with three items. I want the first item to be centered in the page (under the headline) but the following items only should have a less margin.
HTML:
<div class="page-width">
<h1>Headline</h1>
<div class="container">
<div class="flex-item">
<div class="flex-wrapper">
Center me
</div>
</div>
<div class="flex-item">
<div class="flex-wrapper">
Hello World
</div>
</div>
<div class="flex-item">
<div class="flex-wrapper">
Hello World
</div>
</div>
</div>
</div>
CSS:
.page-width {
max-width: 500px;
border: 5px solid green;
}
h1 {
text-align: center;
}
.container {
display: flex;
justify-content: flex-start;
overflow: scroll;
}
.flex-item {
margin-left: 20px;
}
.flex-wrapper {
background: blue;
width: 250px;
height: 250px;
}
How can I achieve to center the first item, while the second and third only remain with a margin of 20px? Also, it should be responsive, for example when the page width is smaller, the first item should still be centered.
I tried to use
.flex-item {
flex: 0 0 100%
}
and center the wrapper inside, so the box would be in the center, but then the second and third item are outside of the screen.
Codepen: https://codepen.io/ascena/pen/wvqZgzg
.page-width {
max-width: 500px;
border: 5px solid green;
}
h1 {
text-align: center;
}
.container {
display: flex;
justify-content: flex-start;
overflow: scroll;
padding-left:20%;
}
.flex-item {
margin-left: 20px;
}
.flex-wrapper {
background: blue;
width: 250px;
height: 250px;
}
<div class="page-width">
<h1>Headline</h1>
<div class="container">
<div class="flex-item">
<div class="flex-wrapper">
Center me
</div>
</div>
<div class="flex-item">
<div class="flex-wrapper">
Hello World
</div>
</div>
<div class="flex-item">
<div class="flex-wrapper">
Hello World
</div>
</div>
</div>
</div>

Trying to create proportional table with divs

I'm trying to create a HTML page with a proportional table, using div elements only. I wish the left column to take 60% of the table width and have 3 rows. For the 2nd column I wish it to take the remaining 40% of the table's width, and have 4 rows, each row with 2 cells.
Here is my HTML markup: Why I only see the first (left) column?
body,
html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #DDDDDD;
}
#MasterDiv {
display: table;
height: 100%;
width: 100%;
}
.left {
display: table-column;
width: 60%;
}
.right {
display: table-column;
width: 40%;
}
.A {
height: 30%;
display: table-row;
}
.B {
height: 35%;
display: table-row;
}
.B2 {
height: 25%;
display: table-row;
}
.C1 {
display: table-cell;
background: #ff00ff;
}
.C2 {
display: table-cell;
background: #ffffff;
}
.C3 {
display: table-cell;
background: #0000ff;
}
.C4 {
display: table-cell;
background: #ff0000;
}
.C5 {
display: table-cell;
background: #00ff00;
}
.C6 {
display: table-cell;
background: #000000;
}
<div id="MasterDiv">
<div class="left"></div>
<div class="right"></div>
<div class="A">
<div class="C1"></div>
</div>
<div class="B">
<div class="C2"></div>
</div>
<div class="B">
<div class="C3">
</div>
</div>
<div class="B2">
<div class="C1"></div>
<div class="C2"></div>
</div>
<div class="B2">
<div class="C3"></div>
<div class="C4"></div>
</div>
<div class="B2">
<div class="C5"></div>
<div class="C6"></div>
</div>
<div class="B2">
<div class="C4"></div>
<div class="C6"></div>
</div>
</div>
you need to nest your rows and columns within the left and right divs. At the moment you're declaring left and right but have no content inside them and there's mix of table and div elements which can confuse things.
I've made a div only example of what you described above. The "row" divs on the left take up 100% and the 'split-columns' take up 50% of the "right" width. The height is based on content but if you want to specify you can do by adding an id or class.
.container {
width: 100%;
font-family: Helvetica, Sans-Serif;
}
.left,
.right,
.split-column {
float: left;
background-color: #f9f9f9;
}
.left {
width: 60%;
}
.right {
width: 40%;
}
.split-column {
width: 50%;
background-color: lightblue;
}
<div class="container">
<div class="left">
<div class="row">
row 1
</div>
<div class="row">
row 2
</div>
<div class="row">
row 3
</div>
</div>
<div class="right">
<div class="split-column">
cell 1
</div>
<div class="split-column">
cell 2
</div>
<div class="split-column">
cell 1
</div>
<div class="split-column">
cell 2
</div>
<div class="split-column">
cell 1
</div>
<div class="split-column">
cell 2
</div>
<div class="split-column">
cell 1
</div>
<div class="split-column">
cell 2
</div>
</div>
Try this
http://www.cssdesk.com/5wSVE
I have added some css from TJ Hannington answser

Display 2 div in block and vertical div beside them

I am trying to design a section which 3 image. I can get the two images to display by block easily. I can float the third image to the right and adjust the height easily. However my issue is it does not align side by side.Below is an example of what I am trying to achieve
This is an example of what I have so far
.image-one,
.image-two {
width: 250px;
background-color: green;
display: block;
margin-top: 10px;
}
.image-three {
float: right;
background-color: lightblue;
width: 250px;
height: 200px;
}
<div class="container">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
<div class="image-three"> Image three </div>
</div>
You should be able to simple add flex to the container, and then add the content within a left and a right div.
Here's a working example:
.container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.image-one,
.image-two {
width: 250px;
height: 95px;
background-color: green;
margin-bottom: 10px;
}
.image-three {
background-color: lightblue;
width: 240px;
height: 200px;
margin-left: 10px;
}
<div class="container">
<div class="left">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
</div>
<div class="right">
<div class="image-three"> Image three </div>
</div>
</div>
You can use flexbox for this:
.container {
display: flex;
flex-direction: column; /* align items in columns */
flex-wrap: wrap; /* wrap to a new column when height is reached */
justify-content: space-between; /* add spacing in between top and bottom image */
height: 210px; /* height of your 2 images plus and spacing you want */
width: 510px; /* width of 2 columns plus any spacing */
}
.image-one,
.image-two {
width: 250px;
height: 100px;
background-color: green;
display: block;
}
.image-three {
background-color: lightblue;
width: 250px;
height: 210px; /* I would make this image the height of the other 2 plus spacing */
align-self:flex-end; /* align this to the right of the container */
}
<div class="container">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
<div class="image-three"> Image three </div>
</div>
Maybe you can add some internal divs like this:
<div class="container">
<div class="container-left">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
</div>
<div class="container-right">
<div class="image-three"> Image three </div>
</div>
</div>
Then, add css to container-left and container-right to properly set the width and the float. Like this:
.container-left, .container-right{
width:250px;
float:left;
}
Why don't you make use of bootstrap columns?
HTML
<div class="container">
<div class="row main-row">
<div class="col-6 left-col">
<div class="row left-col-top">
<!-- Top left image here -->
</div>
<div class="row left-col-bottom">
<!-- Bottom left image here -->
</div>
</div>
<div class="col-6 right-col">
</div>
</div>
</div>
CSS
.main-row {
height:300px;
}
.left-col-top {
background-color:blue;
height:50%;
}
.left-col-bottom {
background-color:red;
height:50%;
}
.right-col {
background-color:green;
height:100%;
}
Easy flexbox solution :)
#main, #left {
display:flex;
}
#left {
flex-direction: column;
flex: 1;
}
.section {
flex: 1;
margin: 2px;
background-color: green;
}
<div id="main">
<div id="left">
<div class="section">Hello</div>
<div class="section">Hello</div>
</div>
<div id="right" class="section">Hello</div>
</div>

Center All Content In Each Div - Responsive?

.row {
width: 100%;
height: 150px;
}
.col {
display: inline-block;
margin: 0 auto;
height: 150px;
}
#left {
float: left;
width: 30%;
height: 150px;
background-color: red;
}
#center {
width: 40%;
height: 100%;
background-color: green;
}
#right {
float: right;
width: 30%;
background-color: blue;
}
<header>
<div class="row">
<div class="col" id="left">
Test Test Text
</div>
<div class="col" id="center">
Image
</div>
<div class="col" id="right">
Text Image
</div>
</div>
</header>
I have read so many posts but still cannot make this work. I am missing something. I want to have these three divs in my header. The center div should be centered in the middle of the page and it will be a image. The other divs will be on the left and right and a combination of text and images as desired. I want all 3 divs to have their content vertically and horizontally centered. How do I do this and maintain some responsiveness for users on div browser and screen sizes. Responsiveness is secondary issue, getting the content aligned is the main challange. Thanks,
You can use display: table for row and display: table-cell for columns
.row {
width: 100%;
height: 150px;
display: table;
}
.col {
width: 30%;
height: 150px;
display: table-cell;
text-align: center;
vertical-align: middle;
}
#left {
background-color: red;
}
#center {
width: 40%;
background-color: green;
}
#right {
background-color: blue;
}
<header>
<div class="row">
<div class="col" id="left">
Test Test Text
</div>
<div class="col" id="center">
Image
</div>
<div class="col" id="right">
Text Image
</div>
</div>
</header>
You could use CSS3 flexbox for it:
.row, .col {
display: flex;
justify-content: center;
align-items: center;
}
.col {
height: 200px;
flex: 1 100%;
}
#left {
background-color: red;
}
#center {
background-color: green;
}
#right {
background-color: blue;
}
<header>
<div class="row">
<div class="col" id="left">
Test Test Text
</div>
<div class="col" id="center">
Image
</div>
<div class="col" id="right">
Text Image
</div>
</div>
</header>
JSFiddle

How to make divs same height?

I have one parent-div which contains three divs and I would like to make them same height but it is not working. The first and third div contains each an image. The second div contains three divs with content.
Here is the HTML:
<div class="container">
<div class="column1">
<img src="http://placehold.it/300x318">
</div>
<div class="column2">
<div class="row1">
<div class="text">UNIKE GUSTAVIANSKE STILMØBLER.</div>
<div class="text">VI SELGER HÅNDVERK ETTER 1700-</div>
<div class="text">OG 1800-TALLS TRADISJONER.</div>
</div>
<div class="row2"></div>
<div class="row3">
<div class="text">
Åpningstider:<br>
Man - Fre 11 -17 Lør 11- 15
</div>
</div>
</div>
<div class="column3">
<img src="http://placehold.it/300x318">
</div>
</div>
The .container has the css-rule display:flex;. When I apply this also to .column1, .column2 and .column3, the layout breaks.
I am trying to achieve that the images height increase and decrease depended to .column2. Unfortunately, I have not the possibility to change the HTML or use JS.
Here you can see a JS-Fiddle. I have commented out the CSS-rules.
Many thanks for your help!
In the question you mention that you apply display:flex to .column1, .column2 and .column3.
Instead just apply this to .column1 and .column3 and leave .column2 as display:block.
This should resolve your problem (works in your JS-Fiddle).
You just need to apply a height and max-width to the images. They will distort to fit into the space and make your images look weird. If you choose images that are this dimensions, they will look better.
.container {
width: 100%;
display: flex;
}
.container img{
height: 100%;
max-width: 100%;
}
.row1 {
background-color: #fff;
padding-top: 40px;
}
.row1 .text {
font-size: 30px;
text-align: center;
line-height: 50px;
font-weight: 300;
}
.row2 {
height: 150px;
background-color: #e4e8eb;
}
.row3 {
background-color: #c7cacf;
padding: 10px 0px;
}
.row3 .text {
font-size: 25px;
text-align: center;
line-height: 25px;
}
<div class="container">
<div class="column1">
<img src="http://placehold.it/300x318">
</div>
<div class="column2">
<div class="row1">
<div class="text">
UNIKE GUSTAVIANSKE STILMØBLER.</div>
<div class="text">VI SELGER HÅNDVERK ETTER 1700-</div>
<div class="text">OG 1800-TALLS TRADISJONER.
</div>
</div>
<div class="row2"></div>
<div class="row3">
<div class="text">Åpningstider:
<br>Man - Fre 11 -17 Lør 11- 15</div>
</div>
</div>
<div class="column3">
<img src="http://placehold.it/300x318">
</div>
</div>
you can add this lines for row css
.row {
display: flex;
justify-content: center; /* align horizontal */
align-items: center;
}
You just need to specify the height and width of image tag.Just add width:100% and height 100% for image tag.
.container {
width: 100%;
display: flex;
}
.container img{
height: 100%;
max-width: 100%;
}
.row1 {
background-color: #fff;
padding-top: 40px;
}
.row1 .text {
font-size: 30px;
text-align: center;
line-height: 50px;
font-weight: 300;
}
.row2 {
height: 150px;
background-color: #e4e8eb;
}
.row3 {
background-color: #c7cacf;
padding: 10px 0px;
}
.row3 .text {
font-size: 25px;
text-align: center;
line-height: 25px;
}
.imgsize{
width: 100%;
height: 100%;
}
<div class="container">
<div class="column1">
<img src="http://placehold.it/300x318" class="imgsize">
</div>
<div class="column2">
<div class="row1">
<div class="text">
UNIKE GUSTAVIANSKE STILMØBLER.</div>
<div class="text">VI SELGER HÅNDVERK ETTER 1700-</div>
<div class="text">OG 1800-TALLS TRADISJONER.
</div>
</div>
<div class="row2"></div>
<div class="row3">
<div class="text">Åpningstider:
<br>Man - Fre 11 -17 Lør 11- 15</div>
</div>
</div>
<div class="column3">
<img src="http://placehold.it/300x318" class="imgsize">
</div>
</div>
If I'm understanding properly you can add this to your styles:
img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
Your columns are already filling to the parent height. Using the above css styles the images in this will fill the parent div height and basically overflow the width. If you do something else like set height of the images to 100% it will distort the image.
Here is a similar question with same (but more detailed) answer. https://stackoverflow.com/a/26967278/3366016