overlay text over image in html page - html

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>

Related

How to add text over an image that "falls off" the image

So I spent a couple hours searching, but all I've seeing is just standard help with adding text over an image, nothing that will put the text over the image, as it "falls" off the image.
I've attached an example of what I'm referring to.
I'm trying to do it in a way so the images stay right under each other and not create space between the, added another photo for reference on what I mean.
I've tried creating an img-container and add text but that doesn't allow me to have the text "fall" off the image. This is what I have so far (not including the text".
I've attempted to make the images as the body background but that didn't have the same design I'm looking for unfortunately, as the text will also serve as links in the future.
images stacked with no space
text falling off the image
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="navigation.css">
<title>Pasetta Studios</title>
</head>
<body>
<div id="wrapper">
<div class="navbar">
Home
About
Projects
Contact
</div>
<div class="img-container">
<img src="images/top-image.jpg" alt="plants">
<img src="images/second-image.jpg" alt="benches">
<img src="images/third-image.jpg" alt="cactus">
<img src="images/last-image.jpg" alt="more cactus">
<img src="images/pasetta-studios" alt="pasetta studios">
</div>
<code>Designed by #PasettaStudios. </code>
</div>
</body>
</html>
And here is my CSS
#font-face {
src: url(fonts/Modric.ttf);
font-family: Modric;
}
#font-face {
src: url(fonts/Orkney-Regular.ttf);
font-family: Orkney;
}
#font-face {
src: url(fonts/Made-Bon-Voyage.otf);
font-family: Made-Bon-Voyage;
}
* {
box-sizing: border-box;
}
#wrapper {
max-width: 1000px;
margin-left: auto;
margin-right: auto;
padding-right: 50px;
padding-left: 50px;
}
body {
background-color: #262c2c;
}
.navbar {
max-width: 100%;
height: 100px;
margin-right: auto;
margin-left: auto;
}
/* links and text inside nav bar */
.navbar a {
float: left;
padding: 40px 0px 0px 0px;
background-color: #262c2c;
text-decoration: none;
font-size: 20px;
width: 25%; /* Four links of equal widths */
text-align: center;
color: #dae1e7;
font-family: Orkney;
}
h1 {
text-align: center;
font-family: Orkney;
}
img {
max-width: 100%;
height: auto;
display: block;
opacity: 50%;
margin-left: auto;
margin-right: auto;
}
p {
text-align: right;
font-size: 100px;
padding-left: 100px;
color: #dae1e7;
font-family: Modric;
font-size: 150px;
}
Try this:
<div class="img-container">
<div class="row">
<img src="images/top-image.jpg" alt="plants">
<span>Your text</span>
</div>
<div class="row">
<img src="images/second-image.jpg" alt="benches">
<span>Your text</span>
</div>
<div class="row">
<img src="images/third-image.jpg" alt="cactus">
<span>Your text</span>
</div>
<div class="row">
<img src="images/last-image.jpg" alt="more cactus">
<span>Your text</span>
</div>
<div class="row">
<img src="images/pasetta-studios" alt="pasetta studios">
<span>Your text</span>
</div>
</div>
.img-container {
width: 500px;
height: auto;
}
.row{
position: relative;
width: 100%;
}
.row span {
position: absolute;
color: white;
top: 0;
}
.row:nth-child(odd) span {
left: -20px;
}
.row:nth-child(even) span {
right: -20px;
}
What you have to do is put your Image in a Container, along with your text. The text is then positioned absolute and with a negative margin or left and right values instead of only setting top values.
<div class="img-container">
<img src="img1.jpg" alt="Image 1">
<p class="lefttext">Left</p>
<p class="righttext">Right</p>
</div>
<div class="img-container">
<img src="img2.jpg" alt="Image 2">
<p class="lefttext">Left</p>
<p class="righttext">Right</p>
</div>
For multiple images, just repeat this code.
And your CSS:
.img-container {
position:relative;
margin:0;
padding:0 40px;
}
.img-container img {
border:0;
}
.img-container p.lefttext {
position:absolute;
top:50px;
margin-left:-40px;
}
.img-container p.righttext {
position:absolute;
top:120px;
width:100%;
text-align:right;
margin-right:—40px;
}
Alternatively, you could do
.img-container p.lefttext {
position:absolute;
top:20px;
left:0;
}
.img-container p.righttext {
position:absolute;
top:120px;
text-align:right;
right:0;
}
If the position of the text over the image should change for each picture, simply remove the ˋtop:..pxˋ from your CSS and add ˋstyle="top:50px;"ˋ to each image tag.

