0

I have two divs inside a div,

HTML

<div class="preview">
       <div class="gamePreview"></div>
       <div class="gameName"></div>
</div>

I would like the gameName divs to be on top of the game Preview divs.

CSS

.preview {
    display: block;
}

.gamePreview, .gameName {
    margin-left: 20px;
}

.gamePreview {
    width: 30%;
    height: 350px;
    margin-top: 40px;
    background-color: lightgrey;
    float: left;
}

.gameName {
    width: 29.59%;
    background-color: #494949;
    height: 150px;
    opacity: 0.5;
    margin-top: 240px;
    clear: both;
    position: absolute;
}

This works fine when there is only one of the preview divs. However, if I wanted to put two divs on the same line, the gameName divs all float left on the same spot. Instead, I would like each gameName div to be on top of its own gamePreview div.

https://jsfiddle.net/r5t5vuqk/

What I would like it to look like:

2
  • Make a Fiddle please. Commented Jun 17, 2015 at 4:03
  • 1
    Show an image of your preferred layout. Commented Jun 17, 2015 at 4:09

3 Answers 3

4

Check this fiddle. I think this is what you need.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

.preview {
    display: block;
}

.gamePreview, .gameName {
    margin-left: 20px;
}

.gamePreview {
    width: 30%;
    height: 350px;
    margin-top: 150px;
    background-color: lightgrey;
    float: left;
}

.gameName {
    width: 29.59%;
    background-color: #494949;
    height: 150px;
    opacity: 0.5;
    margin-top: -10px;
    clear: both;
    position: absolute;
}

Comments

0

Check this fiddle. FIDDLE

.preview {
   display: block;
    float: left;
    margin: 5px;
    width: 30%;
}

.gamePreview, .gameName {
    margin-left: 20px;
}

.gamePreview {
   background-color: lightgrey;
    float: left;
    height: 350px;
    margin-top: 40px;
    width: 100%;
}

.gameName {
    background-color: #494949;
    clear: both;
    height: 150px;
    margin-top: 240px;
    opacity: 0.5;
    width: 100%;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.