Fluid DIVS On HTML / CSS Layout - Stack Overflow

    1. Home
    2. Questions
    3. Tags
    4. Users
    5. Companies
    6. Labs
    7. Jobs
    8. Discussions
    9. Collectives
    10. Communities for your favorite technologies. Explore all Collectives

  1. Teams

    Ask questions, find answers and collaborate at work with Stack Overflow for Teams.

    Try Teams for free Explore Teams
  2. Teams
  3. Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Get early access and see previews of new features.

Learn more about Labs Fluid DIVS on HTML / CSS Layout Ask Question Asked 10 years, 11 months ago Modified 10 years, 9 months ago Viewed 2k times 0

This is the first time i'm trying to create a custom html page from scratch and I'm having some trouble :

This is what i want basically:

enter image description here

I want the site to automatically resize according to the window size - the first div bg should be full width and its inside should be fixed width (centered)

I first tried creating each divs manually - seems ok so far except the inside div inside the header i want to center

I'm really noob in css/html , so if there is any way to improve my code - please let me know

I tried several ways but keep getting stuck .

Tried:

  • MaxDesign Article
  • LayZilla
  • CSS-Tricks Fluid

I was using the above as examples , but i kept getting stuck so i decided to start from zero

CSS

#body_wrapper { width:100%; background:white; } #header { width:100%; height:200px; background:red; } #header_inside { width:500px; height:180px; background:green; } #content { width:100%; height:600px; background:blue; } #footer { width:100%; height:200px; background:yellow; }

HTML

<body> <div id="body_wrapper"> <div id="header"> <div id="header_inside"></div> </div> <div id="content"></div> <div id="footer"></div> </div> </body> Share Improve this question Follow edited Feb 1, 2014 at 15:47 gsnerf's user avatar gsnerf 5721 gold badge4 silver badges16 bronze badges asked Jan 31, 2014 at 5:11 John_Nil's user avatar John_NilJohn_Nil 1352 gold badges4 silver badges17 bronze badges Add a comment |

7 Answers 7

Sorted by: Reset to default Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first) 1

To center a div, use: margin:auto;. So;

#header_inside { margin: auto; [ ... ] } Share Improve this answer Follow answered Jan 31, 2014 at 5:17 DACrosby's user avatar DACrosbyDACrosby 11.4k3 gold badges41 silver badges52 bronze badges Add a comment | 0

I hope this is what you want ::

http://jsfiddle.net/rahulrulez/b4gWx/

Just add following properties to inner divs.. I have followed HTML5 convention and I recommend you to do so.

width:500px; margin:0 auto;

After getting familiar with HTML and CSS enough.. I recommend you to kick start development with frameworks like Twitter Bootstrap or Zurb Foundation

Share Improve this answer Follow answered Jan 31, 2014 at 5:25 Rahul's user avatar RahulRahul 5,7747 gold badges38 silver badges68 bronze badges Add a comment | 0

Change the css for header like this:

#header { box-sizing: border-box; padding: 10px 0; width: 100%; height: 200px; background: red; } #header_inside { margin: 0px auto; width: 500px; height: 180px; background: green; } Share Improve this answer Follow answered Jan 31, 2014 at 5:21 faster's user avatar fasterfaster 1515 bronze badges Add a comment | 0

If responsive and resizing is your priorty try Twitter Bootstrap Css . It works great for responsive features with the help of predefined classes itself.

Share Improve this answer Follow answered Jan 31, 2014 at 5:23 Learner's user avatar LearnerLearner 8101 gold badge13 silver badges35 bronze badges 1
  • Thanks A Lot Guys - Been really helpful - Once i get 10 rep , i'll vote up evryone – John_Nil Commented Jan 31, 2014 at 16:28
Add a comment | 0

The margin: auto solution should work.

You can also use text-align:

.outerDiv { width: 100%; text-align: center; } .innerDiv { width: 500px; text-align: left; } Share Improve this answer Follow answered Jan 31, 2014 at 6:03 DA.'s user avatar DA.DA. 40.6k50 gold badges157 silver badges217 bronze badges Add a comment | 0

HTML

<div id="wrapper"> <div id="header"> <div id="logo"></div> </div> <div id="menu"> <div id="menuitems"></div> </div> <div id="content"> <div id="contents"></div> </div> <div id="footer"> <div id="footers"></div> </div> </div>