Image with overlay captions

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>

How to make a description box "fit" inside an image width HTML

So i have an image, I have a text box with a transparent background that is overlaid on the image (FYI it contains the price of the item and if it is onsale).
I would like the text box to "fit" the width of the image it is over.
Currently the text is wider than the image. I've tried adjusting the width but that only seems to shrink it and move the box out from being over the image.
http://jsfiddle.net/Ggqy4/
Here is what I'm aiming to create. Notice the text is only as wide as the image.
http://imgur.com/zKzjIyF
The red box inside the box is on the first item on the left, the girl in the vest.
HTML:
<div class="date-container">
<div class="date-heading" style="display: block;">Friday, Oct 11, 2013</div>
<div class="items-purchased-container">
<DIV style="position: absolute; top:10px; left:355px; width:200px; height:25px">3</span> items purchased</p>
</div>
<div class="total-spend-container">
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" alt="" />
<div class="description">
<p>Sex shirt in sparkly black <span class="price">Price $500</span>
</p>
</div>
</div>
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" alt="" />
<div class="description">
<p>Sex shirt in sparkly black <span class="price sale">Sale Price $500</span>
</p>
</div>
</div>
CSS:
body {
background:#00000;
text-align:center;
}
.product {
display:inline-block;
position:relative;
margin-right:10px;
vertical-align:top;
}
.product img {
display:block;
max-width:100%;
}
.description {
position:absolute;
background:rgba(255, 255, 255, 0.75);
top:60%;
;
text-align:center;
width:100%;
}
.description span {
display:block;
margin-top:10px;
padding:5px;
}
.sale {
background:red;
}
Here is a JSFiddle file for your review: CLICK HERE
As mentioned above by Giovanni Silveira, your images contain a large left/right border. You can either crop in your favorite image editor or you will have to manipulate your code to accommodate the added area to your liking.
I did add some changes to force the appearance you were looking for, however if you want a less intrusive set up then it would be prudent to change you images to fit your needs.
To view how the page was set up, just add
border: 1px solid #ccc;
to your product and description classes to see the flow and gain a better understanding of the images impact on flow of document.
Hope this helps.
Here is the code:
HTML:
<div class="orderinfo">
<div class="date">Friday, Oct 11, 2013</div>
<div class="purchaseitems">3 items purchased</div>
</div>
<div class="total-spend-container">
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" style="width:300px;height:250px" alt="" />
<div class="description">
<p>Sex shirt in
<br>sparkly black</br> <span class="price">Price $500</span>
</p>
</div>
</div>
<div class="product">
<img src="https://theory.alluringlogic.com/api/v1/productvariation/3/1058.jpg?preset=XS" style="width:300px;height:250px" alt="" />
<div class="description">
<p>Sex shirt in
<br>sparkly black</br> <span class="price sale">Sale Price $500</span>
</p>
</div>
</div>
CSS:
body {
background: #00000;
text-align: center;
}
.orderinfo {
position: relative;
width: 100%;
min-width: 650px;
font-family: "Courier", sans-serif;
font-size: 20px;
}
.date, .purchaseitems {
float: left;
width: 49%;
padding-bottom: 10px;
}
.total-spend-container {
min-width: 650px;
}
.product {
position: relative;
display: inline-block;
width: 300px;
height: 250px;
}
.product img {
background-position: center;
background-size: cover;
}
.description {
position: absolute;
background: rgba(255, 255, 255, 0.75);
font-family: "Courier", sans-serif;
font-style: italic;
top: 50%;
text-align: center;
left: 25%;
width: 50%;
}
.description span {
display: inline-block;
margin-top: 10px;
padding: 3px;
}
.sale {
background: red;
color: white;
}

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