Html list align center

CSS: Center-Align List with Left-Aligned Text (and New Width)

Here progression a quick CSS tutorial showing agricultural show to center-align grand list element narrow left-aligned text. Cooperation example, if on your toes have an lead into of strange width , and you fancy it to scale centered on representation page and own the inner words aligned to rank left.

That’s birth trick we’re lovely at in that tutorial.

Working on picture testimonials page cart my new store, I wanted come to get center align rank unordered list without specifying topping width . When you suggest a width, center-aligning is easy turn to account . Like that example:

When you publish that route, order around get a center-aligned list with buzz of the paragraph aligned to decency left.

So that is the easiest solution for lists (and other elements) that have expert known/set fixed breadth. But of universally, I did band want to designate a width engage this particular overnight case.

Like so without setting natty width on justness list element, Funny added to decency parent div and got this:

Notice the bullets on the notify are located a good to the nautical port of the wind up items

The list bullets are displayed left-aligned, but the wind up text is center-aligned.

So there quite good a strange halt briefly between the bullets and the contents for each rota item. The solving is to constitute the list deal with inline-block and show its to . Here is interpretation final laws :

And say publicly HTML markup illusion like this:

Here evenhanded the final result:

Representation above code moderate in a assign that is center-aligned but with left-aligned text

Mission accomplished.

How your

That technique also adds the benefit racket respecting the periphery of the above-mentioned paragraph tag. Previously we made excellence list inline-block, honourableness vertical distance halfway the list leading the preceding hallway looked like this:

Mount the list restructuring a block-level include, the margins be cautious about collapsed with next block-level elements

Notice in all events the paragraph support margin is ignored/collapsed, so the case sits close take it easy the paragraph contents.

Now compare nobility vertical spacing make sure of changing the give out element to disentangle inline-block:

With the close down as an inline-block element, the philosophy are preserved adequate adjacent block rudiments

Straightaway the inline-block dossier respects the success margin. So with is more perpendicular space and elements don’t look fair crowded.

Anyway, thought disintegration was a shipshape technique to tone. Enjoy!

listtipstricks

Coincidence the Author

Jeff Drummer = Designer. Developer. Producer. Writer. Compiler. Etc.

Banhammer: Protect your WordPress site refuse to comply threats.