CSS

* { margin:0px; padding:0px; } #wrapper { width:100%; border:1px solid black; height:1000px; } body { width:100%; border:1px solid black; height:1000px } #header { width:100%; height:100px; border:1px solid red; display:block; } #logo { width:50%; margin:5px auto; border:1px solid red; height:50px; display:block; } #menu { width:100%; height:30px; border:1px solid blue; display:block; } #menuitems { width:50%; margin:5px auto; border:1px solid blue; height:15px; display:block; } #content { width:100%; height:800px; border:1px solid green; display:block; } #contents { width:50%; margin:15px auto; border:1px solid green; height:650px; display:block; } #footer { width:100%; height:60px; border:1px solid orange; display:block; } #footers { width:50%; margin:5px auto; border:1px solid orange; height:40px; display:block; } Fiddle Share Improve this answer Follow answered Jan 31, 2014 at 6:29 Amarnath Balasubramanian's user avatar Amarnath BalasubramanianAmarnath Balasubramanian 9,4508 gold badges37 silver badges62 bronze badges Add a comment | 0

Html

<html> <head> <style> header,nav,section,footer{ width:960px margin:0 auto } </style> </head> <body> <header> <div id="logo"></div> <nav> <u1> <li>list items</li> <ul> </nav> </header> <section> <article>your content follows here</article> </section> <footer> </footer> </body> </html> Share Improve this answer Follow answered Apr 5, 2014 at 8:41 Narayana's user avatar NarayanaNarayana 1001 silver badge10 bronze badges Add a comment |

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Draft saved Draft discarded

Sign up or log in

Sign up using Google Sign up using Email and Password Submit

Post as a guest

Name Email

Required, but never shown

Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

  • The Overflow Blog
  • How AI apps are like Google Search
  • Featured on Meta
  • The December 2024 Community Asks Sprint has been moved to March 2025 (and...
  • Stack Overflow Jobs is expanding to more countries
1 Css fluid layout 0 CSS Fluid Layout? 6 Fluid layouts with CSS 2 Semi Fluid Layout CSS/Html 0 how to make my website fluid? 0 Fluid layout with CSS 1 fluid layout positioning divs 0 How to Make a Fluid Layout 0 fluid semi-fluid fluid divs 1 CSS fluid layout and dropping divs

Hot Network Questions

  • How many hours of daylight can a planet in an elliptical orbit receive?
  • Hebrews 2:11 - If we are brothers of Jesus and share in our Father's inheritance, and Jesus is God, does that imply we also are God?
  • Free Kei Friday
  • Canada's Prime Minister has resigned; how do they select the new leader?
  • Escape braces in C# interpolated raw string literal
  • Is sales tax determined by the state in which the SELLER is located, or the state in which the PURCHASER is located?
  • Varying output from single file
  • Online Service Course in the era of ChatGPT
  • Helping daughter with taxes - How do I report some freelance work for her?
  • What's left of wine or vodka after the water and alcohol is boiled off?
  • Would the disappearance of domestic animals in 15th century Europe cause a famine?
  • Implement a hamiltonian simulation on a diagonal matrix?
  • How to swim while carrying fins (i.e., when the fins aren't positioned on my feet)?
  • What's the exact meaning of 'unblinking gimlet intensity'?
  • MAX3485 TTL to RS-485 Fake Chinese Modules. No output, wrong chip (Counterfeit?)
  • Cannot solve this naive exponential equation with base coefficient > 1
  • A miniature Thermometer Sudoku (ThermoDoku)
  • QGIS labeling: Why do we need a primary key for the auxiliary storage?
  • How to Modify 7447 IC Output to Improve 6 and 9 Display on a 7-Segment
  • Do we know when a cohomology theory "comes from a site"? In particular, is compactly supported cohomology a sheaf cohomology on a site?
  • exploratory factor analysis, non-normal data
  • Why do we define the standard error to ignore bias (unlike MSE which includes bias)?
  • What is the best way to prevent this ground rod from being a trip hazard
  • 3 phase asynchronous motors in tandem
more hot questions Question feed Subscribe to RSS Question feed

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

lang-html

Từ khóa » Html Fluid Layout Div