Image with overlay captions - html

I have a problem with image descriptions. I have HTML structure like this:
<div class="scrollable-content" data-mcs-theme="dark-thick" style="padding: 0px; overflow-x: auto;">
<ul style="list-style: none; white-space:nowrap; padding: 0px;">
#foreach($projects as $project)
<li style="display: inline; margin: 0px;">
<a href="{!! url($locale.'/projects/project/'.$project->id) !!}">
<img class="project-cover-image" src="/images/{!! $project->cover_image_name !!}" height="250px" width="auto">
</a>
</li>
#endforeach
</ul>
</div>
It creates a nice looking gallery with horizontal scrollbar. But I need to add descriptions to images that will be placed at the bottom of the pictures covering whole their widths and they should have to be transparent to some degree.
The problem is, whatever I do, I either get description that takes 100% width of the page, or it has width of the text inside it.
I have tried doing it with div, span, different combinations of position absolute/relative, everything and I couldn't manage to make it work.
It should look something like this:
How can I do that?

You have two options (wich produce the same result):
1- A div with a image as background, and a subtitle inside this div;
#image {
width:550px;
height:150px;
position:relative;
background: url('http://i.imgur.com/HNj6tRD.jpg');
background-repeat: no-repeat;
background-size:100% 100%;
}
.coverdown {
color: white;
width: 100%;
height: 30%;
position:absolute;
bottom:0%;
background: rgba(0,0,0,0.5);
text-align: center;
}
<div id="image">
<div class="coverdown">Subtitle here with a description.</div>
</div>
2- The image and a subtitle with position:absolute inside a position:relative container;
#container {
width:550px;
height:150px;
position:relative;
}
img {
width:550px;
height:150px;
position:absolute;
top:0px;
left:0px;
}
.subtitle {
color: white;
width: 100%;
height: 30%;
position:absolute;
bottom:0%;
background: rgba(0,0,0,0.5);
text-align: center;
}
<div id="container">
<img src="http://i.imgur.com/HNj6tRD.jpg" alt=img>
<div class="subtitle">Subtitle here with a description.</div>
</div>

