Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HTML: position text on top of image

Posted on 2015-01-24
7
Medium Priority
?
197 Views
Last Modified: 2015-02-01
I'm working on an epub eBook in calibre. It is intended to be responsive. I can make full use of CSS 3.

In one part of the book I'd like to put text on top of an image.
The image must be horizontally centered on the page.
The text must be horizontally centered on top of the image, 15% down from the top.
The image has a blank section 15% from the where the text is to go. In a responsive environment, as the size of the viewport changes, the image and consequently the blank section will also change in size. I want the text to be positioned in that blank section.

I'm having trouble getting the image horizontally centered and in getting the text to both center and be the right proportional distance down.

Here's what I have so far. There's a corresponding JSFiddle at I created a JSFiddle for what I have now: http://jsfiddle.net/blearyeye/d888kv7w/.
CSS
.block_17 {
    display: block;
    color: #773A77;
    font-family: "Filosofia", sans-serif;
    font-size: 2em;
    font-weight: bold;
    line-height: 1.5;
    page-break-after: avoid;
    text-align: center;
    text-indent: 0;
    margin: 0;
    padding: 0
    }

Open in new window

HTML
<div style="display:inline;position:relative">
<img src="TheImage.png" style="position:absolute;"/>
  
<p class="block_17" id="calibre_pb_20" style="inline;top:70;width:100%;position:absolute;">The Desired Text</p>
</div>

Open in new window


There are a number of problems I'm having.  The image isn't being centered in the viewport. The text isn't being centered at all. The text isn't being moved down at all, even with an absolute top attribute.
0
Comment
Question by:BlearyEye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 15

Expert Comment

by:Edwin Hoffer
ID: 40568296
Hello BlearyEye,

Don't use the <p> tag in <div> code

Here as an example:

<div style="display:inline;position:relative">
<img src="http://bdluv.com/xmisc/misc/Cover%20Image%20Flowers%20House.png" style="position:absolute;"/>
</div>  
<p class="block_17" id="calibre_pb_20" style="top:70;width:100%;position:absolute;">Text To Display</p>

Open in new window


Hope this helps you
Thanks
Edwin
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40568379
Part of you CSS is not valid because you are not specify a unit of measure... what does top:70 mean? 70px; 70%? 70vh?

If you want it responsive you probably should be using vh and vw for most units of measure; but I am not going to waste my time guessing at what the page looks like.  Post a link to the page, which I suspect probably has a lot of problem when I see inline styles being used.

Cd&
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 40571805
Being an ebook, it's kind of hard to post a link to the page. But you're asking for more context, which is reasonable. I'll add in the rest of the CSS.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:BlearyEye
ID: 40576608
Well, this has been a learning experience. It seems that epub generally assumes that the program that renders it to the viewer will choose the base font size and line spacing.  (This lets the reader specify a preferred size and spacing.) So unless I fix it, the font size can be inconsistent with the size of the graphic as it's scaled according to viewport.

So ... I made the change that Edwin Hoffer suggested and things started looking better. As COBOLdinosaur noted the 70 by itself is meaningless. I changed it to 40% and it seems about right. So ... the current problem is that the text is centered in the viewport but the graphic is not. I think if I can get that sorted I'll be well on my way.

I updated the fiddle, http://jsfiddle.net/d888kv7w/10/.
0
 
LVL 15

Accepted Solution

by:
Edwin Hoffer earned 2000 total points
ID: 40576726
Hello BlearyEye,

The image you are using is not a full width image, but if you still want to use this as background then use the below code in your "body" tag:

body{	
	background-image: url(http://bdluv.com/xmisc/misc/Cover%20Image%20Flowers%20House.png);
	background-position: center;
	background-repeat: no-repeat;
}

Open in new window


In above code you can change background-position to: top left, center, right left, etc. and you want to repeat the background then change "no-repeat" to "repeat"

Thanks
Edwin
0
 
LVL 1

Author Closing Comment

by:BlearyEye
ID: 40582959
Just what I needed, thanks.
0
 
LVL 15

Expert Comment

by:Edwin Hoffer
ID: 40583205
You are welcome :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question