Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position a element to exact point on the background image?

Background img shown as fig 1, requirement

  1. Width cover mobile phone screen and height adaptive
  2. Position number to exact point (like fig 2)

If changing fig 1 to fig 3, i can position the single line text to exact point. Please take a look in jsbin. But it did not truly solve the problem.

I have no idea how to do if background img just like fig 1. Any other ideas to to this? Thanks.

Fig 1

Fig 2

Fig 3


English is not my native language; please excuse typing errors.

like image 773
Liu Dongyu Avatar asked Aug 30 '16 07:08

Liu Dongyu


People also ask

Which property is used to specify the position of the background image?

The background-position CSS property sets the initial position for each background image. The position is relative to the position layer set by background-origin .

How many types of picture positions are there in background settings?

The background-position property in CSS allows you to move a background image (or gradient) around within its container. It has three different types of values: Length values (e.g. 100px 5px ) Percentages (e.g. 100% 5% )


2 Answers

Please forgive me for my unclear expression and thanks for your attention.


Finally, i find a solution by myself.

  1. convert background image (shown as fig 1) to svg
  2. use svg.js to position the things i want to exact point.

Please take a look in jsbin to see what exactly i want to position

like image 145
Liu Dongyu Avatar answered Nov 15 '22 13:11

Liu Dongyu


I read your post and figured out that you wand something like that

Fig.1 in your background with numbers at their exact location on forground, like 20 in second line of yellow block of fig.2 and, 0 and 3 in second line of red block of fig.2

well in your code which you gave at jsbin you are using fig.3 and positioning text on it with code

<div class="chance-msg">还有20次机会,分享即可领取红包</div>
<div class="invite-msg">已邀请0人,还差3人,加油</div>

You can do the same thing by using fig.1 and writing only text only numbers in div you only need to position your div by adding margin left or you can use span to write your numbers in or you can just do that for a quick review

<div class="chance-msg"><span style="visibility:hidden">还有</span>20<span style="visibility:hidden">次机会,分享即可领取红包<span></div> <div class="invite-msg"><span style="visibility:hidden">已邀请</span>0<span style="visibility:hidden">人,还差</span>3<span style="visibility:hidden">人,加油</span></div>

like image 33
Junaid Amjad Avatar answered Nov 15 '22 12:11

Junaid Amjad