What I am trying is to display message row by row, and finally display a text box for input to send message, now the problem I faced is that I can display the message row by row, however the text box will be show near to the display message horizontally. The text box cannot be show at the bottom row of the page. Here is the unexpected result image. I tried many ways but seems cannot solve it.
Edited: And I need to display incoming message on left side and outgoing message on the right hand side
<div class="container">
<div class="row">
<div class="row" style="width:100%">
<table>
<tr>
<td bgcolor="#CCFFEE">
test() blah,blah,blah 2016-08-12 04:44:20
</td>
<td>
<img src="" alt="Smiley face" height="80" width="80">
</td>
<td></td>
<td></td>
<tr>
<tr>
<td bgcolor="#CCFFEE">
test() Hi 2016-08-12 04:43:16
</td>
<td>
<img src="" alt="Smiley face" height="80" width="80">
</td>
<td></td>
<td></td>
<tr>
</table>
<br/>
<br/>
<table>
<form action="/v1/reply" method="post" onsubmit="return validateForm();window.location.reload();" name="myForm">
<tr>
<td>
<input type="text" id="body" name="body" style="width:700px;height:50px;">
</td>
<td>
<button type="submit" style="width:100px;height:50px;" id="sent_1" value="Send">Submit</button>
</td>
</tr>
<br>
</form>
</table>
</div>
Use display: inline-table then float:right; and float:left if you want a <td> to be wider than the other <td>, use colspan. All and more properties and attributes are used in the Snippet below:
SNIPPET
.msg {
display: inline-table;
table-layout: fixed;
border-collapse: collapse;
width: 50%;
}
.left {
float: left;
text-align: left;
}
.right {
float: right;
text-align: right;
}
.input {
width: 100%;
}
img {
display: block;
padding:0 80% 0 0;
margin: 0 auto 0 0;
}
<div class="container">
<div class="row">
<div class="row" style="width:100%">
<form action="http://www.hashemian.com/tools/form-post-tester.php" method="post" name="myForm">
<table class='left msg'>
<tr>
<td colspan='2' bgcolor="#CCFFEE">
test() blah,blah,blah 2016-08-12 04:44:20
</td>
<td>
<img src="http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png" alt="Smiley face" height="80" width="80">
</td>
<tr>
<tr>
<td colspan='2' bgcolor="#CCFFEE">
test() Hi 2016-08-12 04:43:16
</td>
<td>
<img src="http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png" alt="Smiley face" height="80" width="80">
</td>
<tr>
</table>
<table class='right msg'>
<tr>
<td colspan='2' bgcolor="#CCFFEE">
test() blah,blah,blah 2016-08-12 04:44:20
</td>
<td>
<img src="http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png" alt="Smiley face" height="80" width="80">
</td>
<tr>
<tr>
<td colspan='2' bgcolor="#CCFFEE">
test() Hi 2016-08-12 04:43:16
</td>
<td>
<img src="http://home.cse.ust.hk/~rossiter/mooc/matching_game/smile.png" alt="Smiley face" height="80" width="80">
</td>
<tr>
</table>
<table class='input msg'>
<tr>
<td colspan='5'>
<input type="text" id="body" name="body" style="width:100%;height:50px;">
</td>
<td>
<input type='submit' style="width:100px;height:50px;" id="sent_1" value="Submit">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
if you are using Twitter Bootstrap in this,
insert <div class="clearfix"></div>
just before
<table>
<form action="/v1/reply" method="post" onsubmit="return validateForm();window.location.reload();" name="myForm">
<tr><td><input type="text" id="body" name="body" style="width:700px;height:50px;"></td>
<td><button type="submit" style="width:100px;height:50px;" id="sent_1" value="Send">Submit</button></td>
</tr><br>
</form>
</table>
css:
table,
tr{
width:100%;
}
If the table is not compulsory for you, then you can use flex-box
You can understand the advantage of using flexbox after executing the following code snippet.
It is more customisable and in my html code, The position of image is before message. But in the output for sent message, image is coming after message.
.row{
display: flex;
align-items: center;
}
img{
width: 35px;
}
.reciever{
justify-content: flex-start;
}
.sender{
justify-content: flex-end;
}
.sent, .recieve{
align-items: center;
display: flex;
max-width: 50%;
}
.sent{
flex-direction: row-reverse;
}
form{
padding: 1em;
text-align: center;
}
input{
width: 85%;
height: 20px;
}
button{
height: 25px;
}
<div class="container">
<div class="row sender">
<div class="sent">
<img src="http://www.carderator.com/assets/avatar_placeholder_small.png" alt="">
<span>sent message 1</span>
</div>
</div>
<div class="row reciever">
<div class="recieve">
<img src="http://www.quantumphotonics.uottawa.ca/wp-content/uploads/2014/09/portrait_placeholder.png" alt="">
<span>recieved message 1</span>
</div>
</div>
<div class="row sender">
<div class="sent">
<img src="http://www.carderator.com/assets/avatar_placeholder_small.png" alt="">
<span>sent message 2</span>
</div>
</div>
<div class="row reciever">
<div class="recieve">
<img src="http://www.quantumphotonics.uottawa.ca/wp-content/uploads/2014/09/portrait_placeholder.png" alt="">
<span>recieved message 2</span>
</div>
</div><div class="row sender">
<div class="sent">
<img src="http://www.carderator.com/assets/avatar_placeholder_small.png" alt="">
<span>sent message 3</span>
</div>
</div>
<div class="row reciever">
<div class="recieve">
<img src="http://www.quantumphotonics.uottawa.ca/wp-content/uploads/2014/09/portrait_placeholder.png" alt="">
<span>recieved message 3</span>
</div>
</div>
<form action="">
<input type="text" >
<button>Submit</button>
</form>
</div>
Here is the working Demo
Related
This is what I have for two side by side columns of key-value pairs with fixed width between the key-values. The columns should get further apart on resize, but not the key value pairs themselves.
I don't really understand how the 'width: 1%' is working. Is there a better solution to this? Is there anything wrong with the way I've done this?:
http://jsfiddle.net/zdt6ejq0/3/
<table width="50%" style="float: left">
<tr>
<td style="vertical-align: top; width: 1%"><b>Inment:</b></td>
<td style="vertical-align: top">{wbsSubstructure}</td>
</tr>
<tr>
<td><b>ACDnge Oer:</b></td>
<td>{changder}</td>
</tr>
<tr>
<td><b>Coct Ne:</b></td>
<td> {cact}</td>
<tr>
<td style="vertical-align:top;"><b>Den:</b></td>
<td> {dil}</td>
</tr>
</table>
<table width="50%" class="data" style="float: right">
<tr>
<td style="vertical-align: top; width: 1%"><b>Inon De:</b></td>
<td style="vertical-align: top">{ine}</td>
</tr>
<tr>
<td><b>Sc Nr:</b></td>
<td> {spmber}</td>
</tr>
<tr>
<td><b>Cct Nr:</b></td>
<td> {cumber}</td>
</tr>
<tr>
<td style="vertical-align:top;"><b>Don:</b></td>
<td> {dil}</td>
</tr>
</table>
You could place the tables inside two divs, one floating left, one floating right.
I also recommend to use css classes, not style tags, inside html.
Like this:
http://jsfiddle.net/69x3rstc/
<div class="container">
<div class="floatLeft">
<table>
<tr >
<td><b>Inment:</b></td>
<td>{wbsSubstructure}</td>
</tr>
<tr >
<td ><b>ACDnge Oer:</b></td>
<td>{changder}</td>
</tr>
<tr >
<td ><b>Coct Ne:</b></td>
<td> {cact}</td>
<tr >
<td><b>Den:</b></td>
<td> {dil}</td>
</tr>
</table>
</div>
<div class="floatRight">
<table class="data">
<tr >
<td><b>Inon De:</b></td>
<td>{ine}</td>
</tr>
<tr >
<td ><b>Sc Nr:</b></td>
<td> {spmber}</td>
</tr>
<tr >
<td ><b>Cct Nr:</b></td>
<td> {cumber}</td>
</tr>
<tr >
<td><b>Don:</b></td>
<td> {dil}</td>
</tr>
</table>
</div>
</div>
CSS
.floatLeft { width: 50%; float: left; }
.floatRight {width: 50%; float: right; }
.container { overflow: hidden; }
There are many ways to do this, each variation depends on your stack, personal preference and or requirements. If you are not locked down to using a table. My preference is to use divs instead to achieve the same effect. This allows you to make use of modern css3 attributes and not be bound by the constraints of a table element. Yes, tables are semantically correct for tabular data, however, the responsive world puts a world of complexities that tables weren't initially designed for.
Ex:
.tabular-data {
display: flex;
flex-wrap: wrap;
}
.column {
flex-basis: 50%;
display: flex;
}
.column .column-inner:first-child {
flex-basis: auto;
flex-wrap: nowrap;
}
.column .column-inner:last-child {
flex-grow: 1;
padding-left: 0.5rem;
}
<div class="tabular-data">
<div class="column">
<div class="column-inner">
<div class="cell"><strong>Inment:</strong></div>
<div class="cell"><strong>ACDnge Oer:</strong></div>
<div class="cell"><strong>Coct Ne:</strong></div>
<div class="cell"><strong>Den:</strong></div>
</div>
<div class="column-inner">
<div class="cell"> {dil}</div>
<div class="cell"> {cact}</div>
<div class="cell">{wbsSubstructure}</div>
<div class="cell">{changder}</div>
</div>
</div>
<div class="column">
<div class="column-inner">
<div class="cell"><strong>Inon De:</strong></div>
<div class="cell"><strong>Sc Nr:</strong></div>
<div class="cell"><strong>Cct Nr:</strong></div>
<div class="cell"><strong>Don:</strong></div>
</div>
<div class="column-inner">
<div class="cell">{ine}</div>
<div class="cell">{spmber}</div>
<div class="cell">{cumber}</div>
<div class="cell">{dil}</div>
</div>
</div>
</div>
I have an html table on my website (emma-moore.com) that I'm using for layout instead of tabular data:
<table border="0" cellpadding="5px" width="100%" class="followFont">
<tbody>
<tr>
<td align="left">Follow your heart</td>
</tr>
<tr>
<td align="left" style="padding-bottom: 10px">and you'll always</td>
</tr>
<tr>
<td align="left">
<img border="0" src="balloonsAndLavenderFields.jpg" width="99px" height="150px" class="homePictureFrame" />
</td>
</tr>
<tr>
<td align="left" style="padding-top: 10px">end up where your</td>
</tr>
<tr>
<td align="left">soul needs to be.</td>
</tr>
</tbody>
</table>
Best practice is not to use inline styles and tables for layout, and I'm wondering how to replace the table with a div block and put the text and the jpg inside the div block in such a way that the text and jpg display the same way as they do when using the table. How can I best do this with css and a div block?
Thanks,
William
.followFont
{
padding:5px;
border:0;
cellpadding:5px;
width:100%;
display:table;
}
<div class="followFont">
<div style="display:table-row;">
<div style="width:100%; display:table-cell; text-align:left;">Follow your heart</div>
</div>
<div style="display:table-row;">
<div style="width:100%; display:table-cell; text-align:left; padding-bottom: 10px;">and you'll always</div>
</div>
<div style="display:table-row;">
<div style="width:100%; display:table-cell; text-align:left;">
<img border="0" src="balloonsAndLavenderFields.jpg" width="99px" height="150px" class="homePictureFrame" />
</div>
</div>
<div style="display:table-row;">
<div style="width:100%; display:table-cell; text-align:left; padding-top: 10px;">end up where your</div>
</div>
<div style="display:table-row;">
<div style="width:100%; display:table-cell; text-align:left;">
soul needs to be.
</div>
</div>
</div>
Link:-https://html-cleaner.com/features/replace-html-table-tags-with-divs/
<h2>Phone numbers</h2>
<table width="300" border="1" cellpadding="5" style="text-align: center">
<tr>
<th width="75"><strong>Name</strong></th>
<th><span style="font-weight: bold;">Telephone</span></th>
<th> </th>
</tr>
<tr>
<td>John</td>
<td>0123 456 785</td>
<td><img src="images/check.gif" alt="checked" /></td>
</tr>
<tr>
<td>Cassie</td>
<td>9876 532 432</td>
<td><img src="images/check.gif" alt="checked" /></td>
</tr>
</table>
<h2>Phone numbers</h2>
<div class="rTable">
<div class="rTableRow">
<div class="rTableHead"><strong>Name</strong></div>
<div class="rTableHead"><span style="font-weight: bold;">Telephone</span></div>
<div class="rTableHead"> </div>
</div>
<div class="rTableRow">
<div class="rTableCell">John</div>
<div class="rTableCell">0123 456 785</div>
<div class="rTableCell"><img src="images/check.gif" alt="checked" /></div>
</div>
<div class="rTableRow">
<div class="rTableCell">Cassie</div>
<div class="rTableCell">9876 532 432</div>
<div class="rTableCell"><img src="images/check.gif" alt="checked" /></div>
</div>
</div>
You can use
<div id="table" style="display: table;">
<div class="cell" id="cell1"></div>
<div class="cell" id="cell2"></div>
<div class="cell" id="cell3"></div>
</div>
You'll be using like table
Div can have the same properties as table
like
#table
{
vertical-align:middle;
text-align:center:
border:solid 1px #ddd;
width:100%;
}
.cell
{
display:table-cell;
vertical-align:middle;
text-align:center;
border:solid 1px #ddd;
width:25%;
padding:10px;
}
and soon....
Hope this helps
I want to align table inside div to right side of the div, but they are aligned to left, what is wrong with my css? I have table inside the div, which contains a text and a picture, what I want is to place the table on right hand side use align=right in table. And some tables I would like to align on the left side, how can I align some tables on right side in a page or some tables in left side in the same page? Thanks
<!DOCTYPE html>
<html>
<head>
<title>Landing</title>
<style>
.form-section{
margin:15px;
}
</style>
</head>
<body>
<div class="jumbotron" align="center">
<img src="/static/img/Chaatz-192x192px.jpg" class="img-responsive" alt="Responsive image" style="width:10%;height:10%">
<h2></h2>
</div>
<div class="container">
<div class="row">
<div class="row" style="width:100%">
<form class="form-horizontal">
<table align="right">
<tr>
<td>
test(user11)
H111i
2016-08-12 07:46:22
</td>
<td><img src=http://d2h8t8into6exa.cloudfront.net/user_comic_avatars/VkKDIkBHsd.jpg alt="Smiley face" height="80" width="80"></td>
<tr>
</table>
<br>
<table align="right">
<tr>
<td>
test(user11)
H111i
2016-08-12 07:46:21
</td>
<td><img src=http://d2h8t8into6exa.cloudfront.net/user_comic_avatars/VkKDIkBHsd.jpg alt="Smiley face" height="80" width="80"></td>
<tr>
</table>
<br>
<style>
.multiline
{
padding:0px;
white-space: pre-wrap;
height: 100px;
width: 50%;
margein:0px
}
.row {
display: flex;
}
td { white-space:pre }
</style>
Please update your code as per this. The problem, .row should have 'col-` as their child as a standard practice.
.multiline
{
padding:0px;
white-space: pre-wrap;
height: 100px;
width: 50%;
margein:0px
}
td { white-space:pre }
.user-table{width:100%;}
.user-table tr > td{
text-align:right;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="jumbotron" align="center">
<img src="/static/img/Chaatz-192x192px.jpg" class="img-responsive" alt="Responsive image" style="width:10%;height:10%">
<h2></h2>
</div>
<div class="container">
<div class="row">
<form class="form-horizontal">
<div class="col-sm-12 col-md-12">
<table class="user-table">
<tr>
<td>
test(user11)
H111i
2016-08-12 07:46:22
</td>
<td><img src=http://d2h8t8into6exa.cloudfront.net/user_comic_avatars/VkKDIkBHsd.jpg alt="Smiley face" height="80" width="80"></td>
<tr>
</table>
</div>
<div class="col-sm-12">
<table class="user-table">
<tr>
<td>
test(user11)
H111i
2016-08-12 07:46:21
</td>
<td><img src=http://d2h8t8into6exa.cloudfront.net/user_comic_avatars/VkKDIkBHsd.jpg alt="Smiley face" height="80" width="80"></td>
<tr>
</table>
</div>
</form>
</div>
<div>
I have 4 divs and 4 images and each of them has an ID. I need to show another div when you hover the first div's image.
I wrote this code but only the first image with ID="insta2" and div ID="iinsta2" worked.
<style type="text/css">
#insta1{display:none}
#insta2{display:none}
#insta3{display:none}
#insta4{display:none}
#iinsta1:hover + #insta1 {
display: block;
}
#iinsta2:hover + #insta2 {
display: block;
}
#iinsta3:hover + #insta3 {
display: block;
}
#iinsta4:hover + #insta4 {
display: block;
}
</style>
And body:
<tr>
<td colspan="3" rowspan="2" style="text-align:center; width:30%">
<div id="insta1"><p> Hover 1 </p></div>
<img id="iinsta2" src="url" style="width:100% ; height:auto">
<div id="insta2"> <p> Hover </p></div>
</td>
<td colspan="4" style="text-align:center; width:40%">
<img id="iinsta1" src="url" style="width:100% ; height:auto">
</td>
<td colspan="3" rowspan="2" style="text-align:center; width:30%">
<div id="insta3"><p> Hover 3 </p></div>
<img id="iinsta3" src="url" style="width:100% ; height:auto">
<div id="insta4"> <p> Hover 4 </p> </div>
</td>
</tr>
<tr>
<td colspan="4" style="text-align:center; width:40%">
<img id="iinsta4" src="url" style="width:100% ; height:auto">
</td>
</tr>
Use this way:
#insta1,
#insta2,
#insta3,
#insta4 {
display: none;
}
#iinsta1:hover + #insta1,
#iinsta2:hover + #insta2,
#iinsta3:hover + #insta3,
#iinsta4:hover + #insta4 {
display: block;
}
<table>
<tr>
<td colspan="3" rowspan="2" style="text-align:center; width:30%">
<div id="insta1">
<p>Hover 1</p>
</div>
<img id="iinsta2" src="url" style="width:100% ; height:auto">
<div id="insta2">
<p>Hover</p>
</div>
</td>
<td colspan="4" style="text-align:center; width:40%">
<img id="iinsta1" src="url" style="width:100% ; height:auto">
</td>
<td colspan="3" rowspan="2" style="text-align:center; width:30%">
<img id="iinsta3" src="url" style="width:100% ; height:auto">
<div id="insta3">
<p>Hover 3</p>
</div>
</td>
</tr>
<tr>
<td colspan="4" style="text-align:center; width:40%">
<img id="iinsta4" src="url" style="width:100% ; height:auto">
<div id="insta4">
<p>Hover 4</p>
</div>
</td>
</tr>
</table>
The + object can be used only with siblings that are next. Also, I have reduced your CSS. Please use absolute positions for positioning the :hovers. And, if you wanna maintain the HTML layout, you need to use JavaScript for this.
img ~ p {
visibility: hidden;
}
img:hover ~ p {
visibility: visible;
}
<table border=1>
<tr>
<td>
<div class="item">
<h1>Hover 1</h1>
<img src="http://placekitten.com/100" />
<p>Hover</p>
</div>
</td>
<td>
<div class="item">
<h1>Hover 1</h1>
<img src="http://placekitten.com/100" />
<p>Hover</p>
</div>
</td>
<td>
<div class="item">
<h1>Hover 1</h1>
<img src="http://placekitten.com/100" />
<p>Hover</p>
</div>
</td>
<td>
<div class="item">
<h1>Hover 1</h1>
<img src="http://placekitten.com/100" />
<p>Hover</p>
</div>
</td>
</tr>
</table>
The example here seems complicated so I boiled it down to what I understood the question to be. I hope this helps. Feed back is welcome.
How to make inside table same size as text inside :
<table class="table-1">
<tr>
<td align="center">
<div class="block" id="block-1" style="background: black">
<a style="color: black" href="myFunc()"><c:out
value="${item.title}" /></a>
</div>
</td>
</tr>
</table>
css:
table.table-1 {
width: 100%;
}
How to make <div class="block" id="block-1" style="background: black"> take size of
<a style="color: black" href="myFunc()"> <c:out value="${item.title}"/> </a>
use display: inline-block; for .block
table.table-1 {
width: 100%;
}
.block{
display: inline-block;
}
<table class="table-1">
<tr>
<td align="center">
<div class="block" id="block-1" style="background: black">
<a style="color: #fff" href="myFunc()">text text text</a>
</div>
</td>
</tr>
</table>