1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

CSS background colour and HTML image

Discussion in 'CSS' started by ianhaney, Oct 7, 2013.

  1. #1
    Hi

    I am having a css/html image issue

    I got a static image using a css class called static, on my 1024 screen size it is perfect but on my 1280 screen I want the image to have a background colour of a dark grey that extends further than the image if that makes sense

    I am using css mediaqueries for the larger screen

    I can't work out how to do it, the HTML is below

    <img src="images/landlordrefurbstatic4.jpg" alt="" title="" class="static">
    HTML:
    The CSS is below

    /* Media Queries */
    
    @[USER=124521]media[/USER] only screen and (min-width: 1280px) {
    
    .static {
    width: 1120px;
    height: 320px;
    margin: 0 0 0 -67px;
    background: #373737;
    }
    
    }
    Code (markup):
    Sorry to post again

    Kind regards

    Ian
     
    ianhaney, Oct 7, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #2
    generally speaking any image of that size probably isn't content -- and as such doesn't belong in a IMG tag in the first place... it SOUNDS like you might be talking about what should be your body background -- but without seeing the image itself and how it's placed on the page it's hard to weigh in more than that.

    Though 1120x320 is WAY too massive to have any business on a site unless it's the actual page content (like in a image gallery) if you care about accessibility, page speed, etc, etc... It almost sounds like you've painted yourself into one of the three major /FAIL/ at web design -- a fixed width layout. (the other two of course being fixed metric (px) fonts and illegible color contrasts)
     
    deathshadow, Oct 7, 2013 IP
  3. Tony Pham

    Tony Pham Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    Your css is making image resized to 1120px width and 320px height, so the background is not applicable anyway because image will full of that area.
     
    Tony Pham, Oct 12, 2013 IP
  4. sellerfriend

    sellerfriend Greenhorn

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #4
    i think if it is not specified the size would be original
     
    sellerfriend, Oct 12, 2013 IP
  5. Jason Macfarlane

    Jason Macfarlane Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    21
    #5
    Instead of adding the background color on the image, try wrapping the image with a div and add the background color to that.

    HTML
    <div class="bg-color">
        <img src="images/landlordrefurbstatic4.jpg" alt="" title="" class="static">
    </div>
    HTML:
    CSS
    @[USER=124521]media[/USER] only screen and (min-width: 1280px) {
    .static {
        width: 1120px;
        height: 320px;
        margin: 0 0 0 -67px;
    }
    }
    
    .bg-color {
        width: 100%;
        background: #373737;
    }
    Code (markup):
    Start from that and see what happens :)
     
    Jason Macfarlane, Oct 13, 2013 IP
  6. 100wordrants

    100wordrants Active Member

    Messages:
    93
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    93
    #6
    Try doing something like this for your CSS. This will center your image to the top and put the background color to #373737.

    .static {
    background-image: url(images/your-image.jpg) no-repeat;
    background: #373737;
    margin: 0 auto;
    }
    Code (markup):
     
    Last edited: Oct 22, 2013
    100wordrants, Oct 22, 2013 IP
    WebBuddy likes this.
  7. WebBuddy

    WebBuddy Well-Known Member

    Messages:
    1,364
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    100
    #7
    Thanks @100wordrants ! I was having a similar issue. Although the specifics were different but solution from you guys helped me out. It was actually a no-brainer after all haha :p

    I will send you a PM today or tomorrow, and if you could help me with some more coding, it'd be great. Thanks!
     
    WebBuddy, Oct 22, 2013 IP
  8. 100wordrants

    100wordrants Active Member

    Messages:
    93
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    93
    #8
    @WebBuddy Sure thing. Ill do what I can. Hope others can find this useful.
     
    100wordrants, Oct 22, 2013 IP