Uniqiue background on every page - php

I'm using Drupal 7. My bg image in page.tpl.php file and image get to css.
My html:
<div class="mainimage" id="mainimg" class="clearfix"></div>
And CSS:
#mainimg {
background: url("../img/mainimg.jpg") repeat scroll 0 0 transparent;
height: 500px;
left: 50%;
margin-left: -640px;
position: absolute;
width: 1280px;
z-index: 1;
top:0;
}
My bg image seen all pages. It's normally. But i want, change my bg image on every page.
E.G.
...
mysite.com/index.php -bg image: mainimg.jpg
mysite.com/news -bg image:news.jpg
mysite.com/about -bg image: about.jpg
...
How can i solve this?

You can use the built-in Drupal functions to add a unique identifier to the body, so you can target each page individually in your CSS.
For example, if the body had id="news", you could change the background image by adding this to your CSS:
#news #mainimg {
background-image: url("../img/news.jpg");
}

Use a different class per each page.
mysite.com/news
HTML
<div class="mainimage news-bg" id="mainimg" class="clearfix"></div>
CSS
.news-bg {
background: url("../img/news-bg.jpg") repeat scroll 0 0 transparent;
}
mysite.com/about
HTML
<div class="mainimage about-bg" id="mainimg" class="clearfix"></div>
CSS
.about-bg {
background: url("../img/about-bg.jpg") repeat scroll 0 0 transparent;
}

make the image php generated.
1) set header("content-type: image/jpg");
2) check from which page the request came and choose image
3) echo the binary data of your image.
Say this is in the file bg.php, you have to set background-image:url('bg.php');
Example:
function currentPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}
if(currentPageName() == "news.html")
$imagedata = file_get_contents('path/to/news.jpg');
//etc
header('Content-type: image/jpg');
echo $imagedata;

Related

Grid thumbnail / item size using calc ( )

