Responsive, transparent CSS image caption with graceful degradation? - image

What is the proper way to create responsive, transparent CSS captions over images — with graceful degradation in older browsers?
I am trying to achieve:
Centered vertical column of images
Images are equal heights and widths
Each image has a caption which should be centered
Caption should have a see-through background
Would be nice if the background became black in older browsers that don't support transparency
If you take a look at this Fiddle example, there's clearly a lot wrong with it.
The basic premise for HTML5 is:
<section>
<figure>
<img src="1.jpg">
<figcaption>Caption 1</figcaption>
</figure>
<figure>
<img src="2.jpg">
<figcaption>Caption 2</figcaption>
</figure>
<figure>
<img src="3.jpg">
<figcaption>Caption 3</figcaption>
</figure>
</section>
But the CSS3 code is where we get some problems. Is it the right approach even? I got it to work with some fine-tuning (not included), but the fine-tuning doesn't seem to make semantic sense to me anyway.
For example, this is the result:
I have a feeling the CSS is wrong on many levels (pun intended).

I modified your CSS slightly. The main changes were adding position: relative; to the parent element and position: absolute; to the caption.
CSS:
section {
overflow: auto;
}
section figure {
float: left;
clear: both;
position: relative;
overflow: auto;
margin: 0 auto;
padding: 30px 0 0 0;
font-size: 15px;
}
section figure img {
vertical-align: bottom;
}
section figure figcaption {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: rgba(0,0,0,0.7);
text-align: center;
color: #fff;
padding: 10px;
}
section {
padding-bottom: 30px;
background: #ccc;
}
Demo: http://jsfiddle.net/XjthT/6/

Related

Using the Gamepad API, when window is resized, a finite padding-bottom appears and I can't seem to get rid of it?

QUESTION:
Using the Gamepad API, i am having a problem when re-sizing the window; namely, a finite padding-bottom appears between the bottom of the #gameBoard and the bottom edge of the Browser window -- which I do not want:
Please note that I have tried a Sticky Footer which depends on position: absolute; which I would prefer to avoid.
EG,
with a padding-bottom > 0
I am looking for this with each window re-size:
padding-bottom = 0
HTML:
<div id="gameEnclosure">
<div id="header">
stuff here
</div>
<div id="gameBoard">
<canvas id="game">
game piece img's here
</canvas>
</div>
</div> <!-- gameEnclosure -->
CSS
/* COMMON RESET */
html, body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
}
body {
background-color: blue;
}
#gameBoard {
display: block;
position: relative;
width: 100%;
height: auto;
background-color: #fff;
background-image: url("../images/room.gif");
background-size: cover;
}
As already stated, I have tried using a Sticky Footer and I just do not like using position: absolute. Also, the individual game piece images do not maintain their proper aspect ratio with window re-sizing = another no-no.
JS
function doBodyOnResize() {
let gameHeight = $('#gameBoard').outerHeight();
$('body').css('padding-bottom', gameHeight);
$('#gameBoard').css('height', gameHeight);
}
This is the onresize function I used to have with the Sticky Footer.
Without a Sticky Footer, game pieces zoom in and zoom out just great -- if I could just get keep padding-bottom = 0 upon window resizing.

Another stacking centered images question

I have an image of TV set and I want to place images of "shows" in it, centered horizontally on the screen (in front of the tv screen image). I'm using a to set the dimensions of the area in which to place the images, but I don't have to if it's not necessary. I've fiddled with position:absolute/relative of the and the images, but I can't get both images to be centered and stacked - either they partly overlap when centered or they align perfectly at the edge of the "". Here's the current iteration of the code. Any advice would be appreciated.
<div id="sourceDiv" align="center">
<img class="test" src="uvaCover.jpg" style="z-index:2; width:800px">
<img class="test" src = "tvScreen.jpg" style="z-index:1; width:900px">
</div>
.test {
position: absolute;
display: block;
margin:auto;
height:auto;
overflow: hidden;
}
#sourceDiv {
position:relative;
background-color: red;
top:170px;
left: 20px;
width:1000px;
height: 800px;
margin:auto;
}
I found the answer. For the ":
display: flex;
align-items: center;
justify-content: center;

Image sticking out of it's container

