What is the correct way to do a CSS Wrapper?

后端 未结 9 2119
后悔当初
后悔当初 2020-12-07 12:45

I have heard a lot of my friends talk about using wrappers in CSS to center the \"main\" part of a website.

Is this the best way to accomplish this? What is best pra

相关标签:
9条回答
  • 2020-12-07 13:30

    a "wrapper" is just a term for some element that encapsulates all other visual elements on the page. The body tag seems to fit the bill, but you would be at the mercy of the browser to determine what displays beneath that if you adjust the max-width.

    Instead, we use div because it acts as a simple container that does not break. the main, header, footer, and section tags in HTML5 are just div elements named appropriately. It seems that there could (or should) be a wrapper tag because of this trend, but you may use whichever method of wrapping you find most suitable for your situation. through classes, ids and css, you can use a span tag in a very similar way.

    There are a lot of HTML element tags that we do not use often or possibly even know about. Doing some research would show you what can be done with pure HTML.

    0 讨论(0)
  • 2020-12-07 13:32

    You don't need a wrapper, just use the body as the wrapper.

    CSS:

    body {
        margin:0 auto;
        width:200px;
    }
    

    HTML:

    <body>
        <p>some content</p>
    <body>
    
    0 讨论(0)
  • 2020-12-07 13:32

    The easiest way is to have a "wrapper" div element with a width set, and a left and right margin of auto.

    Sample markup:

    <!doctype html>
    <html>
    <head>
        <title></title>
        <style type="text/css">
            .wrapper { width: 960px; margin: 0 auto; background-color: #cccccc; }
            body { margin: 0; padding: 0 }
        </style>
    </head>
    <body>
        <div class="wrapper">
            your content...
        </div>
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题