Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Centering a Div Element

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #22543
    BlueBox
    Member

    my first style sheet :oops: :

    Code:
    {

    margin: 0;
    padding: 0;
    border: 0;

    background-color: white;

    }

    /* Content ———————————————–*/
    div
    {
    vertical-align: middle;
    display: block;
    font-family: Georgia, serif;

    font-size: 16px;

    letter-spacing: 1px;

    padding: 20px 20px 20px 20px;
    margin: 20px 20px 20px 20px;

    background-color: white;

    border-left: 2px solid #cccccc;

    border-right: 2px solid #cccccc;

    border-top: 2px solid #cccccc;

    border-bottom: 2px solid #cccccc;

    width: 500px;
    }

    my problems are:
    – how do I align the div element to the center of the page
    – and how do I make the overflow words go to the next line

    Thanks for Helping

    #46834
    BlueBox
    Member

    Ill try that out right now.
    About the text i meant that if i draw a border around the div element and place a realy long line of text in it the text goes over the border

    #46847
    Chris Coyier
    Member

    Text, by default, should be wrapping down onto the next line automatically inside your div, you don’t need to do anything special to achieve that. The two exceptions are that somewhere else in the stylesheet "white-space" got set to "no-wrap", which prevents text from breaking down onto the next line. Or, the text doesn’t have any spaces in it. For example, really really long URL’s. Those have a habit of wanting to stick together on one line and busting outside of div’s.

    #46863
    BlueBox
    Member

    Thanks, it works!

    #53130
    ploughansen
    Member

    Is it possible to center a div inside another div, without giving it a width?

    Example:

    Code:

    I want the navigation centered inside the header, but I don’t want to constrain the width of the nav (at least not greater than the header).

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘CSS’ is closed to new topics and replies.