Is it possible to layout span/div in this way? - html

Im generating a table in php, and would like it in the top left of the screen.
The table varies slightly in width so directly to the right of it should go two blocks of text (text1, text2) and a third text (text3) which floats in the topmost right of the screen.
Below the three texts should be text4.
Requirements:
Text1 needs to always be to the right of the table.
text4 always needs to be below the top 3 texts.
I uploaded an image with the span/div/table/text and have literally been trying to arrange these for about 1.5 hours now. it seems like it should be really simple but im struggling with my requirements and one of them always seems to misalign. (all the 'texts' are just pieces of html text (not <input type=text or <textarea>)
Edit: Thankyou, is it possible without using libraries or bootstrap?

If you don't like using <table> tags for layouts, and don't like an extra large dependency to your project (like bootstrap), one could go for the following option:
<div class="table">
Table
</div>
<div class="text-container">
<div class="text1">
Text1
</div>
<div class="text2">
Text2
</div>
<div class="text3">
Text3
</div>
<div class="text4">
Text4
</div>
</div>
It is crucial that the display type of .table, .text-container and .text{1,2,3} are all display: inline-block;. This will make them inline. However, to force wrapping of .text4, this will still have to be display: block;.
https://jsfiddle.net/nnLofpL1/
Like hjardine uses in his example: it may also be a good idea to look to the clear property.

However it is not the nicest solution, the classic "table in table" does the job:
<table>
<tr>
<td>
<table>
<tr>
<td>PHP generated data</td>
</tr>
</table>
</td>
<td>
<table>
<tr style="height: 60px;">
<td>Text 1</td>
<td style="padding-left: 100px;">Text 2</td>
<td style="width: 200px; text-align: right;">Text 3</td>
</tr>
<tr style="height: 60px;">
<td colspan="3">Text 4</td>
</tr>
</table>
</td>
</tr>
</table>
https://jsfiddle.net/jrrfbqfk/

I can see you don't want to use bootstrap so i have updated an answer so that you don't have to use a table either, exact same output but without the problems of using a table for output.
.div1{float:left;width:40%;border:1px solid #000;min-height:200px;}
.div2{float:right;width:58%;border:1px solid #000;min-height:200px;}
.row1{min-height:100px;}
.sp1{float:left;width:30%;padding:4px;border:1px solid #000;min-height:60px;}
.sp2{float:left;width:30%;padding:4px;border:1px solid #000;min-height:60px;}
.sp3{float:right;width:30%;text-align:right;padding:4px;border:1px solid #000;min-height:60px;}
.divRow{width:100%;border: 1px solid #000;}
<div>
<div class="div1">
<div class="divRow">1</div>
<div class="divRow">2</div>
<div class="divRow">3</div>
<div class="divRow">4</div>
<div class="divRow">5</div>
<div class="divRow">6</div>
</div>
<div class="div2">
<div>
<div class="row1">
<div class="sp1">1</div>
<div class="sp2">2</div>
<div class="sp3">3</div>
<div style="clear:both;"></div>
</div>
<div class="row2" style="border:1px solid #000;min-height:40px;">
sadsadsad
</div>
</div>
</div>
<div style="clear:both;">
</div>
</div>
An easy solution to laying out a page so that things are where you want them is using bootstrap, because of the grid layout in bootstrap you can keep things in the same relative positions no matter what the size of the page is.
For what you want to do i think it would benefit you greatly.
EXAMPLE
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<div class="Container">
<div class="row">
<div class="col-xs-2">
Top left
</div>
<div class="col-xs-2 col-xs-offset-8">
Top right
</div>
</div>
</div>
This is a link to Bootstrap which is well worth learning IMHO!

Related

Is there a way I can contain an image and content in a separate container using HTML / inline CSS / Markdown

Looking to have an image on the left side of a container, however, if the content is too short or too long I'd have to adjust the height of the image proportionally to prevent the content from sliding below the image. The reason I want to contain the Image and the content in the container is to ensure that the image is coherent throughout the entirety of the pages.
We can use HTML / in-line CSS / Markdown to make this adjustment. Perhaps I believe we may need to use Flexbox
I've attached the code below, I've used Grid and a table, and I don't really like it
<div style=“display:grid; grid-template-columns:auto 1fr”>
<div>
<h1> <img src=“https://image.shutterstock.com/image-vector/sample-stamp-grunge-texture-vector-260nw-1389188336.jpg”
align=“left”
hspace=“30"
width=“100”
height=“100">
</div>
<div>
<h3>TITLE</h3>
Description for Title
<table>
<tr>
<td><strong>BLAH:</strong></td>
<td style=“padding-left:20px”><p>Updates are made annually or more frequently if needed<p/></td>
</tr>
<tr>
<td style=“vertical-align:top”><strong>Contact Us:</strong></td>
<td style=“padding-left:20px”>
<ul style=“padding-left: 15px; margin: 0px”>
<li style=“padding-bottom: 10px”><a href=“mailto:sample#email.com”>Email: Jane Doe</a></li>
<li><a>Skype: Sample</a></li>
</ul>
</br>
</td>
</tr>
</table>
</div>
</div>
--Most Recent
The image is on the left side but the table seems to overlap the image
This is what it currently looks like
edit 2
I've edited this again for you if this needs to be inline styles, i've gave a class name on the different containers so you can clearly see how this is working,
your image can just go into image-container and your content can go in content-container. You can add size to the containers, padding, margin etc.. to adjust the layout that you want, but this should help with the basic setup for your HTML.
<div class="main-container" style="display: flex;">
<div class="image-container">
<img
src=“https://image.shutterstock.com/image-vector/sample-stamp-grunge-texture-vector-260nw-1389188336.jpg”
hspace="30" width="100" height="100">
</div>
<div class="content-container">
<h3>TITLE</h3>
<h4>Description for Title</h4>
<table>
<tr>
<td><strong>BLAH:</strong></td>
<td style="padding-left: 20px;">
<p>Updates are made annually or more frequently if needed</p>
</td>
</tr>
<tr>
<td style="vertical-align: top;"><strong>Contact Us:</strong></td>
<td style="padding-left: 20px;">
<ul style="padding-left: 15px; margin: 0;">
<li style="padding-bottom: 10px;">
Email: Jane Doe
</li>
<li><a>Skype: Sample</a></li>
</ul>
</td>
</tr>
</table>
</div>
</div>
Here a flexbox example:
HTML
<div style="display: flex; flex-flow: row nowrap;">
<div style="flex: 1 auto;">
<img src=“https://image.shutterstock.com/image-vector/sample-stamp-grunge-texture-vector-260nw-1389188336.jpg” hspace="30" width="100" height="100">
</div>
<div style="flex: 1 auto;">
<h3>TITLE</h3>
Description for Title
<table>
<tr>
<td><strong>BLAH:</strong></td>
<td style=“padding-left:20px”>
<p>Updates are made annually or more frequently if needed
<p />
</td>
</tr>
<tr>
<td style=“vertical-align:top”><strong>Contact Us:</strong></td>
<td style=“padding-left:20px”>
<ul style=“padding-left: 15px; margin: 0px”>
<li style=“padding-bottom: 10px”><a href=“mailto:sample#email.com”>Email: Jane Doe</a></li>
<li><a>Skype: Sample</a></li>
</ul>
</td>
</tr>
</table>
</div>
</div>
DEMO HERE

Overflowing layout with flexbox and bootstrap3 columns causing undesired page width increase

I have a layout making use of twitter-bootstrap-3 columns and flexbox.
At a highlevel, the layout I am trying to achieve is like this:
The toolbar and the rest of the content are flexed next to each other (dashed boxes are the children of the flex):
The non-toolbar sections (the green, blue and yellow boxes) are one bootstrap3 row, with three columns (columns are dashed boxes). On large screens the layout should be like the image (meta + main content is col-md-7, secondary #1 is col-md-5, secondary #2 is col-md-12), but defaulting to separate rows on small screens (all col-sm-12):
Finally, the meta and main content (the green and blue boxes) are flexed next to each other (dashed boxes are the children of the flex):
The tricky part is that the main content (the blue section) can get quite wide and must scroll horizontally. The issue I am running into is that as the overflowing content section gets larger, it seems to push the screen artificially wide and escape the boundaries of the bootstrap column.
Here is a simplified example showcasing the issue. (You might have to click "Full page" link to see the overflow issue.)
Is there any way to get around this issue?
.flex {
display: flex;
}
.flex-variable {
flex: 1 1 auto;
/*flex:1;*/
}
.w-100 {
width: 100%;
}
.overflowable-h {
overflow-x: auto;
}
div {
border: 1px gray solid;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<h1>overflowing content</h1>
<div class="flex">
<div>toolbar</div>
<div class="flex-variable">
<div class="row">
<div class="col-md-7">
<div class="flex">
<div class="text-nowrap">
<table>
<tr>
<td>metadata</td>
<td>metadata</td>
</tr>
<tr>
<td>metadata</td>
<td>metadata</td>
</tr>
</table>
</div>
<div class="flex-variable w-100 text-nowrap overflowable-h">
<table>
<tr>
<td>content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content-content</td>
</tr>
<tr>
<td>content-content-content-content-content-content-content-content-content</td>
</tr>
</table>
</div>
</div>
</div>
<div class="col-md-5">
<div>secondary-secondary-secondary-secondary-secondary-secondary</div>
</div>
<div class="col-md-12">secondary-secondary-secondary-secondary-secondary-secondary-secondary-secondary-secondary</div>
</div>
</div>
</div>
<h1>no overflowing content</h1>
<div class="flex">
<div>toolbar</div>
<div class="flex-variable">
<div class="row">
<div class="col-md-7">
<div class="flex">
<div class="text-nowrap">
<table>
<tr>
<td>metadata</td>
<td>metadata</td>
</tr>
<tr>
<td>metadata</td>
<td>metadata</td>
</tr>
</table>
</div>
<div class="flex-variable w-100 text-nowrap overflowable-h">
<table>
<tr>
<td>content-content</td>
</tr>
<tr>
<td>content-content-content</td>
</tr>
</table>
</div>
</div>
</div>
<div class="col-md-5">
<div>secondary-secondary-secondary-secondary-secondary-secondary</div>
</div>
<div class="col-md-12">secondary-secondary-secondary-secondary-secondary-secondary-secondary-secondary-secondary</div>
</div>
</div>
</div>
</div>
</body>
</html>
if i understand correct, try this:
add and modify your css like below: (toolbar can have any fixed width px/rem/vw/percent and Your flex-variable should calc available width based on toolbar width)
#toolbar{width:200px;}
.flex-variable {
flex: 1 1 auto;
width: calc(100% - 200px);
}
and add id to toolbard div
<div id="toolbar">toolbar</div>
You can achive this in many ways, but your container should have some width to not overflow.

Using div with display table-cell inside real tables td

I have a complicated layout created with real tables and it works fine but now I created a new layout using DIVS and it worked fine until I tested height on cellphones and it looks pretty bad, it just don't want to keep my height 100% tested also set footer to margin bottom 0 and nothing so I will test the follow:
<table style="width:100%;height:100%;border:0;border-spacing:0px;border-collapse:collapse;">
<tr>
<td style="height:21px;">
<DIV style="display: table-cell;"> divvvvv </div></td>
</tr>
<tr>
<td style="height:79px;"">
</td>
</tr>
<tr>
<td style="height:100%;"> </td>
</tr>
<tr>
<td style="height:21px;"> </td>
</tr>
</table>
The question is, can I add those divs inside the table TD element without adding div-display-table and div-display-row before? It seems like the best way to go for me is to mix tables and divs. What would then be the correct way of mixing them? Because TDs in Tables will not respect the height and width neither so I must use both tables and divs seems like ...
Like this:
<div class="container">
<div class="row">
<div class="column">Column 1</div>
<div class="column">Column 2</div>
<div class="column">Column 3</div>
</div>
<div class="row">
<div class="column">Column 1</div>
<div class="column">Column 2</div>
<div class="column">Column 3</div>
</div>
</div>
Mixing in table elements with divs is eventually going to give you a headache, especially when it comes to responsive design. For this same issue, I use Bootstrap CSS. They have a grid system that is extremely effective in replacing table-style layouts and adapting to mobile devices. Your target HTML is actually really close to the markup that Bootstrap uses, so your head is obviously int he right place!
After downloading the Bootstrap js and css, I would do something like this:
<!-- the container-fluid class creates a full-width container -->
<div class="container-fluid">
<!-- the row class creates a row broken into 12 columns. -->
<div class="row">
<!-- specify how many columns an element should take up out of 12 for each given device. below is the markup for 3 evenly-spaced columns for a medium (desktop) device -->
<div class="col-md-4">Column 1</div>
<div class="col-md-4">Column 2</div>
<div class="col-md-4">Column 3</div>
</div>
<div class="row">
<div class="col-md-4">Column 1</div>
<div class="col-md-4">Column 2</div>
<div class="col-md-4">Column 3</div>
</div>
</div>
I tried to understand what you are wanting but it wasn't very clear...so this is what I assumed you meant.
DEMO
CSS:
.container {
display:table;
height:200px;
border:1px solid red;
}
.column {
display:inline-block;
}
table {
border: 1px solid black;
}
td {
width:150px;
border: 2px solid blue;
}
HTML:
<table style="width:100%;height:100%;border:0;border-spacing:0px;border-collapse:collapse;">
<tr>
<td style="height:21px;">
<div class="container">
<div class="row">
<div class="column">Column 1</div>
<div class="column">Column 2</div>
<div class="column">Column 3</div>
</div>
<div class="row">
<div class="column">Column 1</div>
<div class="column">Column 2</div>
<div class="column">Column 3</div>
</div>
</div>
</td>
</tr>
<tr>
<td style="height:79px;"">
</td>
</tr>
<tr>
<td style="height:100%;"> </td>
</tr>
<tr>
<td style="height:21px;"> </td>
</tr>
</table>

Floating table cells

How can I float td's within a table?
I have the following table:
<table align="center">
<tr>
<td>Huge IMAGE</td>
<td>VERY long TEXT</td>
<td>Annotations</td>
</tr>
</table>
Now I'd like the td-cells to move like this (but with floats) when a small end user device loads this view:
<table align="center">
<tr>
<td>Huge IMAGE</td>
</tr>
<tr>
<td>VERY long TEXT</td>
</tr>
<tr>
<td>Annotations</td>
</tr>
</table>
I would highly advise that you use a nested div structure instead of tables for your layout.
<div class="outerContainer">
<div class="imageHolder"></div>
<div class="textDescHolder"></div>
<div class="annotations"></div>
</div>
Then use "display: inline-block" on the inner div elements to control the layout. Although I am unclear as to how you wish to display the text and annotations in relation to the images.
I don't know exactly, what you want to do, but does it have to be a table? Maybe you should use an unordered list instead. In this list you can float your list items.
Something like:
http://jsfiddle.net/7kM48/
CSS
ul li{
float: left;
width: 100px;
height: 100px;
list-style: none;
}
HTML
<ul>
<li style="background-color: yellow;">Content 1</li>
<li style="background-color: fuchsia;">Content 2</li>
<li style="background-color: green;">Content 3</li>
</ul>
You could try using columns from bootstrap:
<div class="container" style="text-align: center">
<div class="col-md-4 col-sm-12">
Huge Image
</div>
<div class="col-md-4 col-sm-12">
Very long text
</div>
<div class="col-md-4 col-sm-12">
Annotations
</div>
</div>
this way you have the same output in a normal screen, and one row each for a small device

Table with fused rows

I need the following type of table in html
i.e., with fused rows in the second column (one entity). Basically, there would be text in the four non-fused cells and an image in the fused ones. How can I do this? If there is a way wherein I can avoid the use of tables, that would be better.
You need to use rowspan="4" attribute in the second TD of the first row. e.g.
<table>
<tr>
<td></td>
<td rowspan="4"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
This specifies that the second cell in the first row spans over 4 rows. Notice that in the 2nd to 4th rows there is no need to specify a second column as that is already specified in the first row.
However: if you are using this just for layout then I would avoid the table altogether and use some divs and CSS to achieve the same result.
<div class="outer">
<div class="left">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div class="right">
<!-- image here -->
</div>
<br style="clear:both;"/>
</div>
And CSS:
.left{
float:left;
}
.right{
float:left
}
You can find some good advice on this layout in this answer.
Or with Bootstrap:
<div class="row">
<div class="col-md-6">
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="col-md-6">Your Image Here</div>
</div>