0

I have a div with absolute positioning, which serves as a kind of horizontal line, with a background image with x-repition. I want its width to fill up the whole page, but its x-position isn't 0 so I can't just give it width 100%. How do I do it?

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
Clox
  • 1,923
  • 5
  • 28
  • 43
  • Possible duplicate of [How to create an HTML button that acts like a link?](https://stackoverflow.com/questions/2906582/how-to-create-an-html-button-that-acts-like-a-link) – Exil Jun 02 '17 at 10:44
  • Uh.. How is that a duplicate? – Clox Jun 02 '17 at 12:34

3 Answers3

3

You can specify both left and right at the same time:

position: absolute;
left: 5px;
right: 5px; /* or whatever value you want */
ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
  • I don't understand how that would work? What should I set the width to with that? I did try setting right too but it didn't seem to make any difference at all. Using chrome by the way. – Clox Mar 15 '10 at 13:47
  • @Clox: the whole point of this approach is that you don't have to set the width explicitly, since it is calculated automatically. It's certainly news to me that it doesn't work in Chrome; I don't have access to Chrome right now, but I will test it later. – ЯegDwight Mar 15 '10 at 14:13
1

I think you would have to use javascript to capture the width of the window. Then assign the width to the div.

    var winW = 630, winH = 460;

    if (parseInt(navigator.appVersion)>3) {
     if (navigator.appName=="Netscape") {
      winW = window.innerWidth;
      winH = window.innerHeight;
     }
     if (navigator.appName.indexOf("Microsoft")!=-1) {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
     }
    }


  document.getElementById('divName').style.width = winW;
  document.getElementById('divName').style.height = winH;
Kyle
  • 1,662
  • 2
  • 21
  • 38
  • I prefer to avoid javascript but that might still come in handy sometime, thanks =) – Clox Mar 15 '10 at 13:48
1

I managed to solve it by nesting the div in another div which has left:0, with width:100% and overflow:hidden. Works perfectly =)

Clox
  • 1,923
  • 5
  • 28
  • 43