Solved

Minimum and maximum size (width) in CSS

Posted on 2009-04-12
8
2,043 Views
Last Modified: 2012-05-06
Hi E's, all the projects I produce in the web has been made in css, but never with liquid size. Now I want produce a site with the measures as a percentage.
I want to know how I define for a width, a minimum size and a maximum size using css.
This is just because I want optimize my site for minimum of width-1024 and maximum 1920. In this way if customer have a resolution of 800*600, the browser don't destroy my design.

What is the best trick for the minimum and maximum size?

Regards, JC
0
Comment
Question by:Pedro Chagas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24126182
You can specify a minimum an maximum width for an element using the "min-width" and "max-width" styles:
#something {
   min-width: 10%;
   max-width: 90%;
}

Open in new window

0
 
LVL 13

Assisted Solution

by:numberkruncher
numberkruncher earned 80 total points
ID: 24126185
So for your particular example:

#something {
   min-width: 1024px;
   max-width: 1920px;
}

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 24126264
Hi, Thanks for the answers. Just one doubt, min a max-width work with IE6?

Regards, JC
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 13

Expert Comment

by:numberkruncher
ID: 24126286
According to QuirksMode (http://www.quirksmode.org/)  min-width and max-width are not supported by IE6.

When you want to find out if a feature (be it CSS, JavaScript, HTML) is supported by different web browsers, QuirksMode (http://www.quirksmode.org/) is the site to visit. It lists computability comparisons for most features. I use this website all of the time, it is fantastic.
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 24126321
Hi, for the minimum size is good idea use a image with 1024 width? The image resolve the issue?
Regards, JC
0
 
LVL 18

Assisted Solution

by:Hube02
Hube02 earned 80 total points
ID: 24126492
a reasonable work around for IE6.

As is stated, IE6 does not understand min/max width. But IE6 also does not understand the > child selector. Also, IE6 considers width to be min-width and will enlarge the width of an element. There is no fix for max-width.

to do this we create out wrapper div that we'll use to set up the widths of out page:

<body>
  <div id="wrapper">
    <!-- rest of html here -->
  </div>
</body>

for css:

/* set up default that will be used by IE6 */
#wrapper {
  width: 1024px;
}

/* now alter the width for browsers that understand the > child selector
     and min/max width */

body>#wrapper {
  width: auto;
  min-width: 1024px;
  max-width: 1920px;
}


/**************************

for more on the child selector: http://www.w3.org/TR/CSS2/selector.html#child-selectors
0
 
LVL 13

Expert Comment

by:qwerty021600
ID: 24128032
Give

min-width: 1024px;
width: 1920px;
0
 
LVL 4

Accepted Solution

by:
rafe_ earned 190 total points
ID: 24130322
As Hube02 said, IE6 does not recognise the min or max width and height attributes at all. However there is a better fix which does not require you to split up your properties into different statements, and is more intuitive to work with.

IE6 treats width and height as a min width and height respectively, and at the same time, it is the only browser which does not recognise the !important modifier, which is normally used to create a hierachy of css properties.

Hope that helps!
/* CSS FOLLOWS */
 
div.container {
 
 width: auto !important; /*non-IE browsers prefer this width property*/
 min-width: 1024px; /*IE ignores this completely*/
 width: 1024px; /*IE uses this property for width rather than the previous one because it ignores !important*/
 
 
}
 
 
/* CSS ENDS */
 
<!--HTML FOLLOWS-->
 
<body>
<div class="container">
 
</div>
</body>

Open in new window

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question