0

hey guys was hoping you could help me out..

The task seems simple but I just cant figure it out...

i.e

<div style="text-align: center;background-color: rgb(150, 161, 255);  " id="clock">
        asd
</div>

I have a div with some text in it, and I want to center align that text and make the background such that it stays only behind the text.

doing display:inline makes the background stay only behind the text, but then the text is no longer center alligned.

tried all display properties of css but no luck diddnt work.

been googling for like 20 minutes now but I guess im not sure what to search for .

any help would be appreciated.thanks.

3

3 Answers 3

4

Have a look at this:

HTML:

<div>
    <span>
        my text
    </span>
</div>

CSS:

div {
    background: red;
    text-align: center;
}

span {
    background: lime;
}

Live example: JsFiddle

1
  • Just a couple of seconds faster than me
    – menislici
    Jul 6, 2012 at 12:01
1

Why not add a span tag to the text inside the div and style it?

<div style="text-align: center; " id="clock">
    <span>asd<span>
</div>​

And the css

#clock span{
background-color: rgb(150, 161, 255);
}​

Example

0
0

please check i hope this will help you i tried to make according to your requirement..

 <div style="text-align: center;background-color: rgb(150, 161, 255); display:table; margin:auto;  " id="clock">
            asd
    </div>

demo :- http://tinkerbin.com/L8AOfd5P

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.