1

I have a small div box inside a main div. The main div uses a background image. I want to add some text in the box div and a background image, so that the background image appears only in the empty area after the text. So it would be like the text in the box has the background image of main div and the rest of the empty area inside the box div has another background image. Here's the html:

        <div class="main">//width = x
           <div class="box"> //width = x
              <span class="text">Text, no bg. </span>  // width = y
              <!-- need bg here in x-y area.-->
            </div>
        </div>

hope it makes sense.

Edit: Please check my Jsfiddle link here: http://jsfiddle.net/zr9Ks/ All I'm trying is to have same background as the main div under the span inside the box div, and push the box div bg after the text.

8
  • why -1? @Elen its very basic example and I've mentioned that main and box div have same width, thats all css. Commented Jan 6, 2012 at 13:52
  • 3
    paste the CSS even if it is basic Commented Jan 6, 2012 at 13:53
  • you should show what you've already tried Commented Jan 6, 2012 at 13:59
  • it's a bit unclear. to me it sounds that you need another div after your span with the background you need, then span will have bg of main and the other img will appear lower. is that what you want? Commented Jan 6, 2012 at 14:01
  • Does the background image that will be in box have a fixed height? Commented Jan 6, 2012 at 14:04

4 Answers 4

1

I now understand better the effect you are after. The only way I can think is using a table making the right cell to be 100% width and the left one no-wrap, check the following jsfiddle:

http://jsfiddle.net/LQydR/

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

Comments

1

The background can be shifted to the left if that is what you need. As @Elen says, it is a bit unclear what you expect. Anyway, shifting the background is something like this:

.main {
    width:300px;
    background-image:url('mainbg.png');
}


.text {
    width:100px;
    background:none;
}

.box {
    width:300px;
    background-repeat:no-repeat;
    background-position:100px 0;
    background-image:url('boxbg.png');
}

Bear in mind that span will not obey to width and will take the width of the text inside unless you make it to display:block.

4 Comments

Thanks, the idea is same but the only problem is that the .text does not have fixed width, so i can not set background image position.
That is why you should paste your CSS and maybe a complete example of what you have. Maybe you just need a float after .text with the background image to get the effect you want but without examples you have us guessing.
Please see this jsfiddle.net/zr9Ks ; I dont want the box bg to appear below the text (it should appear only after the text.
in this case you owe to display span-text and span-bg inline inside a container and set their width 30%/70% or something...
1

I think i understood what you need:

.box {
    width:300px;
    padding-bottom: [height of the img];
    background: url('img.png') repeat-y left bottom;
}

Comments

1

If I understood your question correctly, all you need to do is to declare a different background image/color on .main and on .box and you're good to go.

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.