How to make an image stick out of his container keeping it's transparent background? I see it a lot lately on many startup-like websites (as bellow). Could it be achieved by playing with overflow or translate property? Thanks a lot.
Edit: Here's a page from which the image is startup template
image sticking out of it's container
Try this:
.section-1 {
height: 300px;
background-color: #ddd;
}
.section-2 {
position: relative;
background-color: #eee;
}
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
.img-overlayed {
position: relative;
top: -155px;
margin: 0 auto -155px;
}
<section class="section-1">
</section>
<section class="section-2">
<img src="http://placehold.it/400x400" alt="" class="img-responsive img-overlayed">
</section>
So long as the image has transparency the background of the sections will show through.

Latest opera won't hide the overflow while using border-radius property

while using border-radius Opera won't actually hide the overflowing parts of elements. I already tried to apply things I managed to find in similar threads, such as defining the border style or paying attention to positioning with absolute and relative parameters. It is still not working though.
html
<div class="node">
<div class="skill skill1"></div>
<div class="skill skill2"></div>
<div class="skill skill3"></div>
<div class="skill skill4"></div>
</div>
css
.node {
position: relative;
width: 250px;
height: 250px;
opacity: 0.9;
border-radius: 50%;
overflow: hidden;
left: -60px;
border: solid 1px transparent;
}
.skill {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 50%;
transform-origin: 100% 100%;
-webkit-transform-origin: 100% 100%;
}
.skill1 {
background-color: #26ac79;
-webkit-transform: rotate(90deg) skewX(45deg);
transform: rotate(90deg) skewX(45deg);
}
.skill2 {
background-color: #25765f;
-webkit-transform: rotate(135deg) skewX(45deg);
transform: rotate(135deg) skewX(45deg);
}
.skill3 {
background-color: #25313f;
-webkit-transform: rotate(180deg) skewX(45deg);
transform: rotate(180deg) skewX(45deg);
}
.skill4 {
background-color: #25193d;
-webkit-transform: rotate(225deg) skewX(45deg);
transform: rotate(225deg) skewX(45deg);
}
Here's the fiddle:
http://jsfiddle.net/Mu9Ar/
Thanks for any help.
Actually the code you provided works in latest Opera with Blink engine, so I guess you can leave your code as is. However if you need it to work in versions up to 12.16 and your page background is white, what you can do is to put .png overlay over your chart which will clip the chart, just like webdevelopers did in old days when there were no border-radius:)
According to the W3 specification:
http://www.w3.org/TR/css3-background/#corner-clipping
A box's backgrounds, but not its border-image, are clipped to the
appropriate curve (as determined by ‘background-clip’). Other effects
that clip to the border or padding edge (such as ‘overflow’ other than
‘visible’) also must clip to the curve. The content of replaced
elements is always trimmed to the content edge curve.
It appears that Firefox implemented the spec correctly by clipping the content to the edge of the curve when using overflow: hidden.
However, Opera is not compliant on this detail.
As an aside, if you add border-radius property to an img element, the image will be clipped correctly.
At this moment, there is no work-around that I know of unless you try HTML5 canvas.

How to get <img> to be the same width as <figcaption>?

In a responsive design, how can the width of a <figcaption> be made to adjust according to the width of the <img>, but not exceed it?
<section>
<figure>
<img src="link.jpg">
<figcaption>Caption</figcaption>
</figure>
</section>
The corresponding CSS only limits the <img> and not the <figcaption>, see:
How can the <figcaption> be constrained along with the <img>, without using max-width: 200px (or 12.5em) on the <figure> container?
Here are the important bits of CSS (full on JSFiddle):
section figure {
position: relative;
margin: 0 auto; /* to center it */
}
section figure img {
max-width: 100%;
vertical-align: middle; /* to make sure images behave like blocks */
}
section figure figcaption {
position: absolute;
right: 0; bottom: 0; left: 0;
}
Setting max-width: 100%; display: inline-block; (http://jsfiddle.net/vZpmq/1/) or float: [left|right] (http://jsfiddle.net/cdmU3/1/) on the section would cause it to shrink-to-fit it's content (and the box it's in). You might need to rework some other things to fit those changes, though.
Alternatively, try setting width: 100%; height: auto; on the img, and set the width on the figure element? http://jsfiddle.net/9yUsP/
(setting height: auto; on the img means it's retain it's aspect ratio regardless of height or width attributes set on the img element itself)

Resources