So, I've been trying for some time now to figure out how to position a footer correctly. I was browsing some already-asked questions here on SO and I found some ideas which I implemented but that didn't make my footer to work.
Here is the basic explanation. I have bellow written code for my footer. The problem is that the footer "fly" in page if post is not long. I'm coding (better say rewritting) a simple CMS from C to PHP and I'm not into CSS or design overall.
Here is the code:
#footer {
position: static;
background: #346 repeat scroll 0 0;
border-top:3px solid #CCCCCC;
clear: both;
color:#FFFFFF;
font-size:x-small;
line-height:100%;
margin: 2em 0 0;
width: 100%;
text-align: center;
padding:3px 10px 10px;
bottom: 0;
}
Single post view (bad, you see white space left bellow the footer):
(source: easycaptures.com)
Few posts that filled whole page (good, footer bellow pagination):
(source: easycaptures.com)
On the other side when I have position set to fixed I have this overflow:
(source: easycaptures.com)
How do I make my code works fine like in picture where it says (good)?
EDIT: For those who say to change position, I've already tried all positions property (static, absolute, fixed, relative, inherit).
Here is my container code:
#contener {
margin: 0 auto;
text-align: left;
width: 100%;
}
Other:
body, html, #menu, img, a img, form, fieldset {
margin:0;
padding:0;
font-size: 12px;
}
When I set position to "absolute" I got this picture.
Here is my full code of pagination + footer:
<?php
$currentPage = 1;
if(isset($_GET['page'])){
$currentPage = protect_sqli($_GET['page']);
}
$e = $currentPage * $num_psts; // end post
$p = $e - $num_psts+1; // start post
$i = 0;
// Create a connection
$conS = mysqli_connect($hName, $dbUser) or die(mysql_error());
// Select a specific database
mysqli_select_db($conS, $dbName) or die(mysql_error());
// Query creating
$result = mysqli_query($conS, "SELECT * FROM posts ORDER BY dat DESC, tim DESC");
while($row = mysqli_fetch_array($result))
{
$i++;
if($i >= $p && $i <= $e)
{
$postId = protect_sqli($row['slug']);
readfile('p/' . $postId . '.php');
}
}
?>
<center>
<p>
<?php
$result = mysqli_query($conS, "SELECT id FROM posts");
$nPosts = mysqli_num_rows($result); // number of posts
mysqli_close($conS);
echo "Pages: ";
$pages = $nPosts/$num_psts; // number of pages
for($i = 1; $i < $pages+1; $i++)
{
if($i == $currentPage)
{
echo "<strong>".$i."</strong> ";
}
else
{
echo "". $i ." ";
}
}
?>
</p>
</center>
<div id="footer">
<?php readfile(__DIR__ . "/mvc/fe/footer.php"); ?>
</div>
</div>
footer.php:
Made by dn5 | <font color="#e1c1aa">cblogphp</font>
Do you mean a sticky footer which is always on the bottom of your site?
The CSS goes like this:
html, body {
height: 100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -155px; /* the bottom margin is the negative value of the footer's height */
}
.footer, .push {
height: 155px; /* .push must be the same height as .footer */
}
I think what you are looking for is a Sticky Footer. Ryan Faits has some clear instructions here
Try changing the position to absolute:
#footer {
position: absolute;
background: #346 repeat scroll 0 0;
border-top:3px solid #CCCCCC;
clear: both;
color:#FFFFFF;
font-size:x-small;
line-height:100%;
margin: 2em 0 0;
width: 100%;
text-align: center;
padding:3px 10px 10px;
bottom: 0;
}
Demo: http://jsfiddle.net/JE5fn/1/
From CSS tricks: http://css-tricks.com/snippets/css/sticky-footer/
<div class="page-wrap">
Content!
</div>
<footer class="site-footer">
I'm the Sticky Footer.
</footer>
* {
margin: 0;
}
html, body {
height: 100%;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
/* .push must be the same height as footer */
height: 142px;
}
.site-footer {
background: orange;
}
Related
I am trying to make a webpage which displays rectangles of different sizes in a grid.
The code below works to display 3 rectangles all height: 50px and width equal to $rectangleWidth = "200px".
<html>
<head>
<style>
<?php
$rectangleWidth = "200px";
?>
.grid-container {
margin: auto 1fr;
max-width: 8000px;
display: grid;
grid-template-columns: 400px
}
.grid-container div {
border: 1px dashed gray;
text-align: center;
padding: 12px;
}
.pre { display: inline; }
<?php echo ".rectangleRed {
height: 50px;
width: " . $rectangleWidth . ";
background-color: #ff1a1a;
float: left;
margin-right: 0px;
}";
?>
</style>
</head>
<body>
<div class="grid-container">
<?php
for ($x = 0; $x < 3; $x++) {
echo '<div><pre class="rectangleRed"></pre></div>';
}
?>
</div>
</body>
</html>
I have an array with three different widths $rectangleWidths = ["100px", "200px", "300px"]. I am struggling to make the rectangles change size according to the widths.
I tried to put the CSS code for .rectangleRed { } into a php block with the width as a variable so that the width of the rectangle is redefined each increment of the loop. This didn't work. The CSS code was displayed on screen instead of redefining the width of the rectangle. Here is the code from my attempt:
<html>
<head>
<style>
<?php
$rectangleWidths = ["100px", "200px", "300px"];
?>
.grid-container {
margin: auto 1fr;
max-width: 8000px;
display: grid;
grid-template-columns: 400px
}
.grid-container div {
border: 1px dashed gray;
text-align: center;
padding: 12px;
}
.pre { display: inline; }
</style>
</head>
<?php
for ($x = 0; $x < 3; $x++) {
$rectangleWidth = $rectangleWidths[$x];
echo "<style><head>.rectangleRed {
height: 50px;
width: \"" . $rectangleWidth . "\";
background-color: #ff1a1a;
float: left;
margin-right: 0px;
}</style></head>";
echo '<body><div class="grid-container"><div><pre class="rectangleRed"></pre></div></div></body>';
}
?>
</html>
My only guess for why this doesn't work is that maybe I incorrectly used the , , and tags. I'm not sure how I could do this differently to make it work.
I looked at similar questions including Apply CSS Styling to PHP output and How to add CSS styles to a PHP code within a loop?. The solutions for those questions did not resolve my issue.
I've been having trouble for a few hours now trying to understand what I'm doing wrong with this styling. I have a webpage that displays a user post on the left half, and the comment-section along with the comment form on the right half. I have a PostCommentSet class that contains all comments and replies. Right now, my comments are overlapping ontop of each other, they should be placed underneath the former so that both are visible. If a comment has any replies, the reply should be placed below the same comment and then when there aren't any more replies to display, we continue with more comments.
Like this,
Comment 1
...Reply 1 of comment 1
...Reply 2 of comment 1
Comment 2
Comment 3
...Reply 1 of comment 3
Comment 4
etc..
There are elements within the comment and reply classes that have positioning, would that be what is messing it up?
If you have any questions about my code, I will be ready to answer them.
My CSS
.PostCommentSet {
position: absolute;
right: 0px;
top: 60px;
width: 30%;
height: calc(100vh - 207px);
background-color: #777;
padding: 10px 2.5% 0px 1%;
overflow: scroll;
overflow-x: hidden;
}
.PostComments {
background-color: #555;
padding: 10px;
border-radius: 4px;
color: white;
width: 90%;
height: auto;
box-shadow: 0px 0px 5px black;
position: static;
z-index: 2;
display: inline-block;
}
.PostReplies {
background-color: #555;
padding: 10px;
color: white;
border-radius: 4px;
width: 80%;
height: auto;
box-shadow: 0px 0px 5px black;
position: static;
z-index: 1;
display: inline-block;
}
My Php / HTML
while ($commenterrow = mysqli_fetch_assoc($commenterresult)) {
echo '<div class="PostCommentSet"> <div class="PostComments">';
if ($commenterrow['profileimg'] == 1) {
$filename = "profilepics/profile".$commenterid."*";
$fileinfo = glob($filename);
$fileext = explode(".", $fileinfo[0]);
$fileactualext = $fileext[1];
echo "<div class='CommentProfilePicture'><img src='profilepics/profile".$commenterid.".".$fileactualext."?".mt_rand()."'></div>";
}
else {
echo "<div class='CommentProfilePicture'><img src='profilepics/noUser.png'></div>";
}
echo "<div class='CommentUserName'>".$commenterrow['userName']."</div>";
echo "<div class='CommenterComment'>".$commentrow['comment']."</div> </div>";
}
$currentcommentid = $commentrow['commentid'];
$replysql = "SELECT * FROM posts WHERE hostid = '$hostid' AND postid = '$postid' AND commentid = '$currentcommentid' AND replyid > 0";
$replyresult = mysqli_query($conn, $replysql);
while ($replyrow = mysqli_fetch_assoc($replyresult)) {
if (mysqli_num_rows($replyresult)==0) {
echo '</div> <br>';
}
else {
$replierid = $replyrow['userid'];
$repliersql = "SELECT * FROM users WHERE userid = '$replierid'";
$replierresult = mysqli_query($conn, $repliersql);
while ($replierrow = mysqli_fetch_assoc($replierresult)) {
echo '<div class="PostReplies">';
if ($replierrow['profileimg'] == 1) {
$filename = "profilepics/profile".$replierid."*";
$fileinfo = glob($filename);
$fileext = explode(".", $fileinfo[0]);
$fileactualext = $fileext[1];
echo "<div class='ReplyProfilePicture'><img src='profilepics/profile".$replierid.".".$fileactualext."?".mt_rand()."'></div>";
}
else {
echo "<div class='ReplyProfilePicture'><img src='profilepics/noUser.png'></div>";
}
echo '
<div class="ReplyUserName">'.$replierrow['userName'].'</div>
<div class="ReplierReply">'.$replyrow['reply'].'</div>
</div>
</div>
Pretty difficult here without seeing the rest of your css, but i'm confused as to why you're using inline-block level display on your postReplies and postComments elements. This attribute applies to the elements themselves, not their children within. I'd suggest changing both these to block display and see if that helps first. Also, there is no need to declare position:static.
The best thing you could do is strip out your markup and create a fiddle which duplicates your issue. From there it would be an easy fix. Otherwise, please post the css for your whole (relevant) markup.
I'm looking at building a dynamic navigation something that looks similar to that in w3schools (I don't have enough points to be able to embed images yet so stuck with links only for now):
These will be based off the following PHP table:
enter image description here
Where parent_id and child_id are 0 I want those pages to be the main navigation selections, so in this case I'm looking to have DMX, VMAX, VMAX3, VMAX AF and PowerMax to show on the navigation bar.
After that the idea is to list the models of each product, however this is only to appear when the user is hovering over one of the main selections, the parent_id is to equal the id of the page.
Finally when you hover over the result of the parent_id you will get the child_id, this will be decided by the child_id equaling the parent_id.
The functions I'm calling in my code is:
function loop_array($array = array(), $parent_id = 0){
if(!empty($array[$parent_id])){
echo '<ul>';
foreach($array[$parent_id] as $items){
echo '<li>';
?>
<?php echo $items["title"] ?>
<?php loop_array($array, $items['id']);echo '<br><br><br><br>';
}
echo '</ul>';
}
}
function display_menus(){
$con = mysqli_connect("localhost", "root", "", "solvedesktop");
$query = $con->query("SELECT * FROM pages WHERE published = 1");
$array = array();
if(mysqli_num_rows($query)){
while($rows = mysqli_fetch_array($query)){
$array[$rows['parent_id']][] = $rows;
}
loop_array($array);
}
}
The code I'm using on the home page is:
<?php require_once(__DIR__."/../includes/functions.php"); ?>
<?php require_once(__DIR__."/../includes/config.php"); ?>
<?php require_once(__DIR__."/../includes/header.php"); ?>
<?php $page = getPage($_GET["id"]); ?>
<h2 style="text-align:center;">PSE Solve Desktop</h2>
<?php display_menus(); ?>
</div>
<div>
<?php echo returnPageError(); ?>
</div>
<h2> <?php echo $page['title']; ?> </h2>
<br>
<p> <?php echo $page['body']; ?></p>
<script>
CKEDITOR.replace( 'body' );
</script>
The CSS I currently have is:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #00008B;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: #000000;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
So basically I can't get further than the below image when trying to build the navigation bar:
enter image description here
I can get the main sections such as DMX, VMAX, VMAX3, VMAX AF and PowerMax to populate correctly. However it's not showing in one horizontal line and the parent_ids show only appear if the user hovers over the main section.
Any help would be gratefully appreciated :)
Here the problem is with CSS just add some max-width to menu items.
by this solved or not let me know.
I have been racking my brains trying to figure out how to change what I have into something that will organise my content into as many rows as necessary and as many columns (divs) as necessary when the screen resolution changes.
Basically, my current website set up has a content div with a height of 430px which can accommodate any number of columns because I have a horizontal scroll. Within each column there can be up to 10 rows of data before another column is created for the next lot of data.
What I want to do is change the height of the content div to % not px so it will scale with the browser res. My current script will still only output the same number of rows and columns if the content div is too small of too big, so what I want is to have the number of rows less for smaller screen res's and more for higher res screens.
I kind of want the content to wrap into the next column (div) if the browser is made smaller.
Hope this makes sense.
Can someone point me in the right direction? I know this code is currently written differently but I cant think how to do it:
functions.php:
<?php
function printTranscriptions()
{
global $link;
$query = "SELECT * FROM transcriptions ORDER BY artist, title";
if ($result = mysqli_query($link, $query)) {
$count = 0;
while ($row = mysqli_fetch_row($result)) {
if (($count % 10) == 0) {
if ($count > 0) {
echo "</div>\n";
}
echo '<div class="content_columns">'."\n";
}
$artistTitle = $row[1] . ' - ' . $row[2];
echo '<p>' . $artistTitle . '</p>'."\n";
$count++;
}
if ($count > 0) {
echo "</div>\n";
}
/* free result set */
mysqli_free_result($result);
}
}
My index file calls the content in the following structure:
<!-- Transcriptions page start -->
<div class="transcriptions_page">
<h1>
Transcriptions
</h1>
<div class="content">
<div class="list-wrapper">
<div class="transcription-list">
<?php printTranscriptions();?>
</div>
<!-- transcription-list end -->
</div>
<!-- list-wrapper end -->
</div>
<!-- content end -->
</div>
<!-- Transcriptions page end -->
My css:
.content {
display: block;
overflow: hidden;
background-color: #2D949E;
color: #fff;
text-shadow: #FAFAFA;
margin-top: 75px;
margin-left: 10%;
margin-right: 10%;
padding: 20px 20px 20px 20px;
height: 430px;
border: 1px solid #99E9F1;
}
.list-wrapper {
overflow: hidden;
}
.transcription-list {
display: block;
white-space: nowrap;
}
.content_columns {
display: inline-block;
background-color: #429EA8;
letter-spacing: 1px;
margin-right: 20px;
padding: 0 10px;
}
.content_columns:last-child {
margin-right: 0 !important;
}
Thanks
I am having trouble figuring out the logic in creating a grid using DIVs. 3 Columns (the $count variable), then fill those columns with however many boxes. ($totalBoxes)
Below is an example of what I would like to accomplish.
I have tried using logic on repeated regions for tables, but I don’t know if that is working right. Most of my code spits out something like this screenshot:
Can someone point me where my logic is wrong?
CSS
<style type="text/css">
#container {
background-color: #FFC;
height: 750px;
width: 900px;
padding: 5px;
}
#container #column {
background-color: #FC6;
width: 200px;
padding: 5px;
float: left;
margin: 5px;
}
#container #column #box {
background-color: #9C3;
height: 150px;
width: 150px;
margin: 5px;
}
</style>
PHP
<div id="container">
<?php
$count = 3;
$totalBoxes = 8;
?>
<?php for ($i = 1; $i <= $totalBoxes; $i++) {
if ($i % $count == 1){ ?>
<div id="column"> Column <?php echo $i; ?>
<?php } else { ?>
<div id="box"> <?php echo $i; ?> </div>
</div>
<?php } } ?>
</div>
You have error in else thread because you have two closing divs in it.
Also you can't have repeated id
I can't understand do you want 3 columns or 3 rows? If you want 3 columns that your code will not work on totalBoxes mote than 9 (it will produce more columns).
I suggest you to use following logic:
<style>
.column {float: left; padding: 10px; width: 100px; border: solid thin red; background-color: green; margin-right: 5px}
.box {width: 100%; height: 100px; background-color: white; margin-bottom: 5px; }
</style>
<?php
$boxes_in_column = ceil($totalBoxes / 3);
echo('<div class="column">Column 1');
for ($i = 1; $i <= $totalBoxes; $i++) {
echo('<div class="box">'.$i.'</div>');
if (($i % $boxes_in_column) === 0){
echo('</div><div class="column">Column '.(ceil($i / $boxes_in_column)+1));
}
}
echo('</div>');
?>
It will produce extra empty column if you have total boxes divided by 3 without remainder. So try to fix it yourself.
Horizontal fill
<style>
.box1 {display: inline-block; width: 100px; height: 100px; background-color: white; margin: 5px; }
.parent {background-color: blue; border: solid thin red; width: 330px}
</style>
<?php
$totalBoxes = 13;
echo '<div class="parent">';
for ($i = 1; $i <= $totalBoxes; $i++) {
echo('<div class="box1">'.$i.'</div>');
}
echo '</div>';
?>