Jump to content

can you use an image background to define the dimensions of a div?


Darkmatter5

Recommended Posts

The topic says it all.  Can I create an image and use it as a background in a div and have the div use the size of that image as the dimensions for the div?

 

If not can I insert an image into the div and have all the text and content of the div display on top of the image?  Basically putting the image under all the content, but NOT as the background, but as an actual image to force the div to use the images size as its dimensions?

Link to comment
Share on other sites

You can only have text over background images. Why do you want to the div to automatically adjust to your background image? Cant you hard code the width/height of the div?

 

#my_div {
    background-image: ('my_background.gif');
    background-repeat: no-repeat;
    width: 700px;
    height: 100px;
}

Link to comment
Share on other sites

Q&A 2: not naturally. But you can try the following

 

    span {
        position: relative;
        color: #FF0000;
        top: -50px;
        left: -50px;
    }

    <div>
        <img src="image.jpg" height="100px"><span>Text</span>
    </div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.