use position:relative/absolute
body {
margin: 0
}
.scrollable-content {
padding: 0;
overflow-x: auto
}
ul {
list-style: none;
white-space: nowrap;
padding: 0;
margin:0
}
li {
position: relative;
display:inline-block
}
span {
background: rgba(0, 0, 0, .5);
display: inline-block;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
img {
display: block
}
a {
color: #fff
}
<div class="scrollable-content" data-mcs-theme="dark-thick">
<ul>
<li>
<a href="">
<img class="project-cover-image" src="//lorempixel.com/250/250">
<span>description</span>
</a>
</li>
<li>
<a href="">
<img class="project-cover-image" src="//lorempixel.com/500/250">
<span>description</span>
</a>
</li>
<li>
<a href="">
<img class="project-cover-image" src="//lorempixel.com/400/250">
<span>description</span>
</a>
</li>
</ul>
</div>

basicly, you need relative/absolute as #dippas's answer.
as I advised, use inline-block, so it gets sized by content and will allow easily to position your description.
example below with figure and figcaption.
figure can be wrap in a <a>link displayed inline-block and figure as a block then to avoid a gap underneath.
figure {
display: inline-block;
position: relative;
margin: 0;
}
img {
display: block;
max-height:80vh;height:250px/*snippet demo purpose */
}
figcaption {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
/* makeup*/
background: rgba(0, 0, 0, 0.5);
color: white;
}
/* demo purpose */
div {
white-space: nowrap;
overflow:auto;
}
figure {
white-space: normal;
text-align: center;
}
<div>
<figure>
<img src="http://www.hyperkreeytiv.com/wp-content/uploads/2014/08/IMG_4973.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
<figure>
<img src="http://4.bp.blogspot.com/-oSEWgZNEopE/TtL8kfGuBzI/AAAAAAAAB6U/b8VSzZaoK3g/s400/action_wolf_1111_photo1.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
<figure>
<img src="http://1.bp.blogspot.com/-GfOyrk3kZ0w/TewM0BMvbNI/AAAAAAAABM0/KPm3li5Xwko/s1600/alpha+male+Wallpaper__yvt2.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
<figure>
<img src="http://www.ooyuz.com/images/2015/10/13/1447449028465.jpg" alt="wolves" />
<figcaption>
<p>these are wolves</p>
</figcaption>
</figure>
</div>

Related

styling inline images and captions

The following code acts as a section allowing a user to scroll through a host of images horizontally. I want to place text undderneath each image . I'm having serious trouble doing this and would be very grateful for any sugestions
<div class="favored" style="background-color: #F8FFFA;overflow-x:scroll; white-space: nowrap;" >
<span>
<img id='<?echo $user_id;?>' src="<?echo$image_path?>">
<caption for="<?echo $user_id?>" style='position: bottom;'><?echo$first_name?></caption>
</span>
<span>
<img id='<?echo $user_id;?>' src="<?echo$image_path?>">
<caption for="<?echo $user_id?>" style='position: bottom;'><?echo$first_name?></caption>
</span> <span>
<img id='<?echo $user_id;?>' src="<?echo$image_path?>">
<caption for="<?echo $user_id?>" style='position: bottom;'><?echo$first_name?></caption>
</span> <span>
<img id='<?echo $user_id;?>' src="<?echo$image_path?>">
<caption for="<?echo $user_id?>" style='position: bottom;'><?echo$first_name?></caption>
</span>
</div>
Thank you in advance
Flexbox to the rescue!
ul {
display: flex;
flex-direction: row;
justify-content: space-between;
overflow-x: scroll;
overflow-y: hidden;
list-style: none;
padding: 0;
}
ul li {
width: 350px;
text-align: center;
margin: 5px;
}
<ul>
<li>
<img src="http://placehold.it/200x100">
<p>caption</p>
</li>
<li>
<img src="http://placehold.it/200x100">
<p>caption</p>
</li>
<li>
<img src="http://placehold.it/200x100">
<p>caption</p>
</li>
<li>
<img src="http://placehold.it/200x100">
<p>caption</p>
</li>
<li>
<img src="http://placehold.it/200x100">
<p>caption</p>
</li>
<li>
<img src="http://placehold.it/200x100">
<p>caption</p>
</li>
</ul>
I see your code . And I exactly know what you want . So I copy this code directly from one of my projects .
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<style type="text/css">
.block-scroller {
width: 100%;
height: 49.5vw; /* It should has it */
clear: both;
margin: 0.5% 0;
}
#scroller {
width: 100%;
height: 39.5vw; /* It should has it */
overflow-x: scroll; /* It make the block scroll */
}
#scrolled-parent {
width: 300%; /* It should has it */
height: 100%;
}
.scrolled {
width: calc(98.5% / 6) !important; /* 98.5% means the 100% - "all of the scrolled blocks margins" and 6 means the six block that we add in html */
height: 100%;
margin: 0 0.125%;
float: left;
background: url(http://placehold.it/600x500) black no-repeat center /cover;
}
.scrolled p {
width: 100%;
line-height: 10vw;
background: rgba(255, 0, 0, 0.7); /* The background color of captions */
color: white;
font-family: sans-serif;
text-align: center;
font-size: 1em;
margin: 0;
}
p#class-title {
width: 100%;
line-height: 10vw;
background: rgba(0, 0, 0, 0.7);
color: white;
font-family: sans-serif;
text-align: center;
font-size: 1em;
margin: 0;
}
</style>
</head>
<body>
<div class="block-scroller">
<div id="scroller">
<div id="scrolled-parent">
<div id="class301" class="scrolled"><p>301</p></div>
<div id="class302" class="scrolled"><p>302</p></div>
<div id="class303" class="scrolled"><p>303</p></div>
<div id="class304" class="scrolled"><p>304</p></div>
<div id="class305" class="scrolled"><p>305</p></div>
<div id="class306" class="scrolled"><p>306</p></div>
</div>
</div>
<p id="class-title">Class</p>
</div>
</body>
</html>
You see it has a nice transparent caption and a group name . Actually I create it for a mobile app interface but I showed the width, height, background-image of the blocks and captions background-color .
TIP : In the body section on line "62" .block-scroller is the parent of the hole codes.
On line "63" #scroller is the div that has the scrolled div in it .
On line "64" #scrolled-parent has the hole images with its captions in it and it is the only div that is scrolling .
And the .scrolled blocks are the images with it captions .

overlay text over image in html page

