I have absolute positioned "containers" in witch my java elements are running. the background image is working responsive with the page but the "containers" are not scaling. Is there a way to make them scale with the image that they are positioned "on-top" of ? here is some of the code I'm using.
CSS
#forest2 {
width: 960px;
max-width: 100%;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
}
PHP
<div class="forest2" style = "position: relative" >
<img src = "http://xxx/wordpress/wp-content/uploads/2013/01/xxx.png">
<div style = "position: absolute; top: 315px; left: 24px;" class="slideshow0" >
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/1.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/2.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/3.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/4.jpg"/>
<img src="http://xxx/wordpress/wp-content/themes/responsive-child/images/5.jpg"/>
</div>
Script statement .. if needed but probably not
<script type="text/javascript">
$(document).ready(function() {
$('.slideshow0').cycle({
fx: 'fade',
random: true,
timeout: 6000,
speed: 3000,
delay: 100,
});
Resolved with a different method. Adapted AS3 to work in place of java. It works with the responsive design and all the variables are passed fine.
Related
I'm not sure if this is possible but I'll ask anyway...
I'm trying to use the PHP shortcode in Advanced Custom fields
<?php the_field('charitynumber'); ?>
for our client to enter a number on the back end between 1-100. This will effect the height of a div showing/hiding an image based on a overall goal number for a charity. I'm thinking of setting it up like
<div style="<?php the_field('charitynumber'); ?>"><img src="/img_here.jpg"></div>
But cannot think of how to do it or an alternative way.
You need to put the shortcode in a valid style attribute. That means outputting the style name and appending the appropriate units. Also, if the_field() returns a string, you need to echo it.
<div style="height: <?php echo the_field('charitynumber'); ?>%;"><img src="/img_here.jpg"></div>
Give this a shot - you can
<div class="progress">
<div class="fillBar" style="height:calc(100% - <?php the_field('charitynumber'); ?>);"></div>
<img src="/img_here.jpg">
</div>
Then from there, you just need to style the bar. My example below has the progress bar locked to the bottom, and when you land on the page the progress bar will animate from the top down until it stops at the current percentage.
.progress{
position: relative;
width: 50px;
height: 200px;
}
.progress img{
width: 50px;
height: 200px;
position: absolute;
z-index: 1;
}
.progress .fillBar{
width: 50px;
bottom: 0;
height: 200px;
transition: height 0.3s ease-out;
}
I'm trying to make square images from rectangular in css. They also need to be centered.
I've read a lot of questions here, but the answers, good as they might be, always use constant sizes in pixels whereas I need tem to be in percents so the theme can remain responsive.
Basically I need to change this:
into this:
but if the screen is even smaller:
The main problem here is I cannot predict the screen size. It is designed for mobile, so they can vary.
I was thinking about doing css in php (it's for wordpress so it's possible). I was thinking something like width:50% and use the width as a variable, but if I set the height to be equal to width, it will be 50% as well. Is there a way to, I don't know, convert the width to pixels or something? I'm out of ideas, please help.
The problem is, that it is just not possible to change the height relative to the width. So your problem is not the image itself (using overflow: hidden or background-size: cover will do that) but having the square size of your container with dynamic width and then the same height.
A very strange way would be to use a square image (_blank.png with 1px x 1px) and add width: 100% so the height will be the same.
with css:
div{width: 30%;}
img{width: 100%;}
and then add your actual picture as background-image with
background-size: cover;
background-position: center;
Neither performant nor beautiful, but it works.
have you tried this
img { width: 80%; }
make sure there is no height for img in your css file. Also make sure not to set something like height="500px" width="500px" in your html/php file.
also to be centered just do
img { margin: auto; }
Nice picture ;)
If you have an image you want centred—but covers—a parent element, using CSS only, then you’ll need two wrappers:
This works only for wide images. Portrait images will just centre themselves within the container.
<!DOCTYPE html>
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
}
.outer-wrapper {
position: relative;
width: 200px;
height: 200px;
margin: 0 auto;
overflow: hidden;
}
.inner-wrapper {
position: relative;
display: inline-block;
right: -50%;
}
.inner-wrapper img {
display: inline-block;
position: relative;
left: -50%;
}
</style>
</head>
<body>
<div class="outer-wrapper">
<div class="inner-wrapper">
<img src="//placehold.it/400x200" alt="" />
</div>
</div>
</body>
</html>
Just use img{max-width:100% !important; margin:0 auto !important;} and I think it will help you.
Try following css for your image. It won't break the pixels/dimensions for the image.
.imageClass img {
width: 50%;
height: auto;
}
.imageClass img {
width: auto;
height: 50%;
}
<img src="image_path" alt="" class="imageClass" />
Forgive me if this question has been asked before, but I always pull together random hacks for images and want to know a definitive way to do what I'm seeking. Here's the HTML:
<div class="track-artwork">
<img src="<?php echo $chart_track->image; ?>" class="background-image">
<audio>
<source src="" type="audio/mp4" />
<source src="" type="audio/aac" />
</audio>
</div>
</div>
The image I'm linking to is 111px X 111px. It needs to be smaller to fit into the track-artwork div and be fully displayed. I do not have the ability to edit the asset's size with something like photoshop. I want to make it so the image acts as a "background" of sorts, sized to fit the "track-artwork" div with 5px of margin on either size. Here's the CSS I've toyed with to achieve this:
.track-artwork {
cursor: pointer;
display: inline-block;
height: 100%;
margin: 0;
position: relative;
vertical-align: top;
width: 20%;
}
.background-image {
position: absolute;
z-index: 0;
width: 100%;
top: 0;
left: 0;
}
Unfortunately, this isn't working out. The width seems to be sized properly, but the height isn't working -- it seems to stay 111px no matter what I input. I've tried it with hard pixel values, but it doesn't change. Thoughts?
I would set the image to the div background and use either contain or cover as the background-size.
.track-artwork {
cursor: pointer;
display: inline-block;
height: 100%;
margin: 0;
position: relative;
vertical-align: top;
width: 20%;
background-size: cover; // or background-size: contain;
}
Cover will fill the entire div with the background image, cutting off part of the image if the ratios aren't the same.
Contain will resize the image to be fully visible within the div.
You'll have to set the background-image url to the correct image location using php.
You can do this with the CSS3 background-size property.
PHP
<div class="track-artwork" style="background-image:url(<?php echo $chart_track->image; ?>);">
<audio>
<source src="" type="audio/mp4" />
<source src="" type="audio/aac" />
</audio>
</div>
CSS
.track-artwork {
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
}
IE8 Polyfill
If you need to support IE8, there is a Polyfill. You can get it, and information on how to use it at: https://github.com/louisremi/background-size-polyfill
I was wondering how i could make 'this' iframe/div (marked with a red border) use all the available height. The iframe is 160px from top, and i want it to go to the bottom. When i set height # 100% it will fill everything, but when i make the webpage less tall, it will show the scroll-bar very late. This is because he is 160px from top... Does anybody know how to fix this?
php:
<div id="sidebar" style="display: none;">
<div class="sidebar p1"><a onclick="toggle_visibility('sidebar');"><i class="icon-arrow-left-3 fg-color-white"></i></a></div>
<div class="sidebar p2">settings</div>
<div class="sidebar p3">change theme color:</div>
<iframe id="data" src="/test/coredata/sidebar/theme_data.php"/>
</div>
css:
#sidebar{
width: 315px; height: 100%;
position: fixed; right: 0px;
top: 0px; background: #004d5f;
}
#data{width:310px; height:300px; position:absolute; top: 160px; left: 0px; border:3px solid #FF0000;}
screen:
http://puu.sh/21vAz (in url due 10 rep...)
You have set height of your iframe to be 300px:
#data{width:310px; height:300px;
You should set it to 100% if you want it to fill all the frame
<script language="JavaScript">
<!--
function calcularAltura()
{
//Calcular a altura da página actual.
var the_height=
document.getElementById('the_iframe').contentWindow.
document.body.scrollHeight;
//Alterar a altura do iframe
document.getElementById('the_iframe').height=
the_height;
}
//-->
</script>
<iframe width="700" id="the_iframe"
onLoad="calcularAltura();"
src="/test/coredata/sidebar/theme_data.php"
scrolling="NO"
frameborder="0"
height="1">
</iframe>
IT should work ;)
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.