Div is not rigged onto image and text is not centered properly? - php

I have a main Div which is the "master" of all divs. This div's width is 70% of the page. Inside this div, is another div that contains an image. This div is called mainImg. It is set to absolute positioning and all the rest of the elements are set to absolute as well. All these elements move absolutely relative to the main div.
Here's my code:
PHP/HTML
<?php
$resultSet = $db->query("SELECT * FROM Articles");
if ($resultSet->num_rows != 0)
{
while ($rows = $resultSet->fetch_assoc())
{
$id = $rows["id"];
if ($id <= 3)
{
$images = $rows["image"];
$title = $rows["title"];
echo "<div id=main>";
if ($id == 1)
{
echo "<div id=mainImg>";
echo "<img src=$images>";
echo "<div id=mainTitle>";
echo "<h2>$title</h2>";
echo "</div>";
echo "</div>";
}
echo "</div>";
}
}
}?>
CSS
body{
position: relative;
}
#main{
position: relative;
width: 70%;
height: auto;
margin: 1.5% auto;
}
#mainImg{
position: absolute;
width: 65%;
}
#mainImg img{
width: 100%;
}
#mainTitle{
position: absolute;
width: 100%;
height: 25%;
bottom: 0%;
background-color: rgba(100, 0, 0, 0.7);
}
#mainTitle h2{
color: white;
text-align: center;
font-family: sans-serif;
font-size: 120%;
}
My problem that I am facing is that the div inside of mainImg (mainTitle), is not properly rigged inside the image. The div is a semi-transparent block that should fit perfectly on the bottom of the image with 25% height. Instead, the block is coming out of the image a bit. The other problem that I am facing is my text inside this mainTitle div. The text is centered, but not aligned in the middle of the div. I am trying to make the text responsive, with percentages, but whenever I resize the text always goes below the div. How do I fix these three problems? (Rigging the div properly, aligning the text, and keeping the text inside the div at all times for other window sizes?
The semi-transparent div is coming off the edge of the image
When browser is resized, this is what happens to the text

<?php
$res = $db->query("SELECT * FROM Articles");
if( $res->num_rows > 0 ) {
echo "<div id='main'>";/* Open main div outside the loop */
while( $rows = $res->fetch_object() ) {
$id = $rows->id;
if ( $id <= 3 ) {
$image = $rows->image;
$title = $rows->title;
if ( $id == 1 ) {
echo "
<div id='mainImg'>
<img src='$image'>
<div id='mainTitle'>
<h2>$title</h2>
</div>
</div>";
}
}
}
echo '</div>';/* close main div */
}
?>

Related

Ad removing bottom image links

I have an Adsense ad on top of a couple of images. These images have links and depending on the page query string, it'll display a previous image or not. When having this ad on top of these images, it removes the links on these images. In fact, when you right click you can't even get to those images. It'll say "view frame source" which is referring to the Adsense ad. When removing this ad, the images work correctly and the links work as well. How do I make it so that the images are clickable even with the ad on top of the images?
HTML/PHP
echo "<div class='bodyAd'>
<script async src='//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js'></script>
<ins class='adsbygoogle'
style='display:block'
data-ad-client= $pub_id
data-ad-slot= $ad_slot2
data-ad-format='auto'></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>";
echo "<div class='btns'>";
if ($num == $maxNum)
{
echo "<div id='prevBtn'><img class='prevBtn' src='/media/assets/prevBtn.png' style='display: none'/></div>";
}
else
{
$prevNum = $num + 1;
echo "<div id='prevBtn'><a href='$prevNum'><img class='prevBtn' src='/media/assets/prevBtn.png'/></a></div>";
}
if ($num == $minNum)
{
echo "<div id='nextBtn'><a href='/stories/$nextArticle'><img class='nextBtn' src='/media/assets/nextBtn.png'></a></div>";
}
else
{
$nextNum = $num - 1;
echo "<div id='nextBtn'><a href='$nextNum'><img class='nextBtn' src='/media/assets/nextBtn.png'></a></div>";
}
echo "</div>";
CSS
.btns{
display: block;
overflow: hidden;
width: 100%;
margin-top: 50px;
}
.nextBtn{
width: 35%;
margin-top: 20px;
margin-bottom: 25px;
float: right;
}
.prevBtn{
width: 35%;
margin-top: 20px;
margin-bottom: 25px;
float: left;
}

putting button inside code

My working code outputs all the images in my wordpress post and puts the last image as the background of #last-img which is the last image shown.
I'm trying to place a button inside my code which appears inside the #last-img. I can't put it outside the code since when I tried when I use absolute positioning it uses all the images as a reference point
my code
<?php
preg_match_all('/(<img [^>]*>)/', get_the_content(), $images);
preg_match_all('/src="([^"]*)"/i', get_the_content(), $images1);
$count = count($images[1]);
$count1 = count($images1[1]);
foreach($images[1] as $k=> $img){
if($k == $count-1){
$format = '<div id="last-img" style="background:url(%s)"> ... </div>'; // Or $format = "<div id='last-img' style='background:url(%s)'> ... </div>";
$image = $images1[1][$count1-1];
echo sprintf($format,$image);
}else{
echo $img;
}
}
?>
link code
<div id="top-btn">
<div id="top-rotate"></div>
</div>
css
#top-btn {
display: block;
position: absolute;
z-index: 200;
right: 0; left: 0; bottom: 0;
margin: 0 auto;
height: 60px; width: 60px;
}

