Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3932696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:31:07+00:00 2026-05-19T23:31:07+00:00

This is my first SO post, forgive me if my formatting stinks. I’m trying

  • 0

This is my first SO post, forgive me if my formatting stinks.

I’m trying to format some product categories listings. Categories are grouped together by classification. I can get the .preview_box divs to align the way I want and I can get the contents of the .preview_box divs to align the way I want. What I can’t figure out how to do is keep the .classification divs appearing inline and centered. The way I’m getting them inline now is by putting a left float on them, which negates the ability to center them.

How can I center block contents with unknown widths in an unknown width div when my overall page layout’s container’s width is unknown also (80%, min-800px, max-1200px)?

Here’s an idea of my html & css:

<div class="previews">
  <% @classifications.each do |classification| %>
    <div class="classification">
      <h3>
        <%= classification.title %>
      </h3>
      <% classification.subcategories.each do |subcategory| %>
        <div class="preview_box">
          <div class="subcategory_preview_image">
            <% if subcategory.image? %>
              <%= link_to image_tag(subcategory.image.url(:thumbnail)), abbr_subcategory(subcategory) %>
            <% elsif subcategory.products.present? and subcategory.products.first.product_images.present? %>
              <%= link_to image_tag(subcategory.products.first.product_images.first.image.url(:thumbnail)), abbr_subcategory(subcategory) %>
            <% else %>
              <%= link_to image_tag('subcategories/missing.png'), abbr_subcategory(subcategory) %>
            <% end %>
          </div>
          <div class="subcategory_preview_text">
            <%= link_to subcategory.title, abbr_subcategory(subcategory) %>
          </div>
        </div>
      <% end %>
    </div>
  <% end %>
</div>

.previews {
}
.classification {
  margin: 3px;
  padding: 3px;
  float: left;
  text-align: center;
}
.previews .preview_box {
  position: relative;
  width: 120px;
  height: 150px;
  float: left;
  margin: 10px;
}
.previews .preview_box .subcategory_preview_image {
  position: absolute;
  bottom: 40px;
  width: 120px;
}
.previews .preview_box .subcategory_preview_image img {
  display: block;
  margin: 0 auto;
}
.previews .preview_box .subcategory_preview_text {
  position: absolute;
  top: 110px;
  width: 120px;
  text-align: center;
}

Here’s an idea of how it looks currently.

What I’m trying to do is center those gray boxes in the container without having each gray box on its own line, without knowing the width of any of the gray boxes or the width of the white container.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:31:08+00:00Added an answer on May 19, 2026 at 11:31 pm

    I’m not sure if i understand you correctly but this may work for you.
    You need to adapt it to your needs but it should work

    http://jsfiddle.net/wxarF/

    Update:
    http://jsfiddle.net/wxarF/1/

    CSS:

    .previews {
        width: 600px;
        text-align: center;
        border: 1px solid #ccc;
        padding: 20px;
    }
    
    .classification div {
        display: inline-block;
        background: #eee;
        padding:3px;
        margin:0 5px 5px 0;
        border: 1px solid #ccc;
    }
    
    .preview_box {
        display: inline-block;
        background: #ccc;
        margin-right: 3px
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
[please forgive formatting errors-- first post here and I tried earnestly to do it
This is my first post, so please forgive me if this question has been
This is my first post, and first please forgive me for my poor english.
This is my first post to Stack Overflow so please forgive me if I
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post and I have am concerned that some might think
This is my first post. Please forgive me for asking a basic question as
I'm trying to render the list of blog posts in this layout: [first post
Okay this is my first post here so please forgive me if i mess

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.