Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

How to indent text within a div using HTML and CSS?

  • 11-02-2012 04:00PM
    #1
    Closed Accounts Posts: 11


    I am new to both Boards and to web development but I must create a website using the two technologies mentioned above.

    Anyway my burning issue at the moment is how to indent entire divs, Can this be done by changing my CSS?

    For example I want:

    ___________Hello,

    ___________I'm new here.

    ___________Your help would be great

    Instead of:

    Hello,

    I'm new here.

    Your help would be great.


    P.s. I tried using the npsb or whatever keyword it is that indents text but this was very messy as it only indents that line.

    Thanks for any advice!


Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Registered Users, Registered Users 2 Posts: 12,020 Giblet
    ✭✭✭✭


    Use padding, text-indent only works on the first line.
    div { padding: 10px; }

    Margins can be used too, but they are used for spacing on the outside of the element.

    If you are having issues with the width after using padding, either subtract the width of the padding (both sides) from the width of the container, or use
    box-sizing: border-box;
    or
    box-sizing: padding-box;

    box-sizing isn't supported in some browsers though, and some browsers require prefixes such as -moz-box-sizing, or -webkit-box-sizing.


  • Closed Accounts Posts: 18,163 Liam Byrne
    ✭✭✭✭


    Giblet wrote: »
    Use padding, text-indent only works on the first line.
    div { padding: 10px; }

    Margins can be used too, but they are used for spacing on the outside of the element.

    If you are having issues with the width after using padding, either subtract the width of the padding (both sides) from the width of the container, or use
    box-sizing: border-box;
    or
    box-sizing: padding-box;

    box-sizing isn't supported in some browsers though, and some browsers require prefixes such as -moz-box-sizing, or -webkit-box-sizing.

    Avoid padding! It's completely different across browsers.

    Just set the margin of everything within the div to 10 or whatever.


  • Registered Users, Registered Users 2 Posts: 12,020 Giblet
    ✭✭✭✭


    Why avoid padding? Just take the other browsers into account? You would have to create another inner element to use margins in that way. If you want all padding to be consistent, use the correct box-sizing if need be (as in, make newer browsers behave like older browsers), or just use a conditional statement to target ie if that's the issue, and just avoid the float/margin bug is ie.


  • Registered Users, Registered Users 2 Posts: 8,070 Placebo
    ✭✭✭


    isnt box model just different in older ie's?
    not sure how you can avoid padding without using extra div's


  • Registered Users, Registered Users 2 Posts: 12,020 Giblet
    ✭✭✭✭


    Box model is border-box in quirks mode. (Old IE and IE6 in some respects).
    Margins have problems in old IE too, the infamous
    http://www.positioniseverything.net/explorer/doubled-margin.html


  • Advertisement
  • Closed Accounts Posts: 18,163 Liam Byrne
    ✭✭✭✭


    Placebo wrote: »
    isnt box model just different in older ie's?
    not sure how you can avoid padding without using extra div's

    They don't need to be divs - they can be standard elements inside the "padded" div, such as paragraphs and uls and the like.


  • Registered Users, Registered Users 2 Posts: 50 Smithy2306
    ✭✭


    Use the css margin and float attributes. If you want the text inside the div centered use text-align: center in the divs css.


Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement