0

"Inline-block" and "position" confuse me when I use them with list items. Dreamweaver CS3 isn't helping since it doesn't show the blocks inline but as a stack of elements. I'm interested in learning the best practices for getting block elements of various heights to align along their top edges while also centering within the total available space.

Would you please look at this pared-down code to see if I've done it properly? http://www.words4it.com/test_block1.html

Here's the CSS: http://words4it.com/test_block1.css

Thank you

3
  • It looks good to me. If you're looking to make the elements lock together even tighter vertically, try jQuery Masonry. Commented Aug 4, 2012 at 21:20
  • Documentation on the CSS display property is here: developer.mozilla.org/en-US/docs/Web/CSS/display Commented Jan 14, 2017 at 5:25
  • ... and note that display: inline-block is considered a legacy value. Commented Jan 14, 2017 at 5:36

1 Answer 1

1

here is the good article about positioning elements

here is the good article about element sizes, margins and paddings

and after all, my short advice about blocks, inline-blocks and floats: browser has two general models of aligning elements:

  1. inline model, blocks stick to each other horizontally making horizontal lines of blocks with line-breaks between blocks, you may think about it like words in the text. Using this model you operate the following properties:

    • font-size
    • line-height
    • text-align
    • vertical-align
    • etc.
  2. block model, blocks stick to each other vertically making vertical stack of blocks, you may think about it like paragraphs in the text. Using this model you operate the following properties:

    • margin
    • padding
    • float/clear
    • position
    • etc.

The corresponding model should be used when you are trying to achieve the described behaviour. There is little exception: several blocks with the same float value (e.g. float:left) can behave very similar to several inline-blocks, the difference is in browser compatibility and thу choise should depend on situation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.