How do I overlay a paragraph of text over the image (homepagepic.jpg) in the middle of the page.
I want to write a bunch of text over the image, I have done quite a lot of research but I haven't come across much to be honest. Thanks very much indeed in advance
HTML:
<center>
<h1>Welcome To The Kingston University Survey Page</h1>
</center>
<img src="kingstonunilogo.jpg" id="uni" alt="uni logo"/>
<br/>
<div id="buttons">
<button onclick="window.location='http://www.google.com'" type="button home-button">Home</button>
<button onclick="window.location='http://www.google.com'" type="button contact-button">Contact Us</button>
LogIn
</div>
<br/><br/><br/><br/><br/><br/>
<img src="homepagepic.jpg" alt="homepagepic" id="middlepic" />
<br/>
<div id="footer">
©
<img class="social-badge" src="facebookpic.png" alt="facebook logo" onclick="window.location.href='http://www.facebook.com'">
<img class="social-badge" src="twitterpic.jpg" alt="twitter logo" onclick="window.location.href='http://www.twitter.com'">
</div>
CSS:
h1 {
margin:0px;
padding:0px;
}
body {
background-color: #A9D0F5;
}
#middlepic {
display: block; margin: 0 auto;
}
#uni {
display: block; width: 200px; height: 175px; float:left;
}
#footer {
width: 100%; height:100px; display: inline-block; text-align: center;
}
#buttons {
display: block;
margin: 0 auto;
width: 50%;
}
button {
height: 30px;
width: 200px;
background-color: #ccc;
border-radius: 10px;
}
a {
text-decoration: none; color: #000;
}
.social-badge {
width: 40px;
}
Why dont you make a new div and put the homepagepic.jpg as its background and then write in that div.
<div id="written">
This text is over the image
</div>
and in CSS
#written
{
background-image : url(***** here comes the url of image homepagepic.jpg*****);
}
If you don't want to use background-image use position:absolute for the paragraph http://jsfiddle.net/8cup75k3/
p{
width:500px;
position:absolute;
margin-top:-100px;
color:green;
}
Use CSS
background-image: url('kingstonunilogo.jpg');
A semantic approach would be to use a figure element with an absolutely positioned figcaption.
Something like this:
figure { position: relative; }
figcaption {
position: absolute;
top: 0; left; 0;
}
<figure>
<img src="http://placehold.it/240" />
<figcaption>This is overlay text.</figcaption>
</figure>

position relative in logo is not working

I have created a design which is below
http://jsfiddle.net/g9TT7/1/
i want to put logo means below top and left side of the page
<a href="index.html" style="margin-top:10px;position:relative!important;width:200px;display:block;" class="img1">
<img src="image/img_2.png" alt="logo" />
</a>
here i want to put business name in the center of the page and logo will be on the left side of the page. I have set position absolute in my logo but not working.
Please help me to do this.
I hope you want something like this:
Demo
Add css float:left in your logo style and remove position absolute from business div.
You can also adjust position from top and left by playing with margin.
HTML:
<div class="b" style="text-align:center;">
<a href="index.html" class="img1">
<img src="image/img_2.png" alt="logo" />
</a>
<div class="business_name" >
Business
</div>
<div class="clear"></div>
</div>
CSS:
.clear
{
clear:both;
}
.img1{
margin-top:20px;
width:200px;
display:block;
float:left;
}
.business_name {
width: 78%;
font-size: 43px;
font-weight: bold;
float: left;
text-align: center;
line-height: 28px;
margin-top: 5px;
}
.b {
font-size: 25px;
font-weight: bold;
width: 78.5%;
text-align: left;
height: 50px;
margin: 0px;
color: rgb(67, 161, 240);
}
.img1 {
float: left;
margin: 2px 0px 0px;
width: 20%;
text-align: left;
border: 0px solid red;
}
Something like this? http://jsfiddle.net/ADDTn/
<div class="header">
<a href="#" class="logo">
<img src="img.jpg" />
</a>
<h1>Bussiness</h1>
<div class="clear"></div>
</div>
css
.header {
width: 100%;
height: 100px;
}
.logo {
display: block;
float: left;
}
h1 {
text-align: center;
}
.clear {
clear: both;
}
Assign the z-index value
<a href="index.html" style="margin-top:10px;position:relative!important;width:200px;display:block; z-index: 1;" class="img1">
<img src="image/img_2.png" alt="logo" />
</a>
see this demo

Image link cause another image link to be unclickable

I have two image links that need to be centered with a little shifting.
My problem is that one link cause the other to be unclickable.
DEMO - The right one can't be clicked
HTML:
<div class="my_class" id="my_id1">
<a href="URL">
<img src="//placehold.it/200x150" />
</a>
</div>
<div class="my_class" id="my_id2">
<a href="URL2">
<img src="//placehold.it/200x150" />
</a>
</div>
css:
#my_id1
{
left: 120px;
}
#my_id2
{
right: 120px;
top: -157px;
}
.my_class
{
text-align:center;
position:relative;
display: block;
margin-left: auto;
margin-right: auto;
}
.my_class
{
text-align:center;
position:relative;
display: block;
margin: 0px, auto;
}
img{
border:1px solid red;
}
Here is the modified code:
<div class="my_class" id="my_id1"> <a href="URL">
<img src="//placehold.it/200x150" />
</a>
</div>
<div class="my_class" id="my_id2"> <a href="URL2">
<img src="//placehold.it/200x150" />
</a>
</div>
And the CSS:
#my_id1 {
float: left;
left: 150px;
}
#my_id2 {
float:right;
right: 150px;
}
.my_class {
text-align:center;
position:relative;
display: block;
margin-left: auto;
margin-right: auto;
}
.my_class {
text-align:center;
position:relative;
display: block;
margin: 0px, auto;
}
img {
border:1px solid red;
}
You need to float those containers : http://jsfiddle.net/GbzSQ/5/
Your first div overlaps over the other, so you need to float them and then use margins to position them properly.
.my_class{
float:left;
width:200px;
}
The divs of the links are just on top of each other.
So the mouse does not "see the bottom link".
Try using display inline in the divs with defined width.
I would use some floats or display:inline-block 's.
I made an update of your Fiddle with the Floats.
http://jsfiddle.net/cfknoop/GbzSQ/7/
#my_id1 {
float:left;
}
#my_id2 {
float:right;
}
The wrapper needs to be cleared with an clearfix or something.
Try not to use negative positioning, it's bad practice and will cause issues such as this. Try defining the size of the containing divide, position that, then float the divs within this.
I'll put together a quick fiddle to show you.
http://jsfiddle.net/GbzSQ/23/
And here's the HTML:
<div class="container" id="container">
<div class="my_class1" id="my_id1">
<a href="URL">
<img src="//placehold.it/200x150" alt="1" />
</a>
</div>
<div class="my_class2" id="my_id2">
<a href="URL2">
<img src="//placehold.it/200x150" alt="2" />
</a>
</div>
</div>
And the CSS:
.my_class2 {
text-align:center;
float: right;
position:relative;
display: block;
margin: 0 auto;
}
.my_class1 {
text-align:center;
float: left;
position:relative;
display: block;
margin: 0 auto;
margin-right: 20px;
}
img{
border:1px solid red;
}
.container {
width: 440px;
height: 200px;
display: block;
margin: 0 auto;
}

z-index issue when placing text over images

I'll provide CSS and HTML sources first.
jsFiddle
The live example is here
The problem is, h2 texts are not visible unless I do z-index: -1; on images. It makes the text appear, however, then the image is being lost and I look at body background.
There is not something touching z-index values except the fixed navigation bar at top.
What may be causing this, can you have a look?
Ps. Writing z-index: 2; on H2 tags doesn't work either.
If you want z-index:2 on <h2> works, you should add position:relative; or position:absolute; or position:fixed.
You can see z-index
i change your HTML & CSS
change in HTML: Move img into a tag
<div class="spotlight-area">
<div class="spotlight">
<div class="spotlight-item width-2 height-2">
<a href="#" class="spotlight-info">
<h2 class="large">
Random text
</h2>
<img src="http://www.sobafire.com/__v2/themes/default/images/news/spotlight-big.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
</a>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
<div class="spotlight-item width-1 height-1">
<a href="#" class="spotlight-info">
<h2>
Random Text
</h2>
<img src="http://i.imgur.com/TAxDMus.jpg" alt="haber">
</a>
</div>
</div>
</div>
css:
change On CSS: Remove position: absolute; From img and ADD It TO .spotlight-area .spotlight .spotlight-item:hover .spotlight-info h2 Remove padding From .spotlight-area .spotlight-info { and Add Margin to .spotlight-area .spotlight .spotlight-item:hover .spotlight-info h2 with similar value
.spotlight-area {
width: 790px;
margin: 0px auto;
padding: 0px;
}
.spotlight-area img, .spotlight-area embed {
max-width: 100%;
height: auto;
min-height: 50px;
}
.spotlight-area .spotlight {
display: block;
border-top: 1px solid #3b3b3b;
border-left: 1px solid #3b3b3b;
float: left;
margin-bottom: 4px;
}
.spotlight-area .spotlight .width-1 { width: 262px }
.spotlight-area .spotlight .width-2 { width: 525px }
.spotlight-area .spotlight .height-1 { height: 174px }
.spotlight-area .spotlight .height-2 { height: 349px }
.spotlight-area .spotlight .spotlight-item {
float: left;
position: relative;
border-bottom: 1px solid #3b3b3b;
border-right: 1px solid #3b3b3b;
overflow: hidden;
}
.spotlight-area .spotlight .spotlight-item:hover .spotlight-info h2 {
color: #ffc203;
}
.spotlight-area .spotlight .spotlight-item img {
width: 100%;
height: 100%;
top: 0;
left: 0;
margin: 0;
border: 0;
z-index: -1; /* tricky part */
}
.spotlight-area .spotlight-info {
display: block;
height: 100%;
min-height: 50px;
}
.spotlight-area .spotlight-info a {
display: block;
height: 100%;
min-height: 50px;
padding: 20px;
}
.spotlight-area .spotlight .spotlight-item .spotlight-info h2 {
display: inline-block;
max-width: 480px;
font-size: 30px;
line-height: 32px;
color: #f0f0f0;
position: absolute;
margin:20px;
}
in My Test This Change work