Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS how do you place multiple images in one div; ( the second image is a normal colour)

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #43108
    andreea115
    Participant

    Hi everyone

    my question is this. i have a div that is 875px high. the first half of the image will contain a background image. The second half of the div should however just contain a normal background colour i.e: background:#FFF;

    http://codepen.io/anon/pen/gjoyh

    i am having problems doing this. the code i have drafted only stops at the point where the image end. YOu will notice the image in the middle. the first half of the image is grey; well it should extend another 400 px. the second half should be a normal background colour: white.

    i would love some advice on how to draft the code.

    warm regards

    Andreea

    #126759
    wolfcry911
    Participant

    you’ve overridden the white color with the second background declaration (which contains a transparent color). Just use a single background with the white color and the image. Also, don’t use empty divs for spacing layout elements – use margins.

    Further, you don’t need to use an image for the gradient (unless you want to support older browsers).

    #126763
    andreea115
    Participant

    Hello again wolfcry

    i tried using a single colour within the div but i did not work:
    http://codepen.io/anon/pen/yIKzg

    if possible, can you tell how how to code it correctly.

    secondly, the reason why i am using an empty spacing div for the layout is that i am having problems with margin collapse. in the example above, u will not that even though i placed a ” Margin: 0 ” in the containing div (#middlepart_background ) so that i could then apply a padding to the
    #white_middle_background, it did not work. that is why i then found that by placing an empty div i could force it apart.

    i would be grateful if you could advice me how to tackle the margin collapse in the above example.

    warm regards

    Andreea

    #126765
    wolfcry911
    Participant

    http://codepen.io/wolfcry911/pen/JFwLr

    You tried the color with the background, but left the next background declaration in there which again overruled the first.

    You are correct that the ‘problem’ was margin collapse, but empty divs are not the solution. I’ve used overflow: hidden; in this case, but a top padding or border on middlepart_background would also have worked. Top padding on white_middle_background will not work because the padding will show either the background color or image and not appear down the 31px you desire.

    You may want to consider eliminating the outer div entirely and use the body for those images…

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘CSS’ is closed to new topics and replies.