"void space" in a <li> with images - php

I'm kind of stuck on this. I have to put an horizontal list of different states of some services I'm working on. I have 3 different states ( Green, Orange, Red ), and I want to "go back to the line" whenever the state changes. I have the feeling I need to write something like "you go xx pixels down" to correctly have my lists in order, but it still keeps packing weirdly. I don't really know if I'm clear.
Here's part of the code :
$brequest = 1;
echo "<ul>\n";
foreach($arrstate as $sun){
for($x=1 ; $x<4 ; $x++){
if($sun[1] == $x){
if($brequest != $x){
$brequest = $x;
echo "</ul><ul>\n"; //Note that it's just a try here
}
$affichage=" <img src=\"images/" . $images[$x] . ".svg\" title=\"" . $texte_alt[$x] . "\" alt=\"" . $texte_alt[$x] . "\" height=\"40px\" style=\"vertical-align:middle\"";
$comment="<br /><br />".$sun[2]."<br /><br/>Last Updated : ".$sun[3]."<br /><br />By ".$sun[4]."</li>\n";
echo "<li style=\"background-color: " . $couleur_etat[$x] . "\">" . $sun[0] . $affichage. $comment;
}
}
}
echo "</ul>";
The array is sorted by states, and the <style> part is :
<style>
ul { list-style-type: none;}
li {
display: inline;
margin: 1em;
float: left;
padding: 1em;
border: 1px solid black;
border-radius: 15px;
width: 15em;
min-height: 3em;
font-weight: bold;
}
</style>
Feel free to ask me anything about the code. Thank you in advance for your answer !

