Class 6 Exam  >  Class 6 Notes  >  CSS for Beginners  >  CSS- Max-width

CSS- Max-width | CSS for Beginners - Class 6 PDF Download

CSS Layout - width and max-width


Using width, max-width and margin: auto;


As mentioned in the previous chapter; a block-level element always takes up the full width available (stretches out to the left and right as far as it can).
Setting the width of a block-level element will prevent it from stretching out to the edges of its container. Then, you can set the margins to auto, to horizontally center the element within its container. The element will take up the specified width, and the remaining space will be split equally between the two margins:
CSS- Max-width | CSS for Beginners - Class 6Note: The problem with the <div> above occurs when the browser window is smaller than the width of the element. The browser then adds a horizontal scrollbar to the page.
Using max-width instead, in this situation, will improve the browser's handling of small windows. This is important when making a site usable on small devices:
CSS- Max-width | CSS for Beginners - Class 6

Tip: Resize the browser window to less than 500px wide, to see the difference between the two divs!
Here is an example of the two divs above:
Example

div.ex1 {

  width: 500px;

  margin: auto;

  border: 3px solid #73AD21;

}


div.ex2 {

  max-width: 500px;

  margin: auto;

  border: 3px solid #73AD21;

}

The document CSS- Max-width | CSS for Beginners - Class 6 is a part of the Class 6 Course CSS for Beginners.
All you need of Class 6 at this link: Class 6
Are you preparing for Class 6 Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Class 6 exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free
10 videos|41 docs|23 tests

Up next

10 videos|41 docs|23 tests
Download as PDF

Up next

Explore Courses for Class 6 exam
Related Searches

Previous Year Questions with Solutions

,

Sample Paper

,

Free

,

Extra Questions

,

CSS- Max-width | CSS for Beginners - Class 6

,

ppt

,

practice quizzes

,

video lectures

,

mock tests for examination

,

past year papers

,

pdf

,

shortcuts and tricks

,

CSS- Max-width | CSS for Beginners - Class 6

,

Summary

,

CSS- Max-width | CSS for Beginners - Class 6

,

study material

,

Semester Notes

,

Viva Questions

,

Exam

,

Objective type Questions

,

Important questions

,

MCQs

;