Как поместить текст по изображению без абсолютного расположения или установки изображения как backbround

Не идеальное решение, но gitk и git-gui может и показать эту информацию и иметь полосы прокрутки.

13
задан mskfisher 12 June 2012 в 17:00
поделиться

4 ответа

I used to pull stunts like this all the time as soon as tables came. Really ugly, and may seriously embarass any validator you run it trough: overlapping table cells. Works in most browsers though and even without css.

Example:

This is the overlay text

I know, I deserve a downvote for this.

67
ответ дан 1 December 2019 в 17:14
поделиться

If you use absolute positioning, you should specify both the left and top attributes. Also, you should set position:relative; on some parent element to make it a layer, so that the absolute positioning uses that element as origin. If you don't specify the origin, it may be the window or it may be some other element, and you don't know where your absolutely positioned element will end up.

There are some other alternatives to place elements on top of each other, each with their own limitations.

You can use relative positioning to make text display on top of an image:

<img src="..." alt="" />
<div style="position:relative;top:-50px;">
   This text will display 50 pixels higher than it's original position,
   placing it on top of the image. However, the text will still take up
   room in it's original position, leaving an empty space below the image.
</div>

You can use a floating element inside another element to put text on top of an image:

<div>
   <div style="float:left;">
      This text will be on top of the image. The parent element
      gets no height, as it only contains floating elements.
      However, IE7 and earlier has a bug that gives the parent
      element a height anyway.
   </div>
</div>
<img src="..." alt="" />
6
ответ дан 1 December 2019 в 17:14
поделиться

The best way to control the look of things would be to make the text part of the image itself. Of course, if you use a lossy image format like jpeg with high compression it could look really bad, but maybe a PNG will work for you? Or, depending on the number of colors, a gif might work.

This also gives you consistent-looking fonts, filtering, etc.

3
ответ дан 1 December 2019 в 17:14
поделиться

You can try setting negative margins. This is very difficult to maintain in all but the least complex layouts. A negative margin effective "pulls" the element in that direction.

<img src="blah.jpg" height="100"/>
<div style="margin-top:-100px">
  blah blah blah
</div>
2
ответ дан 1 December 2019 в 17:14
поделиться