Answering my own question to help.
I just had to clear:left every <ul> I use, this way the float will stop putting images at the same row. It goes like this :
echo "</ul><ul style=\"clear:left\">";
I know CSS in line is not that much appreciated, but I began HTML PHP & CSS Yesterday. So, let's run with it for the moment !
( And sorry for the bad example, I'll give more attention to details next time. Thank you ! )

Related

Weird php hyperlink issue

This is kinda tricky as I'm using php to output my content and it's a lot of code.
If you go to http://www.nunchycrut.com#nav=resources&rsc=articles&year=2014 you should see articles listed for 2014 - there is only one called memory lane.
When you mouseover the link it doesn't seem to work as it should. the link is underlined on a mouseover but it seems you have to click the actual horizontal underline to follow the link, if you click on the text it won't work.
All of the other links (in orange) on the page are created using the same class this only appears to be happening in the article listings.
Here's the section of php that is outputting the article link:
<div
style='position: relative; float: left; margin-top: 0px; margin-left: 4px;'
onclick='showArticle(\"" . $strY ."\", \"" . $arrLines[4] . "\");'
>
<b>" . $arrLines[1] . " -- </b>
<a
href='#nav=resources&rsc=articles&year=" . $strY . "&art=" . $arrLines[4] . "'
>
" . $arrLines[0] . "
</a>
</div>
$arrLines[0] holds the actual article name (memorylane). I've been playing about with this for a while trying to figure it out, it's the fact that other links are working fine. I've never seen this before with a hyperlink, anyone any clues?
I can post the css class code but I don't think that's the issue here as like I said, the class is being used all over without problems (the 2014 and 2015 article archive links for example).
It's not a huge problem on a browser but I tested it with my phone and it's quite difficult to open that particular link due to this issue/
I did try using the onclick='' attribute in the actual hyperlink like:
<a
href='#nav=resources&rsc=articles&year=" . $strY . "&art=" . $arrLines[4] . "'
onclick='showArticle(\"" . $strY ."\", \"" . $arrLines[4] . "\");'
>
" . $arrLines[0] . "
</a>
But it's still doing the same thing. Happening in all browsers, any ideas or solutions would be appreciated.
Thanks.
You need to make 2 changes (remove float:left):
<p class="ContentReg" style="position: relative; margin-top: 0px; margin-left: 4px;" onclick="showArticle("2014", "memorylane");">
<b>November 12, 2014
-- </b>
<a href="#nav=resources&rsc=articles&year=2014&art=memorylane">
A trip down memory lane.
</a>
</p>
and change (remove position:relative)
<p class="ContentSmall" style="float: right; margin-top: 8px; margin-left: 10px; margin-right: 4px; text-align: right;">
By <font color="#6495ED">Nunchy
</font>
</p>
Remove position: relative in your inline style for paragraph tag.
<p class="ContentSmall" style="/* position: relative; */ float: top; margin-top: 8px; margin-left: 10px; margin-right: 4px; text-align: right;">
Your hyperlink needs to go from:
href='#nav=resources&rsc=articles&year=" . $strY . "&art=" . $arrLines[4] . "'
to:
href='#?nav=resources&rsc=articles&year=$strY&art=$arrLines[4]'
When you use a double quote (") with an echo it will echo the variable, however if you use a single quote (') with an echo it will echo the text as is.
When constructing a hyperlink for PHP you should keep in mind:
- where on the page to go
? - indicates you're setting page variables

Account info Formatting issues

so I have this little box on my site that displays links about the user when logged in. I just added a feature where it gets how many unread messages the user has and displays it next to messages "Messages (1)". It just messed up the formatting completely and I tried to fix it but it isn't cooperating. I have been fighting it for over an hour, any help would be greatly appreciated.
To see what I am talking about, go to the link and the box is in the top right corner. I am trying to get the links to be inline. So it should read:
My Account Messages (0) Logout
right now, the logout is
in a weird position and I can't seem to resolve it.
URL: http://www.clanrippgaming.net/
Thanks a bunch
Here is the php code:
echo "<div class='logged_in'>";
echo "<div class='welcome'>".$user->data['username'] ;"</div>";
echo "<div class='account'>My Account</div>";
echo "<div class='account'>Messages (".$user->data['user_new_privmsg'].')';"</div>";
echo "<div class='account'>Logout</div>";
echo "</div>";
And the CSS for it:
.logged_in {
background-image:url(images/bg_login2.png);
border:3px solid#000000;
outline:1px solid#BDBDBD;
width:304px;
height:55px;
margin-left:-2px;
padding-top:5px;
}
.logged_out {
margin-right: 22px;
position: relative;
}
.logged_out_txt {
margin-top:-20px;
}
.welcome {
color:#B40404;
font-size:22px;
font-family:"Rockwell";
padding-left:15px;
float:left;
font-weight:bold;
}
.account {
font-weight:normal;
list-style:none;
float:right;
position:center;
padding:0px;
margin-top:-5px;
font-size:16px;
text-decoration:underline;
margin-right:15px;
display: inline;
}
.account a:hover {
color:#D8D8D8
}
echo '<div class="account">Messages ('.$user->data["user_new_privmsg"].')</div>';
I think that should do the trick.
My tip: be consistent, choose what you want to use: double quote for attributes? Okay, then stick with that, don't go switching that over mid-code.

displaying items from database in rows

This image shows my website's homepage.
http://i163.photobucket.com/albums/t315/smc22_2007/Website.png
I want rows of 4, not rows of 5.
Here is my php code:
<?php
$query = "SELECT * FROM UFPProducts";
$results = mysql_query ($query, $connect);
while ($row = # mysql_fetch_array($results))
{
print
"<div id= 'item'>" .
"<p>Product id ".$row["ProductID"]."</p>".
"<p><img src=".$row["Image"]."></p>".
"<p>&pound".$row["Price"]."</p>".
"<p>".$row["Description"]."</p>".
"</div>";
}
Here is the CSS for the above:
#item {
width:100px;
text-align:center;
border: 1px solid #D9D9D9;
padding: 0px;
list-style: none;
width: 150px;
float: left;
margin-right: 15px;
margin-bottom: 15px;
border-radius: 10px;
-moz-border-radius: 10px; /* firefox rounded corners */
-webkit-border-radius: 10px; /* Safari rounded corners */
min-height: 220px;
}
#item li h1 {
text-align:center:
}
#item li#white{
min-height: 220px;
}
How can I display rows of 4, not 5?
Thankyou
From looking at the code, there doesn't seem to be anything that "forces" five rows that you could simply change to four. It is quite possible that the width of the parent element naturally causes the items to appear in rows of five. If that is the case, you have a couple of options. You could add left and/or right margins or change the widths of the items to make them wider and force them to overflow to the next row sooner. Or, you could implement a counter in the PHP that would add a <br> tag (or similar) after every four items. You could also shrink the parent element, though that might not be an option. The CSS options are simple enough, in #item, increase the width:
#item {
width:100px;
/*... other css ...*/
}
In the PHP:
<?php
//rest of code
$counter=0;
while ($row = # mysql_fetch_array($results))
{
print
"<div id= 'item'>" .
"<p>Product id ".$row["ProductID"]."</p>".
"<p><img src=".$row["Image"]."></p>".
"<p>&pound".$row["Price"]."</p>".
"<p>".$row["Description"]."</p>".
"</div>";
$counter++;
if ($counter==3) {
$counter=0;
print "<br>";
}
}
Your products are currently set to float with a width of 150px. Since you're floating it will continue to add items until they don't fit (ie, if your items are 10px wide in a 75px wide container and you add 8, you'll see 7 on one 'row' with 1 on the next). You can simply increase the width to fit the container that your products are in until you've got 4 items per 'row'. Your margins and any padding also add to this so keep that in mind.
#item {
...
width: 200px;
...
}
If you don't want to increase the width of your product cells, then increase the margin to the increase the effective width of the elements.
#item {
...
margin-right: 20px;
...
}
You should also update your items to use a class instead of an ID since ID are supposed to be unique on a page.
.item {
...
}
<div class='item'>...</div>
As far as I see, while loop does not enforce any restrictions. Well my suggestion would be something like this:
$i = 1;
$cssClass = 'item';
$columns = 4;
while ($row = # mysql_fetch_array($results))
{
$class = $cssClass;
if (($i % $columns) == 0) {
$class .= ' clear';
}
print "<div id='{$class}'>" .
"<p>Product id " . $row["ProductID"] . "</p>" .
"<p><img src=" . $row[" Image"] . "></p>" .
"<p>&pound" . $row["Price"] . "</p>" .
"<p>" . $row["Description"] . "</p>" .
"</div>";
$i++;
}
And then in css define:
.clear { clear:both; }

CSS: Positioning of individual images

I am building a comics website, but am having trouble aligning the images the way I want.
I'm going for this:
I'm trying to get the comics in a row like this (blue)
But all the images are coming out on top of each other:
I thought my CSS was correct...
*{
margin: 0;
padding: 0;
}
body {
background: gray;
text-align: center;
}
#wrapper {
width: 960px;
margin: 0 auto;
text-align: left;
background: white;
}
#comics {
/*top, right, bottom, left*/
margin: 50px 100px 50px 100px;
}
.comicBG {
position: absolute;
border: 1px dotted black;
background: #99FF33;
padding: 25px;
}
PHP:
echo '<td>';
echo '<span class="comicBG"><a href="./templates/viewcomic.php?id=' . $row['imgid'] . '">
<img src="' . $thumbpath.$row['imgthumb'] . '"/></a>' .
'<br />' . $row['imgtitle'] . '</span>';
echo '</td>';
Does anyone know the best way to position individual data elements (like the images)?
Should I be using a table, or a list?
Thanks!
I'd use an unordeder list. And you see all the images at the same place because you've set their position to absolute and you haven't set any coordinates.
You can remove position:absolute and the images should be in rows. And if you use an unorderer list, you can float the li's to the left.

HTML/CSS question: Part of div being floated to next line, I want it on the same line

I am loading names/grades from a database which happens perfectly... however, the grade assosciated with the person is for some reason getting floated down to the next line and I can't figure out why, as you can see in this picture: http://i.stack.imgur.com/rqhjp.png
I want that number grade to be on the same line, aligned on the right, but I cant figure out why it's getting pushed down to the next line. Here is my php:
echo '<div class = "name">' . $firstname . " " . $lastname . "<strong>" . '<p align="right">' . $avg . '</p></strong></div>';
And the CSS it refers to:
}
#content .name{
background: #FFF;
float:left;
width: 220px;
padding: 0px;
position: relative;
margin: 0px;
font-size: 1.4em;
border: 2px solid #CCC;
border-radius: 10px;
}
Instead of using p and align, put the grade in a span and float it to the right. You can see it working in this fiddle.
'p' is a block element and takes, by default, 100% width.
You can either set a width on the p tag or float right.
I think that if you want to display every person you should use table instead of divs

Categories