I'm trying to create a full-width responsive portfolio grid. I set the width of the items using calc(), and set the thumbnail image to take up 100% of thumbnail div using:
`img.attachment-portfolio-thumb{
width:100% !important;
height:100% !important;
}`
This works, aside that there is about an extra white 10 pixels below each image, inside each div.portfolio-list, and I can't figure out where it is coming from and how to get rid of it. In "inspect element", when hover over the div.portfolio-list, the div takes up the entire space 100%, so it's something inside the div which is causing the extra space.
What I noticed is that in "inspect element" mode the <a> tag (that the portfolio-thumb thumbnail is in, in the Pods Template), has the following dimensions - and the white extra space if part of it: 315px x 26px (315px is the width of the div.portfolio-list as this browser width).
Link to visual image: The left is on hover, as you can tell the overlay includes the bottom empty 10px. The right bottom you see a white strip.
http://prntscr.com/5yedsp
Below is the code for the grid:
Pods Template:
<div class="portfolio-list">
<div class="overlay">
<p>{#post_title}</p>
{#post_thumbnail.portfolio-thumb}
</div>
PHP:
<section class="portfolio_home_inner">
<section class="portfolio_home">
<?php
echo do_shortcode ('[pods name="portfolio" template="portfolio-list"]');
?>
/ Add Image size for Portfolio List
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
// additional image sizes
add_image_size('portfolio-thumb', 300, 300, true ); // (cropped)
}
CSS:
div .portfolio-list{
float:left;
width: calc(20%);
overflow: hidden;
position: relative;
display: inline-block;
}
/*Wordpress default selector for new image size*/
img.attachment-portfolio-thumb{
width:100% !important;
height:100% !important;
}
div .portfolio-list p{
display: none;
color:#000;
}
div .overlay:hover:after {
content: ' ';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: rgba(234,79,38,.85);
}
Would anyone know what is causing the extra 10px underneath the image?
Thank you!
You image has a margin on it of 32px 0 15px (inspect element with chrome), for the class ".image_pic". Setting the image_pic "margin-bottom : 0;" should sort it out for you, perhaps with the important tag.

overlapping background images of nested div

have background images in nested divs as follows
<div id="templatemo_content" style="padding: 30px 30px 0 0; background: #fff url(images/foot_bg.png) no-repeat 0 bottom; z-index:10">
this div has grey colored background image
<div style="background:url(images/job.png) no-repeat 0 0; height:131px; z-index:5">
this is a nested div with another background image having right bottom overlapping grey colored image
</div>
</div>
below image is what i have achieved so far, however, expected image is the 2nd one below
used z-index to both images however browsing through internet found that z-index does not work on background images. please suggest a solution
You also need to set
position: relative;
Thus, the z-index will - should - be effective.
z-index is relative to the parent container from which z-index is set. As such, a child cannot have a lower z-index than its parent in terms of displaying below it.
You may want to change your HTML
<div>
<div>this is a nested div with another background image having right bottom overlapping grey colored image</div>
<div>this div has grey colored background image</div>
</div>
CSS (will require some alteration)
div {
position:relative;
background:#fff;
height:131px;
}
div:first-child {
background:url(images/job.png) no-repeat 0 0;
margin-top:30px;
height:100%;
width:100%;
}
div:last-child {
background:url(images/foot_bg.png) no-repeat 0 bottom;
position:absolute;
bottom:0px;
height:100%;
width:100%;
}

Page loading GIF - Could someone please explain the answer below?

I found what I was looking for on this link How to show ajax loading gif animation while the page is loading? but I dont know how to implement this on my website.
I want a loading GIF to appear while the page loads and disappears by itself once the page is completely loaded with PHP results.
On the website I use one page template (index.php) and I have all data loaded in that page dynamically according to the user's query.
Thank you in advance.
You will find everything you need here
http://mycodeprograms.blogspot.ca/2012/10/how-to-add-loader-while-page-load.html
When the page is completely loaded, the first thing that happens is the <body>'s onload event fires. This is where you make the image disappear.
For example, make the <body> tag look like this:
<body onload="makeLoadingGifDisappear()">
Somewhere in the page body give your GIF an ID:
<img src="loadinggif.gif" id="myLoadingGif">
Then in the page's JavaScript, make the makeLoadingGifDisappear function hide the GIF:
function makeLoadingGifDisappear() {
document.getElementById('myLoadingGif').style.display = 'none';
}
Well, this is my solution.
1) CSS part
#loadgif {
padding-top:2px;
font: 10px #000;
text-align:center;
vertical-align:text-top;
height: 80px;
width: 130px;
/* Centering the div to fit any screen resolution */
top: 50%;
left: 50%;
margin-top: -41px; /* Div height divided by 2 including top padding */
margin-left: -65px; /* Div width divided by 2 */
position: absolute;
display: none; /* JS will change it to block display */
position: fixed;
z-index: 1000;
/* Loading GIF set as background of the div */
background: #FFF url('../img/loader.gif') 50% 75% no-repeat;
/* Misc decoration */
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
border:#7580a8 solid 1px;
}
2) HTML part
Place div tag within body tag anywhere.
<!-- With or without text -->
<div id="loadgif">Loading...</div>
3) Javascript part
I made two functions, one to show and another to hide the div.
<script type="text/javascript">
// Hide function by changing <div> style display attribute back to none
function hideloadgif() {
document.getElementById('loadgif').style.display = 'none';
}
// Show function by changing <div> style display attribute from none to block.
function showloadgif() {
document.getElementById('loadgif').style.display = 'block';
}
// Making sure that any other event running in the background isn't affected
if (window.addEventListener) { // Mozilla, Netscape, Firefox
window.addEventListener('load', WindowLoad, false);
} else if (window.attachEvent) { // IE
window.attachEvent('onload', WindowLoad);
}
// Call the hideloadgif() function on click event,
// with interval time set to 3 seconds to hide the <div>
function WindowLoad(click) {
setInterval("hideloadgif()",3000)
}
</script>
4) Showing the div.
Call function showloadgif() using onlick="" event anywhere.
For example
<img src="abc/def.jpg" onlick="showloadgif()">
Once the image is clicked, the div will appear and at the same time, hideloadgif() will trigger and hides the div within 3 seconds.
function WindowLoad(click) {
setInterval("hideloadgif()",3000)
}

How can I center an image of *unknown size* in a div, both vertically and horizontally?

