As you can see in the picture, there is a box to the right with some text and a lot of white space.
My goal is to have the text under the pictures while I have 3 pictures in a row that are nicely aligned.
When I try this either the pictures aren't aligned anymore or the pictures aren't cropped anymore.
I wanted every picture with the same size and still sharp but, then this issue came up.
#content {
width: 100%;
max-width: 100%;
margin: 20px auto;
}
form {
width: 50%;
margin: 20px auto;
}
form div {
margin-top: 5px;
}
#img_div {
width: 30%;
margin-left: 2%;
margin-right: 1%;
margin-bottom: 3%;
border: 2px solid #d8680c;
float: left;
}
#img_div:after {
content: "";
display: block;
clear: both;
}
img {
float: left;
object-fit: cover;
width: 250px;
height: 250px;
}
#pictext {
word-wrap: break-word;
}
<div id="content">
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
echo "<img src='fotopage\images/" . $row['image'] . "' >";
echo "<p id='pictext'>" . $row['image_text'] . "</p>";
echo "</div>";
}
?>
</div>
use class instead of using ID
ID must be unique and when you do the loop there will be some other divs with same ID
add it like this
<?php
while ($row = mysqli_fetch_array($result)) {
echo "<div class='img_div'>";
echo "<img src='fotopage\images/" . $row['image'] . "' >";
echo "<p class='pictext'>" . $row['image_text'] . "</p>";
echo "</div>";
}
?>
make sure to reflect them via JS or JQuery depends on what your are using
Related
I'm trying to create a square, created of smaller red and blue squares. The problem is, when i want to use something wierd happens, every new line is off by 20 px.
<style>
.box{
background-color: red;
position: relative;
width: 20px;
height: 20px;
margin-left: 3px;
margin-top: 3px;
float:left;
}
.box1{
background-color: blue;
position: relative;
width: 20px;
height: 20px;
margin-left: 3px;
margin-top: 3px;
float:left;
}
</style>
<?php
for($a=0;$a<4;$a++){
for($i = 0; $i < 4; $i++)
{
echo "<div class= box> </div>";
echo "<div class= box1> </div>";
}
echo "<br />";
for($i = 0; $i < 4; $i++)
{
echo "<div class= box> </div>";
echo "<div class= box1> </div>";
}
echo "<br />";
}
?>
How it looks like
Using relative position is the problem. Use display:inline-block instead.
Also you can accomplish this only using 2 for loops.
<style>
.box{
background-color: red;
width: 20px;
height: 20px;
margin-left: 3px;
margin-top: 3px;
display: inline-block;
}
.box1{
background-color: blue;
width: 20px;
height: 20px;
margin-left: 3px;
margin-top: 3px;
display: inline-block;
}
</style>
<?php
for($a=0;$a<8;$a++){
for($i = 0; $i < 4; $i++)
{
echo "<div class= box> </div>";
echo "<div class= box1> </div>";
}
echo "<br />";
}
?>
The proper way to break float is to use clear style attribute. For example add this to your styles:
br{
clear:both;
}
<br /> will now reset the float of the divs after it, so the next ones will be in new line.
Example in here.
Please note that class attribute should be in quotes, your code is not a valid HTML. To make it valid use one of these:
echo "<div class='box'> </div>";
or
echo '<div class="box"> </div>';
From my point of view you have to add one main div as like below code and have to add float left and width to 100%;
<style>
.box{
background-color: red;
position: relative;
width: 20px;
height: 20px;
margin-left: 3px;
margin-top: 3px;
float:left;
}
.box1{
background-color: blue;
position: relative;
width: 20px;
height: 20px;
margin-left: 3px;
margin-top: 3px;
float:left;
}
.main {
float:left;
width:100%;
}
</style>
<?php
for($a=0;$a<4;$a++){
echo "<div class='main'>";
for($i = 0; $i < 4; $i++)
{
echo "<div class= box> </div>";
echo "<div class= box1> </div>";
}
echo "</div>";
echo "<br />";
echo "<div class='main'>";
for($i = 0; $i < 4; $i++)
{
echo "<div class= box> </div>";
echo "<div class= box1> </div>";
}
echo "</div>";
echo "<br />";
}
?>
I have a php to echo three variable fields :
<li>
<mark> <?php while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo $toprow2['overallRank'] ." ".$toprow2['EmployeeName'] ." ".$toprow2['Total_points_Rewarded']."<br/>";} ?>
</mark>
</li>
Among these three variables of the list,I want to align the first field "overallRank " to left ,"EmployeeName " to centre and "Total_points_Rewarded" to extreme right.
Below is the code I tried for the first field:
<li>
<mark> <?php while( $toprow2 = sqlsrv_fetch_array( $stmt3) ) {
echo "<div style = "text-align=left" ."$toprow2['overallRank'] "</div>"." ".$toprow2['EmployeeName'] ." ".$toprow2['Total_points_Rewarded']."<br/>";} ?>
</mark>
</li>
when I use three divs :
echo "<div style ='text-align:left'>" . $toprow2['overallRank'] . "</div><div style ='text-align:centre'>" . $toprow2['EmployeeName'] . "</div><div style ='text-align:right'>" . $toprow2['Total_points_Rewarded'] . "</div>";
I am not able to align them :Current scenario :
the first block is the rank,then name and last points - the three fields that I am trying to echo here.
css used for above situation:
li mark {
display: inline-block;
justify-content: space-between;
}
li mark div {
display: block;
margin: 4px;
padding: 5px;
min-height: 100px;
border: 1px solid #eebb55;
border-radius: 7pt;
background: grey;
}
#Abhay has a great solution :css aint working here,though
current situation:
Use flex:
echo "<div class='parent-div'><div class='rank'>" . $toprow2['overallRank'] . "</div><div class='name'>" . $toprow2['EmployeeName'] . "</div><div class='points'>" . $toprow2['Total_points_Rewarded'] . "</div></div>";
Your CSS:
.parent-div{
display: -webkit-flex; /* Safari */
display: flex;
}
.rank,.name,.points{
width:33%;
}
.name{
text-align: center;
}
.points{
text-align: right;
}
Small working ex:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<style>
.parent-div{
display: -webkit-flex; /* Safari */
display: flex;
}
.rank,.name,.points{
width:33%;
}
.name{
text-align: center;
}
.points{
text-align: right;
}
</style>
</head>
<body>
<div class="parent-div">
<div class='rank'>Rank</div>
<div class='name'>Name</div>
<div class='points'>Points</div>
</div>
<div class="parent-div">
<div class='rank'>Rank</div>
<div class='name'>Name</div>
<div class='points'>Points</div>
</div>
<div class="parent-div">
<div class='rank'>Rank</div>
<div class='name'>Name</div>
<div class='points'>Points</div>
</div>
</body>
</html>
If continuing with span :
echo "<div class='parent-div'><span class='rank'>" . $toprow2['overallRank'] . "</span><span class='name'>" . $toprow2['EmployeeName'] . "</span><span class='points'>" . $toprow2['Total_points_Rewarded'] . "</span></div>";
Try this CSS:
.parent-div{
display: -webkit-flex; /* Safari */
display: flex;
}
.rank,.name,.points{
display:block;
width:33%;
}
.name{
text-align: center;
}
.points{
text-align: right;
}
Please mind that I have given class: parent-div to all three spans container div.
I hope it helps
Why don't you use
li mark {
display: inline; /* don't use inline-block */
justify-content: space-between;
}
li mark div {
float: left; /* here you put the float so it can be after the first li mark */
display: block;
margin: 4px;
padding: 5px;
min-height: 100px;
border: 1px solid #eebb55;
border-radius: 7pt;
background: grey;
}
li mark div:first-child {
float: left; /* it will put your first div in left side */
}
li mark div:last-child {
float: right; /* it will be in the right side */
}
Also why not remove a width. For example instead being without it in the classes above, this means the width is 100% you could adjust it to width: 50% to half.
I'm working on a php powered site for a musician, part of which involves the ability for him to add upcoming shows to his site through a form. I want a table layout where he can see his upcoming shows, and can choose to add a new one. I tried using a table, but quickly found they don't really work with PHP forms. So I tried to format my form as a table with CSS display properties. That had it not rendering at all, in fact, if you go into the inspector in Chrome,it shows all of the information clearly there, laid out in the HTML, but with no height. I tried manually adding height and width, but to no avail. I tried changing from a form to a div, just to see, and that didn't help either.
.form-table {
width: 100%;
display: table;
font-size: 20px;
}
.admin-table-row {
display: table-row;
width: 100%;
}
.admin-table-cell {
display: table-column;
}
.admin-venue {
width: auto;
text-align: left;
}
.admin-age {
text-align: right;
width: 75px;
}
.admin-date {
text-align: right;
width: 200px;
}
.admin-time {
text-align: right;
width: 100px;
}
.admin-time {
text-align: right;
width: 100px;
}
.admin-edit {
text-align: right;
width: 100px;
}
.admin-delete {
text-align: right;
width: 100px;
}
//echo "<form class='form-table' action='' method='post'>";
echo "<div class='form-table'>";
foreach($stmt as $upcomingShow)
{
$date = date("j F, Y", (strtotime($upcomingShow['date'])));
$time = date("g:i a", (strtotime($upcomingShow['time'])));
echo "<div class='admin-table-row'>";
if(!empty($upcomingShow['link']))
{
echo "<div class='admin-venue admin-table-cell'><a href='" . $upcomingShow['link'] . "' style='text-decoration: none;'>" . $upcomingShow['venue'] . "</a></div>";
}
else
{
echo "<div class='admin-venue admin-table-cell'>" . $upcomingShow['venue'] . "</div>";
}
echo "<div class='admin-age admin-table-cell'>" . $upcomingShow['age'] . "</div>";
echo "<div class='admin-date admin-table-cell'>" . $date . "</div>";
echo "<div class='admin-time admin-table-cell'>" . $time . "</div>";
echo "<div class='admin-edit admin-table-cell'><input name='edit' id='edit' type='submit' value=' Edit ' style='background: none; border: none; padding: 0; font: inherit; cursor: pointer;'></div>";
echo "<div class='admin-delete admin-table-cell'><input name='delete' id='delete' type='submit' value=' Delete ' style='background: none; border: none; padding: 0; font: inherit; cursor: pointer;'></div>";
echo "<input name='show-id' id='show-id' type='hidden' value='" . $upcomingShow['id'] . "'>";
echo "</div>";
}
echo "</div>";
//echo "</form>";
Thanks for all the help. Best, Chris.
Checking your CSS, the issue is in here:
.admin-table-cell {
display: table-column;
}
The display: table-column is not used to specify that the element is a cell, but to specify that the element contains a column of cells; and by definition it is not rendered:
Elements with 'display' set to 'table-column' or 'table-column-group' are not rendered (exactly as if they had 'display: none')
That's why you don't see the contents even after setting a height. What you need to use to specify that the div is a cell, is display: table-cell. Then it will display the content of each cell correctly. This change should fix the issue:
.admin-table-cell {
display: table-cell;
}
I am making a small chat and I am having issues making the div's appear below each other. This is what I have:
$i = 0;
while($i < 5)
{
echo "<div class='MyChatholders'>";
echo "<div class='pro_pic'>";
//my image
echo "</div>";
echo "<div class='ChatInfo'>";
//my information
echo "</div>";
echo "</div>";
echo "<br />";
$i++;
}
MY CSS:
div.MyChatholders
{
left: 5px;
color: black;
width: 290px;
height: 100px;
border-radius: 10px;
}
div.pro_pic
{
left: 5px;
width: 30px;
height: 30px;
border: solid black 1px;
}
div.ChatInfo
{
color: black;
font-size: 14px;
left: 40px;
width: 245px;
}
Please note that the (while function) is just to simulate the information drawn from the DBase.
Now my issues is that all the div's are in one position. I would like them to fall below each other. I do not understand why this is happening. Can someone help me with my code and explain why?
I have looked at this solution but it is not working for me Check here
Add position:relative; to your divs.
Working fiddle based on your code: http://jsfiddle.net/MmGyU/1/
Note: Borders in the fiddle are for demonstration purposes.
div.MyChatholders {
position: relative;
left: 5px;
color: black;
width: 290px;
height: 100px;
border-radius: 10px;
}
div.pro_pic {
position:relative;
left: 5px;
width: 30px;
height: 30px;
}
div.ChatInfo {
position:relative;
color: black;
font-size: 14px;
left: 40px;
width: 245px;
}
Make it print your <div> tags to a new line in your loop using \n
$i = 0;
while($i < 5)
{
echo "<div class='MyChatholders'>\n";
echo "<div class='pro_pic'>\n";
//my image
echo "</div>\n";
echo "<div class='ChatInfo'>\n";
//my information
echo "</div>\n";
echo "</div>\n";
echo "<br />\n";
$i++;
}
EDIT Syntax was wrong, the \n needs to be within quotes
2nd EDIT My mistake, \n is not HTML and it won't work. You could use <br /> instead according to this post
Add clear:both; to your chat divs.
I have a comment system, it works by adding a row to a SQL database. Anyway That works, but then when I echo out the comment div gets all messed up.. Anyway here is the page it is on: http://learntc.net/index.php.
PHP:
while($row = mysql_fetch_array($result))
{
if ($count==1)
{
$bg == "33383C" ;
$count = 0;
}
echo "<div style='background-color: $bg; border: 1px soild silver;' class='comment'>";
echo "<div class='imageAndName'>";
echo "<img src='". $row["image"] ."' class='cPic'/>";
echo "<div class='UserLink'><a href='" . $row["page"] . "'>" . $row["username"] . "</a></div>";
echo "</div>";
echo "<div class='textStuff'>";
echo "<div class='post'>" . $row["comment"] . "</div>";
echo "<div style='color: gray; font-size: 8px'>" . $row["date"] . "</div>";
echo "</div>";
echo "</div>";
$bg = "#282C2F";
$count = $count + 1;
}
CSS:
.comments{
float: right;
padding: 10px;
width: 50%;
border: 1px solid #454D53;
}
.cPic{
width: 60px;
height: 60px;
}
.imageAndName{
width: 30%;
overflow: hidden;
float: left
}
.imageAndName a{
display: block;
}
.textStuff{
width: 70%;
float: right;
}
.post{
overflow: hidden;
width: 100%;
}
.comment{
padding-bottom: 5px;
}
Add clear: both to your .comment style.
Problem one:
$bg == "33383C" ;
should be
$bg = "#33383C";
I don't see anything else. The div is probably screwed up for this reason.