Image not displaying in horizontal

I want the image to automatically be in horizontal, Should I put another div? because the picture will be save automatically by their position
And here's my CSS:
.row{
display: block;
height:auto;
width:auto;
}
.box_img2{
width: 20px;
padding : 5px;
margin-bottom:5px;
background-color:white;
height:30px;
float:center;
}
And here's my PHP:
<?php
include('../connection/connect.php');
$result = $db->prepare("SELECT * FROM candposition ORDER BY posid ASC");
$result->bindParam(':userid', $res);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$dsds=$row['posid'];
$resulta = $db->prepare("SELECT sum(votes) FROM candidates WHERE posid= :a");
$resulta->bindParam(':a', $dsds);
$resulta->execute();
for($i=0; $rowa = $resulta->fetch(); $i++){
$dsada=$rowa['sum(votes)'];
}
echo '<div style="margin-top: 18px;">';
echo '<strong>'.$row['pos_name'].' '.'</strong><br>';
$results = $db->prepare("SELECT * FROM candidates,student WHERE candidates.idno=student.idno AND posid= :a ORDER BY votes DESC");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
if($dsds=='Commissoner'){
echo $rows['prog_id'].$rows['prog_id'].' '.$rows['prog_name'].' = '.$rows['votes'];
}else {
echo "<div class='row'><div class='box_img2'><br>";
echo '<img src="savephp/images/'.$rows['image'].'" width="60" height="70px" />'.' '.$rows['lastname'].', '.$rows['firstname'].'<br>'.' = '.$rows['votes'];
echo '</div>';
}
echo '</div>'.'</div>';
$sdsd=$dsada
?>
<br><br><br><br><br>
<img src="../img/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>
<?php
if ($rows['votes']==0){
echo "<br>";}
else {
echo(100*round($rows['votes']/($sdsd),2)); ?>%<br>
<?php
}
echo '</div>';
}
?>
<?php
}
?>
Here's the image:
I want to be like this
Try this:
.box_img2{
width: 20px;
padding : 5px;
background-color:white;
height:30px;
position: fixed; /* or absolute */
top: 50%;
left: 50%;
margin-top: -15px;
margin-left: -10px;
}
Try going down this path, and looking at things like Boostrap's methods to do thumbnail grids, etc., may help you a lot.
Note, the img CSS is more of an either/or thing...one centers, the other will make it fill the 33% of its container.
<style type='text/css'>
.row:before, .row:after { clear:both; }
.img-container {
float:left;
width:33%;
text-align:center;
}
.img-container img { /* if you want it centered */
display:block; margin:0 auto;
}
</style>
<div class='row'>
<?php for($i=0; $rows = $results->fetch(); $i++) { ?>
<div class='img-container'>
<img src="savephp/images/<?php echo $rows['image'] ?>" width="60" height="70px" />
<?php echo $rows['lastname'] ?>, <?php echo $rows['firstname'] ?><br />
=<?php echo $rows['votes'] ?>
</div>
<?php } ?>
</div>
UPDATE I've updated the code above to give a general idea of putting the images into the page. You can build out the rest of the HTML and conditions as needed. The important thing to note is that if you want 3 images across horizontally, make the width of the .img-container 33%. If you only want 2 horizontally, make the width of the .img-container 50%. They will automatically wrap to the next row. Your code was creating a new <div class="row"> for every single entry, which would put each new entry onto its own line rather than having them layout horizontally.
If you hit points where you want a 100% row, you can just give that a different class with width:100% and it will put itself on its own row.
Again, if you lookup how grids work with Bootstrap 3, it will help you get almost any alignment that you want, and I highly recommend using something like that to get going, and then once you're good at creating layouts...then figure out "how" they do it.

Footer not showing the way I would like to

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;
}

How To Wrap Content That Is Generated Programatically In PHP Through Divs Depending On Screen Res

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

Categories