I'm learning basic HTML 5 and CSS by myself, and I've been using div instead of table as recommended by many bloggers and web developers. But now I'm with this question:
I'm trying to make a table looks like this:
(source: webdesign-gm.co.uk)
Using this code:
CSS
.table {
font-size:14px;
border-style:solid;
border-width:2px;
margin:0;
padding:3px;
text-align:center;
vertical-align:middle;
display:table-cell;
font-family:Verdana, Geneva, sans-serif;
font-weight:bold;}
HTML
<div align="center">
<div id="row1">
<div class="table" style="min-width:500px;max-width:500px;">Random Number: <?php echo $gRandNum; ?></div>
</div>
<div id="row2" style="min-height:140px;">
<div id="row2column1" style="float:left;">
<div id="row2column1row1">
<div class="table" style="border-top-style:none;border-right-style:none;min-width:150px;">test1</div>
</div>
<div id="row2column1row2">
<div class="table" style="border-top-style:none;border-right-style:none;min-width:150px;">test2</div>
</div>
</div>
<div class="table" style="border-top-style:none;min-width:350px;">
test3<br>test3<br>test3<br>test3<br>test3<br>test3
</div>
</div>
<div id="row3" style="width:500px;">
<div class="table" style="min-width:500px;max-width:500px;border-top-style:none;">teste</div>
</div>
http://jsfiddle.net/XxRJe/2/
The row2 was supposed to have 2 columns inside of it. And the first column divided in another 2 rows, and each row would have 50% of the row2 height. But that is what is not happening. How do I fix it?
Basically, I want two columns, and the first divided in 2 rows, but I have no idea on how to set it.
Hi check this code i tried to fix your problem http://jsfiddle.net/XxRJe/13/. To handle heights on divs with % you need to be carefull because to make it work all his parents need to have a height on % or px to set it.
Here the css
.table {
font-size:14px;
border-style:solid;
border-width:2px;
text-align:center;
font-family:Verdana, Geneva, sans-serif;
font-weight:bold;
}
#row2 {
height:300px;
width:500px;
}
#row2column1, #row2column2 {
width:50%;
height:100%;
color:#fff;
background-color:#000;
}
#row2column1 .celd{
height:50%;
background-color:#666;
}
and HTML
<div>
<div id="row1">
<div class="table" style="min-width:500px;max-width:500px;">Random Number:<?php echo $gRandNum; ?></div>
</div>
<div id="row2" style="min-height:140px;">
<div id="row2column1" style="float:left;margin:auto;">
<div id="row2column1row1" class="celd">
<div class="celd">test1</div>
</div>
<div id="row2column1row2" class="celd">
<div class="celd">test2</div>
</div>
</div>
<div id="row2column2" style="float:right">
test3<br>test3<br>test3<br>test3<br>test3<br>test3
</div>
</div>
<div id="row3" style="width:500px;">
<div class="table" style="min-width:500px;max-width:500px;border-top-style:none;">teste</div>
</div>
</div>
If you need some more complex elements you have to play with % an dinamic heights.
An additional tip donĀ“t set styles inline make it all in the css file
Related
I have a table with height 100% and three rows, the first and last ones have a fixed height, and the one in the middle has no specific height so it stretches to the necessary height.
The problem is that if you fill that row with too many items, the table will be too big and it will exceeds the 100%.
<div id="wrapper">
<div id="first" class="row">
<div>
first
</div>
</div>
<div id="second" class="row">
<div>
<div style="height:50px">
cont0
</div>
<div style="height:50px">
cont1
</div>
<div style="height:50px">
cont2
</div>
<div style="height:50px">
cont3
</div>
<div style="height:50px">
cont4
</div>
<div style="height:50px">
cont5
</div>
</div>
</div>
<div id="first" class="row">
<div>
last
</div>
</div>
html, body {height:100%; margin:0; padding:0;}
#wrapper{
width:300px;
height:100%;
display:table;
}
.row
{
display:table-row;
}
#first
{
height:50px;
margin-bottom:5px;
background-color:#F5DEB3;
}
#second{
background-color:#9ACD32;
}
#second > div{
height:100%;
border: 1px solid red;
overflow-y: auto;
}
It's difficult to explain, but this fiddle demonstrates it: http://jsfiddle.net/3EjX8/127/
Resize the table with your mouse in chrome and it will behave nice (scrollbar appears inside the table).
But resize it in firefox and it will have this unexpected behavior.
Maybe I'm wrong and I'm taking good part of a chrome's bug.
I'm just wondering if there is a possibility to make this behave in firefox as it does on chrome.
Thanks.
I made it work on both firefox, chrome.
Don't use display: table for this, not necessary
You had the id "first" two times.
You don't need divs inside divs
Use 'calc' it's a life saver.
http://jsfiddle.net/foreyez/p3rcyofk/
<div id="wrapper">
<div id="first" class="row">
first
</div>
<div id="second" class="row">
<div>
<div style="height:50px">
cont0
</div>
<div style="height:50px">
cont1
</div>
<div style="height:50px">
cont2
</div>
<div style="height:50px">
cont3
</div>
<div style="height:50px">
cont4
</div>
<div style="height:50px">
cont5
</div>
</div>
</div>
<div id="last" class="row">
last
</div>
</div>
html, body {height:100%; margin:0; padding:0;}
#wrapper
{
width:300px;
height:100%;
}
#first,#last
{
height:50px;
background-color:#F5DEB3;
}
#second{
background-color:#9ACD32;
}
#second {
height:calc(100% - 100px);
border: 1px solid red;
overflow-y: auto;
}
I have two elements on my page which I wish to align side by side, what would be the best way of going about this, and can somebody explain the best way to go about coding it when you want to align elements together.
In this example I want the video to take up most of the room say 3/4 and the chart to be in the remaining 1/4. (Bootstrap is loaded on this page)
Any suggestions?
This is what it currently looks like:
http://i1057.photobucket.com/albums/t390/Alexwileyy/element_zps066ecdd2.png
(I have outlined the video in a color so I can see the perimeters)
This is my HTML code for the two elements:
<!--Video Section-->
<div class="video">
<div class="container">
<div class="video-element">
<iframe width="460" height="215" src="//www.youtube.com/embed/PdABTJhRTLY" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
<!--End Of Video Section-->
<!--Start of chart-->
<div class="container">
<div class="chart">
<div class="chart-cont">
<h1 id="chart-header">Charts</h1>
</div>
<div class="chart-cont">
<h1>1</h1>
<img src="http://www.spotlightreport.net/wp-content/uploads/2013/06/gran-tourismo-6-banner-3.jpg">
View Review</td>
</div>
<div class="chart-cont">
<h1>2</h1>
<img src="http://savegameonline.com/wp-content/uploads/2013/05/CoD-Ghosts-banner.png">
View Review</td>
</div>
<div class="chart-cont">
<h1>3</h1>
<img src="http://bit.ly/1tSu4iq">
View Review</td>
</div>
<div class="chart-cont">
<h1>4</h1>
<img src="http://www.spotlightreport.net/wp-content/uploads/2013/06/gran-tourismo-6-banner-3.jpg">
View Review</td>
</div>
<div class="chart-cont">
<h4>View More..</h4>
</div>
</div>
</div>
<!--End of chart-->
This is my CSS code for my two elements:
.chart {
background-color:white;
width:400px;
margin-bottom:10px;
margin-top:-35px;
}
.chart-cont * {
display:inline;
}
.chart-cont {
padding:10px;
box-shadow: 0 2px 5px rgba(26,26,26,0.75);
text-align:center;
}
.chart-cont img {
width:180;
height:60px;
}
.chart-cont h1 {
vertical-align:middle;
}
Any answers greatly appreciated.
First if you want to work with 3/4 of the screen, start using a percentage as width.
First create a content Div, then a LeftContent and a RightContent div.
Like this:
<div class="Content">
<div class="LeftContent">
</div>
<div class="RightContent">
</div>
</div>
CSS:
.Content{
width:100%;
margin:10px;
padding:10px;
}
.LeftContent{
width:60%;
margin:10px;
float:left;
}
.RightContent{
width:30%;
margin:10px;
float:right;
}
Now you can place the video left, and the other images right, adjust how you want to with padding, margin and width percentage, test with making your window smaller (how it looks like on smaller screens).
Notice to make use of float left and float right.
Here is JSFiddle link: http://fiddle.jshell.net/7pp7q/1/
I am trying to achieve what is shown in the below picture.
Found a few links online, where people have suggested to use table-cell. Tried it, but not getting the exact result. Are there any better standard ways to achieve this ? Please suggest.
Tried code:
CSS
.left, .right{
display:table-cell;
HTML
<div class=left>
<div> Cell A text ... </div>
<div> Cell B text ... </div>
</div>
<div class=right>
<div> Cell C text ... </div>
</div>
Why not do:
Demo Fiddle
HTML
<div class='table'>
<div class='cell'>
<div class='table'>
<div class='cell'>Cell A</div>
</div>
<div class='table'>
<div class='cell'>Cell B</div>
</div>
</div>
<div class='cell'>Cell C</div>
</div>
CSS
.table {
display:table;
width:100%;
}
.cell {
display:table-cell;
border:1px solid black;
width:50%;
height:100px;
vertical-align:middle;
}
Add right column vertical-align: middle; property to your existing solution. Demo
I only need one column on my index page and I want it to be on the right side of the screen. I am using a background image that has what I want on the left. bg-image is in the body
I am trying this approach but it is not getting all the way to the right. Am I going about this wrong and more generally how do you position one column to the right of the screen?
<div style=" float:right" >
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>
</div>
css for the four inner divs
body{
background-image: url(images/splashpage.jpg);
background-position:top;
font-family: Arial, Helvetica, sans-serif;
}
.one{
<!-- width:40%; -->
background-color:lightblue;
font-family: Arial, Helvetica, sans-serif;
position:relative;
<!-- left:150px; -->
}
.two{
width:580px;
background-color:lightgreen;
position:relative;
right:100px;
top:50px;
}
.three{
width:600px;
background-color:blue;
position:relative;
right:100px;
}
.four{
width:580px;
position:relative;
left:20px;
margin: 0 auto;
top:50px;
}
.footer{
width:580px;
text-align:center;
position:relative;
top:50px;
this was working fine for the containing div to float right, but all this was doing was putting the inner divs side by side and I need them to stack.
<div style=" float:right" class="container" >
<div class="one" style="float:right"></div>
<div class="two" style="float:right"></div>
<div class="three" style="float:right"></div>
<div class="four" style="float:right"></div>
</div>
so I put a clear div in between each and now the container div floats right as well as the inner divs while stacking. It seems simple now but maybe if someone else has this problem this will help.
<div style=" float:right" class="container" >
<div class="one" style="float:right"></div>
<div style="clear:both"></div>
<div class="two" style="float:right"></div>
<div style="clear:both"></div>
<div class="three" style="float:right"></div>
<div style="clear:both"></div>
<div class="four" style="float:right"></div>
</div>
not sure if its best practice or if there's a more efficient way but it works.
I've had page layout made via an Html table in my home page.
the lay out was fine , though i was reading that tables are not the way to go (SEO and maybe not only that)
so i need to use divs, the layout is as follows
(i am in RTL Lang /style /direction)
My Question is
Could anyone Try and simplify how to or give an example for a lay out like that
and in more detailed explained :
i think "my life" was so simple, when i had to understand the structure of a table
so, for illustration purpose take this markup:
<table>
<tr> <td>1</td> <td>2</td> </tr>
<tr> <td>3</td> <td>4</td> </tr>
</table>
here you don't need to think much to analyze that this will be 2 by 2 table
but when it comes to divs i get no results laying them as i plan to
i would like to know how do i make that simple as it was with a table for me .
2 now that i am trying to achieve that layout via divs (no table involved )
and to make it work so that layout will be Cross Browser, meaning will look same
at least for the 3 main browsers IE8&9 / FF / Chrome (only my preference)
thanks in advance
I tried hard to make template like what you want.I hope you will like it.See my layout
by division tag.I am attaching a screen shot as well that is created on the base of
my div logic.I think it will be clear for you.
<div id="main" >
<div style="background-color:Blue; text-align:center; ">
Main banner
</div>
<div style="background-color:Green; text-align:center; " >
Top menu
</div>
<div style="background-color:Gray; text-align:center; width:300px; float:right; height:200px; " >
Right side menu
</div>
<div style="background-color:Red; text-align:center; height:200px;" >
<div style="background-color:Fuchsia; text-align:center; width:300px; float:right; height:100px; ">
contend2
</div>
<div style="background-color:Lime; text-align:center;height:100px; ">
contend1
</div>
<div style="background-color:Aqua; text-align:center; width:300px; float:right; height:100px; ">
contend4
</div>
<div style="background-color:Orange; text-align:center;height:100px; ">
contend3
</div>
</div>
<div style="background-color:Silver; text-align:center; " >
Footer
</div>
</div>
**In case if you want external css then use**
<div id="main" >
<div id="mainbanner">
Main banner
</div>
<div id="topmenu" >
Top menu
</div>
<div id="rsm" >
Right side menu
</div>
<div id="maincontend" >
<div id="c2" >
contend2
</div>
<div id="c1">
contend1
</div>
<div id="c4">
contend4
</div>
<div id="c3">
contend3
</div>
</div>
<div id="footer">
Footer
</div>
</div>
**CSS................**
#Main
{
}
#mainbanner
{
background-color:Blue;
text-align:center;
}
#topmenu
{
background-color:Green;
text-align:center;
}
#rsm
{
background-color:Gray;
text-align:center;
width:300px;
float:right;
height:200px;
}
#maincontend
{
background-color:Red;
text-align:center;
height:200px;
}
#c2
{
background-color:Fuchsia;
text-align:center;
width:300px;
float:right;
height:100px;
}
#c1
{
background-color:Lime;
text-align:center;
height:100px;
}
#c4
{
background-color:Aqua;
text-align:center;
width:300px;
float:right;
height:100px;
}
#c3
{
background-color:Orange;
text-align:center;
height:100px;
}
#footer
{
background-color:Silver;
text-align:center;
}
You can't ask for complete layouts, but I wrote two tutorials that will definitely help you acquire the skill required to make them: How to Position in CSS and Create a Fixed ('Sticky') Footer with CSS.
Check this
<div id="wrapper">
<div id="header">
<p>This is the Header</p>
</div>
<div id="navigation">
<p>This is the Menu</p>
</div>
<div id="leftcolumn">
<div class="row">
<div>1st block</div>
<div>2nd block</div>
</div>
<div class="row">
<div>3rd block</div>
<div>4th block</div>
</div>
</div>
<div id="rightcolumn">
sfsf
</div>
<div id="footer">
<p>This is the Footer</p>
</div>
</div>
DEMO
HTML-Cleaner has a nice feature to replace HTML tables with DIVs: http://www.html-cleaner.com/features/replace-html-table-tags-with-divs/
Make sure you include the css code supplied.