how can I move div with position:relative above div with position:absolute?

folibis

At my site I have a block with image as background and title above the image:

html

<div class="block">
    <img src="someimage.png" />
    <div class="title">Some title</div>
</div>

css

.block {
    position:relative;
}
.block img {
    position:absolute;
    top:0;
    left:0;
}
.block .title {
    margin-top:100px;
    text-align:center;
}

Requirements for the .block:

  • I cannot change <img> with <div style='background-image:url(someimage.png)'> - it must be <img>
  • .title must be relative

But the problem - absolute div hides the title. . Playing with z-index do nothing just because z-index does not work with relative elements. So my question - how can I organize this block. Any advices will be very apprecated!

jmore009

z-index does work with relative positioning. Just set the .title to relative (or inherit since its parent is relative) and add a z-index

Per http://www.w3.org/wiki/CSS/Properties/z-index

Only works on positioned elements(position: absolute;, position: relative; or position: fixed;)

CSS

.block {
  position:relative;
  width: 100px;
 }

 .block img {
  position:absolute;
  top:0;
  left:0;
}

.block .title {
  margin-top:100px;
  text-align:center;
  color: #FFF;
  position: relative;
  z-index: 1
}

FIDDLE

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Position absolute for a rotated Div

From Dev

Child div absolute position is not relative to parent

From Dev

How to adjust position of a div relative to a div above it upon height change?

From Dev

How to center absolute div (text) above relative div (image) responsively?

From Dev

How can I position a div relative to an image?

From Dev

TCPDF - How can I show a div with absolute position in a pdf created with tcpdf?

From Dev

How to apply clipPath to a div with the clipPath position being relative to the div position

From Dev

How can I position list in <div>?

From Dev

Center div with position absolute?

From Dev

Position a fixed div above a relative div/h1

From Dev

CSS position absolute/relative change outer div alignment

From Dev

css position an absolute div in relative with a slideable menu

From Dev

Can't position a div above other docs?

From Dev

How to adjust position of a div relative to a div above it upon height change?

From Dev

How do i position a div relative to the window page (responsive css)

From Dev

How to align to the center a div with position absolute within a div with position relative?

From Dev

how to position a div below an absolute div in css

From Dev

div with position absolute doesn't overlap div with position relative

From Dev

How can I position a div relative to an image?

From Dev

HTML CSS Div overlapping absolute & relative position

From Dev

Absolute div moves on parent being assigned relative position

From Dev

How to get a position:absolute div on top of relative of another parent

From Dev

CSS: Relative position in absolute position in a relatively positioned div

From Dev

Position a fixed div above a relative div/h1

From Dev

I have absolute position inside relative div, when I zoom in on to the device layout is overlapping the parent

From Dev

Absolute within position relative div?

From Dev

How do I position a div relative to a fixed position div?

From Dev

Javascript, game, How can I determine the position (x,y) of a div element relative to a parent div in javascript?

From Dev

Div not visible if position: relative

Related Related

  1. 1

    Position absolute for a rotated Div

  2. 2

    Child div absolute position is not relative to parent

  3. 3

    How to adjust position of a div relative to a div above it upon height change?

  4. 4

    How to center absolute div (text) above relative div (image) responsively?

  5. 5

    How can I position a div relative to an image?

  6. 6

    TCPDF - How can I show a div with absolute position in a pdf created with tcpdf?

  7. 7

    How to apply clipPath to a div with the clipPath position being relative to the div position

  8. 8

    How can I position list in <div>?

  9. 9

    Center div with position absolute?

  10. 10

    Position a fixed div above a relative div/h1

  11. 11

    CSS position absolute/relative change outer div alignment

  12. 12

    css position an absolute div in relative with a slideable menu

  13. 13

    Can't position a div above other docs?

  14. 14

    How to adjust position of a div relative to a div above it upon height change?

  15. 15

    How do i position a div relative to the window page (responsive css)

  16. 16

    How to align to the center a div with position absolute within a div with position relative?

  17. 17

    how to position a div below an absolute div in css

  18. 18

    div with position absolute doesn't overlap div with position relative

  19. 19

    How can I position a div relative to an image?

  20. 20

    HTML CSS Div overlapping absolute & relative position

  21. 21

    Absolute div moves on parent being assigned relative position

  22. 22

    How to get a position:absolute div on top of relative of another parent

  23. 23

    CSS: Relative position in absolute position in a relatively positioned div

  24. 24

    Position a fixed div above a relative div/h1

  25. 25

    I have absolute position inside relative div, when I zoom in on to the device layout is overlapping the parent

  26. 26

    Absolute within position relative div?

  27. 27

    How do I position a div relative to a fixed position div?

  28. 28

    Javascript, game, How can I determine the position (x,y) of a div element relative to a parent div in javascript?

  29. 29

    Div not visible if position: relative

HotTag

Archive