Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Backgrounds

  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    175
    Thanks
    4
    Thanked 6 Times in 6 Posts

    Backgrounds

    Is there any way to make a background colour just for text in CSS? I was highlighting someing and decided I actually quite liked how it looked.



    When you put it as the background colour, it obviously colours the whole div...



    So can you set a colour just for the background of the text in CSS?

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,957
    Thanks
    9
    Thanked 727 Times in 721 Posts
    Wrap the required text in span tags and apply the required background to the span:

    Code:
    html
    <p>Some text. <span class="highlight">And some text that's highlighted.</span></p>
    
    css
    .highlight{background-color:#FFCC00}
    This will work because <span> is an inline element, unlike <p> or <div> which are block elements by default.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •