Floating table cells - html

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

Related

css div overflow property usage

I am using bootstrap with angular and I have the foll. code in my component.html file.
The below 2 DIV is only occupying col-sm-6, so the other half of div is empty. Now i want to add another table in this empty space and that occupies both the DIV's.
When I try to add on the 1st set of div then the new table occupies only in the 1st div and pushes the 2nd div until the length of the table. If i add
then the 1st div right side is empty and the table occupies just from the 2nd div start and goes until the length of the new table. So I tried to add
overflow: visible; to the 1st Div class="row" but it didnt work. What is the best way to achieve the same?
<div class="row">
<div class="col-sm-2"></div>
<div class="col-sm-3" style="text-align:center; padding-top: 5px;">
<table class="col-sm-12">
<tr>
<td colspan="12" class="labelStyle" style="text-align: center;background-color:#f4f4f4">
BMI Chart
</td>
</tr>
<tr *ngFor="let item of lkBmiChartList;">
<td colspan="8" class="labelStyle">{{item.code}}</td>
<td colspan="4" class="labelStyle">{{item.value}}</td>
</tr>
</table>
</div>
<div class="col-sm-1"></div>
</div>
<div class="row">
<div class="col-sm-3" style="text-align:center; padding-top: 5px;padding-left: 3px;padding-right: 3px;">
<table class="col-sm-12">......</table>
</div>
<div class="col-sm-2" style="text-align:center; padding-top: 5px;padding-left: 3px;padding-right: 3px;">
<table class="col-sm-12">...</table>
</div>
<div class="col-sm-1" style="text-align:center; padding-top: 5px;padding-left: 3px;padding-right: 3px;">
<table class="col-sm-12">...</table>
</div>
</div>
I do not want to use scroll bars or anything. The table should occupy the right of both the div and not specific to any row.

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

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

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!

How to wrap or break long line inside a <span> within a bootstrap table

I have the following bootstrap table:
<div class="row">
<div class="col-md-12" >
<table style="cursor:pointer;" class="table table-striped table-bordered table-hover table-condensed">
<thead>
<th>header1</th>
</thead>
<tbody>
<tr>
<td>
<div>
<ul>
<li>
<span>text1></span>
</li>
<li>
<span>text3></span>
</li>
</ul>
<span>some long text that i want to break</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
the number of span inside ul tag are dynamic and I don't want to wrap them.
I'd like to break the content inside the last span tag to make them wrap at given width, how do I do that? thanks.
Give span display property of block and set the width like this:
.row span {
width: 100px;
display: block;
}
Here is the jsfiddle http://jsfiddle.net/pF8vd/

How to horizontally align columns in a table

I read that each column of a table can be styled using <colgroup> and <col>. I tried the following, but the style speficication is not seeming to work. How can I fix it?
When I do this with width property, it works. Is there anything wrong with text-align property?
<html><body><table>
<colgroup>
<col style="text-align:right" />
<col style="text-align:center" />
<col style="text-align:left" />
</colgroup>
<tr>
<td>aaaaaaaaaaa</td>
<td>bbbbbbbbbbb</td>
<td>ccccccccccc</td>
</tr>
<tr>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
</tr>
</table></body></html>
The result is that each colum is left aligned by default, ignoring the specification made in colgroup.
I am using Chrome 17.
While support for colgroup and col seems to be spotty, I don't think one should throw out the baby with the bathwater. I think tables have their place, to display tabular data. Using divs to display tabular data borders on table-phobia in my opinion.
<html><body>
<style>
.left {text-align:left;}
.center {text-align:center;}
.right {text-align:right;}
</style>
<table>
<tr>
<td class="left">aaaaaaaaaaa</td>
<td class="center">bbbbbbbbbbb</td>
<td class="right">ccccccccccc</td>
</tr>
<tr>
<td class="left">aaa</td>
<td class="center">bbb</td>
<td class="right">ccc</td>
</tr>
</table>
</body></html>
If not in need of tables, here´s how I´d do it tableless, just in case:
HTML:
<div id="container">
<div class="left">left aligned text</div>
<div class="center">center aligned text</div>
<div class="right">right aligned text</div>
</div>
CSS:
.container {}
.left {
width:100px;
float:left;
text-align:left;
}
.center {
width:100px;
float:left;
text-align:center;
}
.right {
width:100px;
float:left;
text-align:right;
}
(and you could just unify all the common styles with commas and just separate the text-alignment)
Don't use tables, use divs. Obviously the following should be seperated out into classes and such, but it works.
<html><body>
<div style="display: table">
<div style="display: table-row">
<div style="display: table-cell;">aaaaaaaaaaa</div>
<div style="display: table-cell;">bbbbbbbbbbb</div>
<div style="display: table-cell;">ccccccccccc</div>
</div>
<div style="display: table-row">
<div style="display: table-cell; text-align:right;">aaa</div>
<div style="display: table-cell; text-align:center;">bbb</div>
<div style="display: table-cell; text-align:left;">ccc</div>
</div>
</div>
</body></html>