I am looking to handle files that were uploaded by users. The main issue in that situation is that they differ in size.
How can I center an image of unknown size, both vertically and horizontally, into a div?
Thanks a lot
EDIT: I am making a thumbnail for an image. Basically, I want to keep the div to the same size, and I want the image inside that div to fit the div, but without changing the scale. I am using overflow:hidden
EDIT:My code is
<div class='pic'><img id='theimage' src='image.png'></div>
and my CSS is
#theimage {
vertical-align: middle;
display: inline;
}
You can do this using the background CSS property. Give your <div> these properties:
div.whatever {
background-position: center center;
background-repeat: no-repeat;
}
Then in your HTML (because it's being generated dynamically), add a style="" attribute to the <div> with the URL of your image in it:
<div style="background-image: url('/path/to/image.png');"></div>
You could do this with an <img> tag inside the <div> too:
<div>
<img src="image.png">
</div>
With this CSS (untested, should work):
div {
text-align: center;
}
div img {
vertical-align: middle;
display: inline;
}
I'm assuming you've given your <div> a fixed width and height elsewhere.
Force the container to behave as a table cell.
#container {
display: table-cell;
vertical-align: middle;
text-align: center;
}
Demo
i got a suggestion though this thread is old
try
< div style='text-align:center;overflow:hidden;width:200px;height:200px;' >
< img src='anypath' width='190'style='vertical-align:middle;display:inline;' />
works just fine ! goodluck

How do you center an image in a specified area, without resizing the image?

I want to center an image in an area, without resizing... I am using HTML.
Example:
I have an image <img src='img1.png' width='64' height='64'> - the image is actually 64x64. It displays perfectly.
Now, I have another image <img src='img2.png' width='64' height='64'> however, the image is not as big as it should be, its 32x32 - what happens here is it resizes the image to 64x64 and makes it look like $%^&.
How do I make images smaller then the desired width and height centered in the 'img' area without any resizing what so ever?
What you will need is something like this:
<div class="box">
<img src="whatever size image you'd like" />
</div>
And for the styling (in an external stylesheet, natch) you'd apply:
/* Image centering */
div.box {
border: 1px black solid;
height: 64px;
width: 64px;
background: #444;
display: table-cell;
vertical-align: middle;
}
.box img {
display:block;
margin: 0px auto;
}
This works for images with dimensions <= 64x64px, and is easily modifiable to work with larger pics. The key elements here are
set dimensions on the div
display as a table-cell (allows vertical align)
vertical align (aligns on the Y-axis w/out weird hacks)
display:block on the img element
margin: auto centers the image laterally
Solution without IE-unfriendly display:table-cell:
<!DOCTYPE html>
<style>
div {
line-height:64px; /* that's the secret sauce */
text-align:center;
width:64px; height:64px;
}
img {vertical-align:middle}
</style>
<div><img …></div>
You could try putting the image inside a DIV that is 64x64 and not specifying the image dimensions. Then you could style the div so its contents are centered and any overflow is hidden.
You can dynamically get an image size using the getimagesize() php function:
<?php
$size = getimagesize('imgX.png');
$height = $size[1];
$width = $size[0];
?>
<div style="text-align: center">
<img src="imgX.png" width="<?php print($width) ?>" height="<?php print($height) ?>" />
</div>
I've had to do something similar with 36x36 images. Users were able to upload any size but the thumbnails were only to show the center 36 square pixels.
Markup:
<li><div><span></span>
<img src="_media/objects/jessica-bowman.png" alt="Jessica Bowman" /></div>
<p>Jessica Bowman</p>
</li>
The span was just there to get rounded corners on the image, it's not necessarily needed.
CSS:
ul.recent-list li div {
position: relative;
float: left;
width: 36px;
height: 36px;
overflow: hidden;
}
ul.recent-list li div span {
position: relative;
z-index: 100;
display: block;
width: 36px;
height: 36px;
background: url("../_media/icons/icon-overlay.png") top left no-repeat;
}
ul.recent-list li div img {
position: relative;
top: -36px;
z-index: 0;
float: left;
}
JavaScript:
$(window).load(function() {
$("ul.recent-list div img").each(function() {
var moveX = ($(this).width() / 2 * -1) + 18;
var moveY = ($(this).height() / 2) * -1 - 18; // 18 is 1/2 the default offset of 36px defined in CSS
$(this).css({'top' : moveY, 'left' : moveX});
});
});
The solution is a simple bit of CSS + HMTL
<img src="transparentpixel.gif"
width="64"
height="64"
style="
background-image:url('path/to/image.jpg');
background-repeat:no-repeat;
background-position:center center;
" />
the transparentpixel.gif is a simple 1x1px transparent gif image
An img tag with width and height attributes is saying "stretch or shrink the image to this size regardless of its actual size". use something like:
<div style="text-align:center;">
<img src="x.jpg">
</div>
and no i don't know why text-align would work, but it appears to in my experience.
Use CSS to render the image using background:
<div style="background: url(img1.png) no-repeat center center; height: 64px; width: 64px;"></div>
This will show the image in the center, without scaling it.

Categories