Jump to content

CSS: Fix a div?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
niggoo

niggoo

    Newbie

  • Members
  • Pip
  • 5 posts
Hello,
my question:
How can I set a fix height or width for a div?

Example:
<div id="container">
</div>

CSS:
#container {
?????????
}

If I just enter width: 70% (or height), the div is "growing" with the content. How can I fix the size?

Thank you for helping me.
I think it´s very easy:)

Kind regards
niggoo

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Try just "width:100px;" or "height:100px;" instead of "width:100%;", should work... I think, haven't played with CSS for a while. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
Pixels set a exact width or height where as percentages change depending on browser height/width or screen height/width.

#4
Scuby

Scuby

    Newbie

  • Members
  • Pip
  • 8 posts
With percentages the higher the window is, the higher the div is... but try just to play with it little bit... you could try overflow: hidden; and display: block; ... but that shouldn't affected

#5
Guest_johnny.dacu_*

Guest_johnny.dacu_*
  • Guests
for the sake of "art": i belive if you use pt or em you'll have a fixed dimension container too.

#6
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts
Include content that matches the width and height of the div. For instance, a bar across the top and another bar along one of the sides, with visibilities set to "invisible". That's the way I do it when it doesn't work.

#7
DarkLordofthePenguins

DarkLordofthePenguins

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 409 posts

thegamemaker said:

Try just "width:100px;" or "height:100px;" instead of "width:100%;", should work... I think, haven't played with CSS for a while. :)

I have found this doesn't work in a lot of cases. CSS is one of my least favorite computer languages.

#8
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
For a div such as container as I am guessing you are trying to make it the div which will hold the whole page usually only a width is fixed: I tend to use 900px for mine. The height will be based depending on what you have on the current page, which basically means that you can use that div on bot the home page and on the about page. Either way setting a fixed with and height is done through pixels just as thegamemaker said.


DarkLordofthePenguins said:

I have found this doesn't work in a lot of cases. CSS is one of my least favorite computer languages.
I was going to ask you to show me one of those cases until you said CSS is a computer language... I see it more like Paint. But please provide me with some of those examples anyway.