I am having a major problem trying to create in-line tables with divs instead of tables and CSS. My issue is that I have 3 types of rows that aren't really in sync, so expectedly, do not line up. I am wondering if there is a solution or a better approach.
As you'll see in the fiddle, I am trying to get the header, row, and child row to line up. All columns and headers have the same width %, but their overall widths will be different. Also, the child row should be indented to appear under the parent.
Fiddle
http://jsfiddle.net/b6ptag0b/15/
HTML
<div id = "wrapper">
<div id = "headers">
<div class = "col header_name">Name</div>
<div class = "col header_id">ID</div>
<div class = "col header_country">Country</div>
</div>
<div id = "table">
<div class = "row" data-id = "1">
<div class = "col button">+</div>
<div class = "col name">Bob Dolle</div>
<div class = "col id">1234</div>
<div class = "col country">America</div>
</div>
<div class = "row_child" data-parent = "1">
<div class = "col name">Joe Dolle</div>
<div class = "col id">67788</div>
<div class = "col country">America</div>
</div>
</div>
CSS
#headers{
background-color:#ccc;
}
.row{
background-color:#ddd;
}
.row_child{
background-color:#AAA8A8;
margin-left:40px;
}
.col{
display:inline-block;
}
#table{
padding:5px;
}
.header_name, .name{
width:30%
}
.header_id, .id{
width:10%;
}
.header_country, .country{
width:25%;
}
.button{
padding:0 10px;
}
well, despite the "use tables" argument (I can see why you want to use DIVS), what you want to do is incredibly easy with CSS, but you're using a really convoluted logic. You can use a columns approach instead of rows, or using your rows approach, just give each columns the same width and include the .button class in the same div as the name , then simply add some table logic to your divs
#table, #headers {
display:table;
width:100%;
}
.row {
display:table-row;
width:100%;
}
.col {
display:table-cell;
width:30%;
}
#headers {
background-color:#ccc;
}
.row {
background-color:#ddd;
}
.row_child {
background-color:#AAA8A8;
margin-left:40px;
}
.header_id, .id {
width:10%;
}
.header_country, .country {
width:25%;
}
.button {
padding:0 10px;
float:left;
}
.row_child .name {
padding-left:50px;
}
See fiddle here
Modern browsers will allow you to use new CSS Table Layouts, for example:
Fiddle
http://jsfiddle.net/b6ptag0b/30/
HTML
<div id = "wrapper">
<div id = "headers">
<div class = "col header_name">Name</div>
<div class = "col header_id">ID</div>
<div class = "col header_country">Country</div>
</div>
<div class = "row" data-id = "1">
<div class = "col name">Bob Dolle</div>
<div class = "col id">1234</div>
<div class = "col country">America</div>
</div>
<div class = "row_child" data-parent = "1">
<div class = "col name">Joe Dolle</div>
<div class = "col id">67788</div>
<div class = "col country">America</div>
</div>
</div>
CSS
#wrapper{
display: table;
}
#headers{
background-color:#ccc;
display: table-row;
}
.row{
background-color:#ddd;
display: table-row;
}
.row_child{
background-color:#AAA8A8;
display: table-row;
}
.col{
display: table-cell;
padding: 2px;
}
Related
Just a quick on in relation to the following site:
christmas.drcrittall.com
My question, is why despite the following CSS:
html, body {
height:100%;
}
/* Background image for website */
body {
/*background: url("images/crumpled.jpg") no-repeat center center fixed;*/
background: url("../img/crumpled.jpg") no-repeat;
background-size: 100% 100%;
/*margin-bottom:5%;*/
}
#header {
height:20%;
border-style: solid;
border-color:red;
/*padding:0px; */
}
#middle {
height:60%;
/* border-style: solid;
border-color:green;*/
}
#cap {
height:20%;
border-style: solid;
border-color:blue;
/* Previously the click here text was overflowing out of this div. See here to see how to deal with this: https://css-tricks.com/almanac/properties/o/overflow/ */
/*overflow:auto;*/.
}
#form {
min-height:20%; /* Setting min-height of white-space beneath body enables container to expand with the form as it gets bigger */
display:none; /* This div is initially hidden until click button which activates jquery animation */
}
#main_image {
max-width:100%;
max-height:60vh; /*Set max and min heights to 60vh to lock within this container ie stop images expanding out */
min-height:60vh;
}
#candle_image {
width:100%;
height:100%;
}
#top_paper {
width:100%;
max-height:100%;
}
/* Make row height and columns fill entire height of containers */
.row, .col-md-6, .col-md-4, .col-md-6, .col-md-12, .col-md-8, .col-md-2, .col-md-3, {
height:100%;
}
Does the row within #cap and #head not fill 100% of the height? I have used flex box to center the font within the header, but can not seem to do the same with the cap... Here is the HTML:
<body>
<div class = "container-fluid center_font" id = "header">
<div class = "row" style = "border-style: solid; border-color:black;">
<div class = "col-md-12 col-xs-12">
<font id = "dear"> Merry Christmas! </font>
</div>
</div>
</div>
<div class = "container-fluid center_font" id = "middle">
<div class = "row"><!-- style = "border-style:solid; border-color:black;">-->
<div class = "col-md-3" id = "holly_1" style = "padding-top:10%;">
<img src = "../img/candles.png" id = "candle_image" class = "img-fluid">
</div>
<div class = "col-md-6 col-xs-12 center_font"><!-- style = "border-style:solid; border-color:yellow;">-->
<img src = "" id = "main_image" class = "img-circle">
</div>
<div class = "col-md-3" id = "holly_2" style = "padding-top:10%;">
<img src = "../img/candles.png" id = "candle_image" class = "img-fluid">
</div>
</div>
</div>
<div class = "container-fluid" id = "cap"><!-- style = "border-style:solid; border-color:green;">-->
<div class = "row" style = "border-style: solid; border-color:black;">
<div class = "col-md-offset-3 col-md-6 col-xs-12 center_font">
<font class = "ammend" id = "dear" style = "font-size:45px;"> Love from Matthew</font><br>
<!--<a href = "#" id = "reveal">
<font id = "dear" class = "fiddle" style = "font-size: 20px;">Click Me</font>
</a>
-->
</div>
<div class = "col-md-offset-3 col-md-6 col-xs-12 center_font">
<a href = "#" id = "reveal">
<font id = "dear" class = "fiddle" style = "font-size: 20px;">Click Me</font>
</a>
</div>
</div>
</div>
</body>
Font size is too big and collapses the offset columns, and you are missing center_font class on #cap.
Add center_font class to #cap.
Change font-size from 45px to less or equal than 36px on font#dear.ammend to keep 1 line of text ("Love from Matthew").
I am new to this forum. I encountered some issues when I was programming a file list display for my education portal.
Here are the codes (part of the whole page):
HTML
<div id = "mcMid">
<div id = "mcMidContainer" class = "tpWhite6">
<div id = "path">
Folder: ROOT
</div>
<div id = "top">
<div id = "name" class = "block1">Name</div>
<div id = "owner" class = "block2">Owner</div>
<div id = "date" class = "block3">Date</div>
<div id = "Delete" class = "block4">X</div>
</div>
<div id = "files">
<div id = "file1" class = "rollOverFBlueFile">
<div id = "name1" class = "block1">Determination of p value</div>
<div id = "owner1" class = "block2">Nguyen Chan</div>
<div id = "date1" class = "block3">2014-05-03</div>
<div id = "Delete1" class = "block4">X</div>
</div>
<div id = "file2" class = "rollOverFBlueFile">
<div id = "name2" class = "block1">Econ Module 1</div>
<div id = "owner2" class = "block2">Joyce</div>
<div id = "date2"class = "block3">2014-05-03</div>
<div id = "Delet2" class = "block4">X</div>
</div>
<?php for ($i=3;$i<$_GET['times'];$i++) { ?>
<div id = "file<?php echo $i; ?>" class = "rollOverFBlueFile">
<div id = "name<?php echo $i; ?>" class = "block1"">Econ Module 2</div>
<div id = "owner<?php echo $i; ?>" class = "block2">Joyce</div>
<div id = "date<?php echo $i; ?>" class = "block3">2014-05-03</div>
<div id = "Delet<?php echo $i; ?>" class = "block4">X</div>
</div>
<?php } ?>
</div>
</div>
</div>
CSS
#mcMid {
float:left;
display:flex;
flex:1;
flex-direction:column;
border-width:1px;
border-left-color:#666;
border-right-color:#666;
border-left-style:solid;
border-right-style:solid;
}
#mcMidContainer {
width:100%;
flex:1;
padding:0px 0px;
}
#path {
width:calc(100% - 20px);
height:auto;
padding:10px 10px;
background-color:#CCC;
}
#top {
width:100%;
height:auto;
padding:5px 0px;
background-color:#EEE;
font-size:12px;
overflow:auto;
}
#files {
width:100%;
flex:1;
overflow:auto;
}
.block1 {
width:calc(50% - 10px);
padding:5px 5px;
height:auto;
float:left;
}
.block2 {
width:calc(20% - 10px);
padding:5px 5px;
height:auto;
float:left;
}
.block3 {
width:calc(20% - 10px);
padding:5px 5px;
height:auto;
float:left;
}
.block4 {
width:5%;
padding:5px 0px;
height:auto;
float:left;
}
.rollOverFBlueFile {
background-color:#FFF;
border-width:1px;
border-bottom-style:solid;
border-color:#999;
width:100%;
height:auto;
padding:5px 0px;
font-size:12px;
overflow:auto;
}
.rollOverFBlueFile:hover {
background-color:#5BADFF;
}
.tpWhite6 {
background-color:rgba(255,255,255,0.5);
}
When this block of code is run with different values of the "times" variable, there were different results. The problem arises when I get the value of "times" to over a certain value when the div's inside start to exceed the allocated height of the "files" div. The "files" div start to stretch and squeezed the "top" and "path" div's.
Is there any other methods, other than fixing the height of "files", to stop this problem? Many thanks!! ^_^
I am generating a table using my Vertical_Table function. When I remove the table from the div I can adjust the dimensions of the rows and columns but when it is inside the div I cannot change them. Any ideas why? Here is some jfiddle so you can see what I am talking about http://jsfiddle.net/6XAHR/
CSS CODE
> #Pallate
{
border: 1px solid black;
position:relative;
top:40px;
margin:0 auto;
width:1200px;
height:360px;
background-color: #C8C8C8;
}
#Scroll_Table_Border
{
Position:relative;
top:40px;
Left:320px;
border: 1px solid black;
height:275px;
max-width: 850px;
background-color: #C8C8C8;
}
#Scroll_Table {
left:25px;
top:25px;
white-space: nowrap;
Position:Absolute;
height:225px;
max-width: 800px;
width: 100% !important;
overflow:auto;
background-color: #C8C8C8;
}
#Button_Group_Title
{
Position:Absolute;
padding-right:5px;
padding-left:5px;
background-color: #C8C8C8;
top:30px;
Left:35px;
z-index:2;
}
#Scroll_Table_Title
{
Position:Absolute;
padding-right:5px;
padding-left:5px;
background-color: #C8C8C8;
z-index:2;
top:30px;
Left:335px;
}
#Button_Group {
text-align:center;
padding-top:30px;
padding-bottom:15px;
padding-right:25px;
padding-left:25px;
border: 1px solid black;
position:Absolute;
top:40px;
left:20px;
height:230px;
width:200px;
vertical-align: middle;
background-color: #C8C8C8;
}
HTML CODE
<div ID = "Pallate" >
<div ID = "Scroll_Table_Title">Trial Information</div>
<div ID = "Button_Group_Title">View Results</div>
<div ID = "Button_Group">
<input type="button" ID = "Paper_Information" onclick="changeContent(this.id)" value="Paper Information" class = "Class_Button">
<input type="button" ID = "Trial_Information" onclick="changeContent(this.id)" value="Trial Setting" class = "Class_Button">
<input type="button" ID = "Results" onclick="changeContent(this.id)" value="Trial Results" class = "Class_Button">
<input type="button" ID = "Control_Law" onclick="changeContent(this.id)" value="Control Algorithm" class = "Class_Button">
<input type="button" ID = "Exercise" onclick="changeContent(this.id)" value="Exercise" class = "Class_Button">
<input type="button" ID = "Actuator" onclick="changeContent(this.id)" value="Pump Properties" class = "Class_Button">
<input type="button" ID = "Sensor" onclick="changeContent(this.id)" value="Glucose Sensor" class = "Class_Button">
<input type="button" ID = "Blood_Glucose_Safety" onclick="changeContent(this.id)" value="Blood Glucose Safety" class = "Class_Button">
<input type="button" ID = "Reference_Glucose" onclick="changeContent(this.id)" value="Reference Measurements" class = "Class_Button">
</div>
PHP CODE
<div ID = "Scroll_Table_Border">
<div ID = "Scroll_Table">
<?php
$Columns = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_NAME = \'Control_Law\'';
$Columns = sqlsrv_query($dbhandle,$Columns);
$Sets = array(sqlsrv_query($dbhandle, 'SELECT * FROM Control_Law WHERE [Paper ID] = ' . $ID));
$i = 0;
while ($Row = sqlsrv_fetch_array($Columns))
{
$Column_Vector[$i] = $Row[0]; $i++;
}
$Table_ID = 'Advanced_Table';
$Columns_Vector = array($Column_Vector);
Vertical_Table($Columns_Vector,$Sets,'40px','',$Table_ID);
?>
</div>
</div>
#Scroll_Table {
left:25px;
top:25px;
white-space: nowrap; //REMOVE THIS
Position:Absolute;
height:225px;
max-width: 800px;
width: 100% !important;
overflow:auto;
background-color: #C8C8C8;
}
This will get it to drop down then you can set the max width. The problem with the text you have in there now is it is all 1 string with no spaces. Remove the spaces and it will drop down normally. Hope this helps!
Ok, I have 3 columns floating left. Now when the viewport is less than 600px I want column 2 to appear before column 1 without using position:absolute. Is there a way to do this just by using CSS and HTML?
If not you can also post other variants.
Here's my fiddle
Is this what you are after? http://jsfiddle.net/panchroma/dWJ9g/
You will see I've reordered the col1 and col2 in the HTML and applied margin to the #col1 and #col2
HTML
<div id="wrapper">
<div id="header">HEADER</div>
<div id="main">
<div id="col2" class="cols">COL 2</div>
<div id="col1" class="cols">COL 1</div>
<div id="col3" class="cols">COL 3</div>
<div class="clear"></div>
</div>
<div id="footer" class="clear">FOOTER</div>
</div>
CSS changes
#col1 {float:left; height:100px; width:200px; background:#cc4444;margin-left:-400px;}
#col2 {float:left; height:200px; width:200px; background:#44cc44;margin-left:200px;}
#media only screen and (max-width:600px) {
#wrapper, #header, #main, #footer {width:100%;}
#col1, #col2, #col3 {float:none; width:100%;margin-left:0;}
}
Hope this helps!
If you don't want to change the markup I'd suggest using javascript, to change the html and id.
http://jsfiddle.net/FBAtT/
var col1 = document.getElementById('col1'),
col2 = document.getElementById('col2'),
swapped = false;
window.onresize = function () {
var width = window.innerWidth;
if (width < 600 && swapped === false) {
swapCols();
swapped = true;
} else if (width > 600 && swapped === true) {
swapCols();
swapped = false;
}
};
function swapCols() {
var _col1 = col1.innerHTML,
_col1id = col1.id,
_col2 = col2.innerHTML,
_col2id = col2.id;
col1.innerHTML = _col2;
col1.id = _col2id;
col2.innerHTML = _col1;
col2.id = _col1id;
}
try this
http://jsfiddle.net/mKbnH/2/
CSS
html * {margin:0; padding:0;}
body {background:#000; font-family:helvetica, verdana;}
#wrapper {margin:50px auto;}
#wrapper, #header, #main, #footer {width:600px;}
#header {height:100px; background:#cccc44;}
#main {}
#col1 {float:left; height:100px; width:200px; background:#cc4444;}
#col2 {float:left; height:200px; width:200px; background:#44cc44;}
#col3 {float:left; height:150px; width:200px; background:#4444cc;}
#footer {height:50px; background:#cc44cc;}
.cols {}
.clear {clear:both;}
#media only screen and (max-width:600px) {
#wrapper, #header, #main, #footer {width:100%;}
#col3 {width:100%;}
#col1, #col2 {width:50%}
}
I have a square that contains pictures and each picture is supposed to be clickable to take you to that person's profile, but my top left picture is not clickable. I'm not sure what I'm doing wrong.
Here is my jsfiddle so you can see the problem.
<div id = 'crew_div'>
<div class = 'my_crew'><div id = 'jason'><a href = 'http://www.startingtofeelit.com/author/musicmakesmelosectrl/'><img src='http://www.startingtofeelit.com/profile/jason.jpg' title = 'View Posts by Jason'></a></div></div>
<div class = 'my_crew'><div id = 'dharam'><a href = 'http://www.startingtofeelit.com/author/4everevolution/'><img src='http://www.startingtofeelit.com/profile/dharam.png' title = 'View Posts by Dharam'></a></div></div>
<div class = 'my_crew'><div id = 'james'><a href='http://www.startingtofeelit.com/author/jjstiles/'><img src='http://www.startingtofeelit.com/profile/james.png' title = 'View Posts by James'></a></div></div>
<div class = 'my_crew'><div id = 'cody'><a href='http://www.startingtofeelit.com/author/codecray/'><img src='http://www.startingtofeelit.com/profile/Cody.jpg' title = 'View Posts by Cody'></a></div></div>
</div>
#crew_div {
position:relative;
width: 312px;
height:312px;
}
.my_crew {
position:absolute;
}
.my_crew img {
width:156px;
display:block;
}
.my_crew #jason {
top:0px;
left:0px;
position:relative;
}
.my_crew #dharam {
top:0px;
left:156px;
position:relative;
}
.my_crew #james {
top: 156px;
left: 0px;
position:relative;
}
.my_crew #cody {
top:156px;
left:156px;
position:relative;
}
Add a z-index to your image like this :
.my_crew #jason {
top:0px;
left:0px;
position:relative;
z-index: 1;
}
You haven't specified width/height dimensions or top/left positioning for your <div class="my_crew">. They are each positioned at the top-left, and their child <div> is then positioned relative to the absolutely positioned parent. That's why the top-left isn't clickable, because it's really stacked under 3 other <div>s.
A better solution would be to combine the two <div>s into one.
See the fiddle here: http://jsfiddle.net/R4HJb/8/
<div id = 'crew_div'>
<div class = 'my_crew jason'><a href = 'http://www.startingtofeelit.com/author/musicmakesmelosectrl/'><img src='http://www.startingtofeelit.com/profile/jason.jpg' title = 'View Posts by Jason'></a></div>
<div class = 'my_crew dharam'><a href = 'http://www.startingtofeelit.com/author/4everevolution/'><img src='http://www.startingtofeelit.com/profile/dharam.png' title = 'View Posts by Dharam'></a></div>
<div class = 'my_crew james'><a href='http://www.startingtofeelit.com/author/jjstiles/'><img src='http://www.startingtofeelit.com/profile/james.png' title = 'View Posts by James'></a></div>
<div class = 'my_crew cody'><a href='http://www.startingtofeelit.com/author/codecray/'><img src='http://www.startingtofeelit.com/profile/Cody.jpg' title = 'View Posts by Cody'></a></div>
</div>
#crew_div {
position:relative;
width: 312px;
height:312px;
}
.my_crew {
position:absolute;
width: 156px;
height: 156px;
}
.my_crew img {
width:156px;
display:block;
}
.my_crew.jason {
top:0px;
left:0px;
}
.my_crew.dharam {
top:0px;
left:156px;
}
.my_crew.james {
top: 156px;
left: 0px;
}
.my_crew.cody {
top:156px;
left:156px;
}
Here is what you need, I reorganized your HTML a bit :)
New Fiddle
<div id = 'crew_div'>
<a href = 'http://www.startingtofeelit.com/author/musicmakesmelosectrl/'><div class = 'my_crew'><div id = 'jason'><img src='http://www.startingtofeelit.com/profile/jason.jpg' title = 'View Posts by Jason'></div></div></a>
<a href = 'http://www.startingtofeelit.com/author/4everevolution/'><div class = 'my_crew'><div id = 'dharam'><img src='http://www.startingtofeelit.com/profile/dharam.png' title = 'View Posts by Dharam'></div></div></a>
<a href='http://www.startingtofeelit.com/author/jjstiles/'><div class = 'my_crew'><div id = 'james'><img src='http://www.startingtofeelit.com/profile/james.png' title = 'View Posts by James'></div></div></a>
<a href='http://www.startingtofeelit.com/author/codecray/'><div class = 'my_crew'><div id = 'cody'><img src='http://www.startingtofeelit.com/profile/Cody.jpg' title = 'View Posts by Cody'></div></div></a>
Why don't you just float them next to each other? That will also save some lines of CSS.
.my_crew {
float:left;
}
Example: http://jsfiddle.net/T5LCm/