Welcome to Dream.In.Code
Become an Expert!

Join 149,520 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,407 people online right now. Registration is fast and FREE... Join Now!




Indenting Items in a Series

 
Reply to this topicStart new topic

Indenting Items in a Series

grinsalot
2 Jun, 2007 - 11:52 AM
Post #1

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 50


My Contributions
Hi,

I'm a novice when it comes to programming in Xhtml. I am attempting to write the code for a small program that will display some items indented, others not.

CODE
<div class="Items">
        <h2>List of Items</h2>
<div style="margin-left:27px; margin-right:27px;
text-align:justify">
        Groceries: Milk<br/>
        Clothing:   Shirts<br/>
<p class="indent">
<p style="margin-left:104px">
         Sweaters<br/>
<div style="margin-left: 0px; margin-right:27px;
text-align:justify">
         Delivery Hours: 8-10<br/>


I'm not even sure if this is the correct way to code this. The list looks fine, except that I have extra spaces between two items in a category. I understand that this is due to the fact that I have used the p-tag. However, I don't know any other way around this. I thought I could make a list but don't understand how to achieve this without outputting bullets or numbers. I obviously need to indent certain items and then restore my default margins. It's the how that I'm lost on.

Thank you in advance for any help.
User is offlineProfile CardPM
+Quote Post

Arbitrator
RE: Indenting Items In A Series
2 Jun, 2007 - 10:35 PM
Post #2

D.I.C Regular
Group Icon

Joined: 26 Jan, 2005
Posts: 492



Thanked: 1 times
My Contributions
Some Issues:
  • I would not use XHTML until Internet Explorer supports it. HTML is easier and I strongly doubt that you’re using any of XHTML’s special features (you’re not if the page works in Internet Explorer).
  • I would not use inline CSS (added via the style attribute). This makes your code harder to maintain. You can still include CSS on the same page (instead of an external file) by putting it inside of one or more style elements within the head element of your document.
  • All elements must be explicitly closed in XHTML. It looks like you have two open paragraph elements. If they’re closed later (in code that you didn’t provide) then you have other errors since p and div elements are not allowed inside p elements.
  • Paragraph elements are used for marking up paragraphs. Please use them correctly. One word without punctuation does not constitute a paragraph.
  • The br element can (and should almost always) be avoided in favor of CSS.

Anyway, I’m not sure what the complete list of content looks like or how you intend to present it, but, since you’re associating data, a definition list (dl) or table are probably the most appropriate elements for your content. Example:

CODE
<div class="Items">
    <h2>List of Items</h2>
    <dl>
        <dt>Groceries</dt>
        <dd>Milk</dd>
        <dt>Clothing</dt>
        <dd>Shirts</dd>
        <dd>Sweaters</dd>
        <dt>Delivery Hours</dt>
        <dd>8–10</dd>
    </dl>
</div>

It might actually make more sense to split that up into two lists since the last set of items don’t seem to go together with the other two sets. Additionally, you could use a (much more complicated) table, although I would avoid doing so.

To indent content, you can use the text-indent, margin-left, or padding-left properties. For example:

CODE
/* Indent all of the list items to the left. */
.Items dl { padding-left: 1em; }
CODE
/* Indent only the “dd” content to the left. */
.Items dd { text-indent: 1em; }

Note that you probably want to set all browser default margins and padding to zero at the beginning of your main style sheet, if you haven’t already. Otherwise, you have to deal with inconsistent browser defaults. Example:

CODE
* { margin: 0; padding: 0; }

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 08:25PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month