How to align image to the bottom in a div inside td - html

I have designed a two column display using table.
I want to align image to the bottom inside td. I used vertical-align: top property in td to show the text from top but here is another problem, I want to show image with the text as well but sometimes when text get larger then some td boxes looks larger than another td boxes, I want to show equal td boxes.
There is free space in bottom of some td boxes, I think if I show the image from bottom then free space will shift from bottom to mid so these boxes will look attractive.
I do not want to show the image from top but bottom for that purpose i used another div for the image inside td but all in vain.
Note:- I have tried different positions properties like relative, absolute but none of them working (and sorry for my English).
$rows = $result->num_rows; // Find total rows returned by database
if($rows > 0) {
//if ($result->num_rows > 0) {
// output data of each row
$cols = 2; // Define number of columns
$counter = 1; //
$nbsp = $cols - ($rows % $cols); // Calculate t
echo '<table width="100%" align="center" cellpadding="4"
cellspacing="10" border= 1px solid white>';
while($row = $result->fetch_assoc()) {
$ads = $row['ads_id'];
$id = $row['user_id'];
if(($counter % $cols) == 1) { // Check if it's new row
echo '<tr>';
}
echo "<td>";
echo "<a href='welcome.php?user_id=$id&&ads_id=$ads'>";
echo "Book title - ". $row["title"] ."<br>";
echo "Book author - " . $row["author"] . "<br>";
echo "Price - " . $row["price"]. "<br>";
echo "Grade - " . $row["grade"]. "<br>";
echo "Description - " . $row["descrip"]. "<br>";
$img = $row['pic'];
echo "<div class=csc>";
echo '<img src="'.$img.'">';
echo"</div>";
echo "</a>";
echo "</td>";
if(($counter % $cols) == 0) {
echo "</tr>";
}
$counter++;
//echo "</table>";
}
if($nbsp > 0) { // Add unused column in last row
for ($i = 0; $i < $nbsp; $i++) {
echo '<td> </td>';
}
echo '</tr>';
}
echo '</table>';
} else {
echo "0 results";
}
$conn->close();
?>
This is the CSS part
table {
width: 100%;
text-align:center;
}
th, td {
vertical-align: top;
text-align: left;
padding: 8px;
background: #D9E4F5;
width: 50%;
font-family: georgia;
.csc{
bottom:1000px;
}
.csc img{
display: inline-block;
width: 100%;
height: 100px;
margin-top: 100px;
bottom:2000px;
}

First of all you've missed a } in your css.
This may solve your problem:
table {
width: 100%;
text-align: center;
}
th, td {
vertical-align: bottom; /* This is what you need */
text-align: left;
padding: 8px;
background: #D9E4F5;
width: 50%;
font-family: georgia;
}
.csc{
bottom: 1000px;
}
.csc img{
display: inline-block;
width: 100%;
height: 100px;
margin-top: 100px;
bottom: 2000px;
}

Related

CSS issue with div wrapping another

I have a problem that I cannot manage to wrap my section properly.
I have a div "container" that with a php part is populated by few divs and I don't know how to properly wrap it with the border:solid of my created div.
html/php part
<div class = "listaCarrello" id ="listaCarrello "style="display: <?php echo !isset($_GET['riepilogo'])&&isset($_SESSION['username'])? "block":"none"?>">
<?php
$isEmpty = true;
foreach ($_COOKIE as $key => $val) {
$query = $connection->query("SELECT * FROM prodotto WHERE IDProdotto = $key");
if ($query != null) {
$isEmpty = false;
$row = $query->fetch_assoc();
echo "<div class = \"elemCarrello\">";
echo "<p class=\"nomeCarrello\">" . $row['nomeProdotto'] . "</p>";
echo "<div class = \"imgCarrello\">";
echo "<img src = \"img/" . $row['immagine'] . "\" alt=\"" . $row['nomeProdotto'] . "\"height=\"150px\" width=\"150px\">";
echo "</div>";
echo "<div class=\"prezzoCarrello\">";
echo "<p>Prezzo unitario " . $row['prezzo'] . "</p>";
echo "<p> Quantità: " . $val;
echo " - Prezzo totale: ";
echo "€" . $row['prezzo'] * $val . "</p>";
$totale = $totale + ($row['prezzo'] * $val);
echo "<p> Modifica la Quantità: ";
echo "<input type='number' id = 'quantita' name='quantita' value='" . $val . "'>";
echo "<button onclick='refreshCookie($key, document.getElementById(\"quantita\").value)'>AGGIORNA</button>";
echo "</div>";
echo "<button class='eliminaCarrello' onclick='eliminaCookie($key)' style='background: white'> <img src='img/elimina.png' height='50' width='50'> </button>";
echo "</div>";
}
}
?>
</div>
<?php
if (!$isEmpty) {
echo "<div class='checkOut'>";
echo "<p>Totale: €" . $totale . "</p>";
echo '<button id="2ndphase" onclick="goToAddress()">AVANTI</button>';
echo "</div>";
}
?>
css part
.listaCarrello{
border:solid;
border-color: lightgray;
border-radius: 10px;
text-align: center;
margin-top: 5px;
width: 99%;
margin-bottom: 5px;
padding-bottom: 50px;
}
.elemCarrello{
margin-top: 5px;
width: 99%;
text-align: left;
float:left;
display: block;
margin-bottom: 5px;
border: solid;
margin-left: 5px;
border-radius: 10px;
}
.nomeCarrello{
padding-left: 10px;
font-weight: bold;
}
.imgCarrello{
float: left;
padding-left: 10px;
}
.eliminaCarrello{
margin-top: -13px;
margin-bottom: 10px;
}
Sorry for my English and I hope that you understood what I am saying.
I have attached a image as an example
Set the "container" divs overflow styling to auto.
container{
overflow:auto;
}

Website (Table) looks fine in Firefox but not Chrome/Edge

Below is some of the code for my website. The table works perfectly on Firefox but when I open it in either Chrome or Edge it squishes the picture up, I'm not too sure what it is that's making it do this.
This is how it looks on Firefox:
This is how it looks on Chrome/Edge:
<div class="row">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "music";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM music_tbl";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
echo "<table class='table-hover mainTable' border='1'>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td><img width='80%' height='80%'src=/Music_Player/songimages/". $row['album_cover_url'].">" .
"</td><td>" . $row["track_name"] .
"</td><td>" . $row["singers"] .
"</td><td>" . $row["album_name"] .
"</td><td>" . $row["trackID"] .
"</td><td><img src=playButton.png class='playB'>
</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
Below is my CSS:
.mainTable {
position: relative;
right: 20%;
margin:0 auto;
font-size: 99%;
text-align: center;
border: 1px solid #b3b3b3;
border-collapse: collapse;
max-width: 45%;
max-height: 100%;
font-family: verdana;
margin-bottom: -1px;
top: 200px;
}
tr, td {
border-collapse: collapse;
padding: 5px;
max-width: 650px;
}
.albums {
padding: 0px;
}

Images are stacked on top of each other?

I am trying to create two columns. One column is on the left and the other column is on the right. These two columns have an image and text to go along with it. Instead of having each image and text turn into a block of its own on a separate line, the images and text stack up on top of each other for both columns. How can I solve this?
PHP/HTML
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="test.css"?parameter="3"/>
</head>
<?php
$resultSet = $db->query("SELECT * FROM Articles");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$id = $rows["id"];
$images = $rows["image"];
$text = $rows["text"];
echo "<div id=body>";
if ($id > 3 && $id < 8)
{
echo "<div id=left>";
echo "<img src=$images>";
echo "<p>$text</p>";
echo "</div>";
}
if ($id > 8)
{
echo "<div id=right>";
echo "<img src=$images>";
echo "<p>$text</p>";
echo "</div>";
}
echo "</div>";
}
}
?>
CSS
#body{
position: relative;
margin: 0 auto;
width: 85%;
height: auto;
}
#left{
position: absolute;
left: 0%;
width: 28.33%;
display: block;
}
#left img{
width: 100%;
}
#right{
position: absolute;
right: 0%;
width: 28.33%;
}
#right img{
width: 100%;
}
First off there are a lot of things are added that don't need to be. That said, try this:
#left{
width: 28.33%;
display: inline-block;
float: left;
}
#right{
width: 28.33%;
display: inline-block;
float: left;
}
1.) Add singular ' quotes around you attribute values in the echo statements.
echo "<img src='path-to-img'>";
2.) If its only 2 columns, then the css for left box should be
`{position:relative; float:left;width:50%} ,
{position:relative; float:right;width:50%}`
for right box. From there you can choose to absolute position the images or text-align:center the boxes or whatever you want from there.
3.) Naming a id='body' is bad practice, you should rename it.
4.) Set CSS to display:block for both, not just one of those divs (left/right)

How can I wrap this text so it doesn't overflow past the widget container?

I have a Wordpress widget and inside the widget I am displaying profile information. Some times the text for the 2nd row is too long and it overflows past the widget container.
What would be a good way to deal with this, and how could I implement it in css or html or whatever?
My css
#profileContainer {
float: left;
position: relative;
width: 400px;
display:block;
padding: 5px;
}
#avatarContainer {
width: 55px;
float: left;
padding: 5 5 5 5;
}
#dataContainer {
float: left;
vertical-align: text-top;
word-wrap: break-word;
}
#dataList {
display: inline-block;
}
My html for the output
?>
<div id="profileContainer">
<?php
$img = bp_core_fetch_avatar( 'html=false&item_id=' . $author->getId() );
$img_html = '<img src="' . $img . '"></img>';
?>
<div id="avatarContainer">
<?php
if ($author->getUrl() != null) {
echo "<a href='" . $author->getUrl() . "'>" . $img_html . "</a>";
} else {
echo $img_html;
}
?>
</div> <!--closing avatar container div -->
<div class="overflow-hidden">
<?php
if ($author->getName() != null) {
echo "<b>" . $author->getName() . "</b>";
}
if ($author->getJobTitle() != null) {
echo "<br/>" . $author->getJobTitle();
}
if ($author->getUserName() != null) {
if ($author->getUrl() != null) {
echo "<br/><a href='" . $author->getUrl() . "'>#" . $author->getUserName() . "</a>";
} else {
echo "<br/>#" . $author->getUserName();
}
}
if ($author->getEmail() != null) {
echo '<br/>' . $author->getEmail() . "";
}
if ($author->getPhone() != null) {
echo "<br/> " . $author->getPhone();
}
echo "<br/>";
?>
</div> <!--closing data container div -->
</div> <!--closing container div-->
<?php
in css do this to wrap text in elipsis mode (three dots)
.overflow-hidden{
max-width:400px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

Inconsistent CSS Table displaying (Using SQL & PHP)

I've run into the problem that when I echo information Into a table using PHP and HTML from the database the information moves depending on how it loads.
By this I mean if I constantly refresh everything will be different to how it previously was. I mean how it is displayed not what is displayed.
.tracklist {
}
.tracklist img {
max-width:15%;
max-height:15%;
}
.tracklist td{
width:36%;
display:block;
padding:1%;
text-align:center;
}
#content {
width:98%;
height:73%;
padding-left:1%;
padding-right:1%;
background-color:#d8d8d8;
text-align:center;
}
#contentbox {
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
text-align:center;
background-color:#999999;
}
<div id="content">
<div id="contentbox">
<br />
<table class="tracklist">
<?php
$i = 0; $trEnd = 0;
while ($row = mysql_fetch_array($result)){
if($i == 0){
echo '<tr>';
}
echo '<td>';
echo $row["genre"]." | ".$row["artist"]." | ".$row["name"];
echo '<br />';
echo "<img src=".$row["image"].' />';
echo '</td>';
if($i == 2){
$i = 0; $trEnd = 1;
}else{
$trEnd = 0; $i++;
}
if($trEnd == 1) {
echo '</tr>';
}
}
if($trEnd == 0) echo '</tr>';
?>
</table>
</div>
</div>
The data from the database is called in the header just so people know that it is called.
Fixed this by putting width:100%; in the class which it inherited the height from.
Seems to of fixed it for now.