Help needed with css for object layout

  • Unknown's avatar

    On my homepage, i have 4 images for certain sections of my website. the 4 images are located under the title EXPLORE SECTIONS

    on desktop and table mode, these 4 images appear in one row, which i nice. however, in mobile mode, they appear as 4 images below each other. what CSS would i need to add to change it so the images appear as 2 images per row in mobile?

    thanks

    The blog I need help with is: (visible only to logged in users)

  • Hey @zahidmakda1986,

    I see you want your explore section’s images to align in a certain way.

    By your description and my understanding.

    • You wish to have 4 images in a single row on desktop or tablet.
    • You also wish to have 2 images in one row in mobile view.

      Please allow me to guide you through a simple workaround ( if it’s not available in your theme as a feature ).

      I have attached a CSS code below that you can try in your theme and we can circle back if it doesn’t work.
    body .is-layout-flex {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 1 rem;
    }
    
    @media (max-width: 768px) {
        body .is-layout-flex {
            grid-template-columns: repeat(2, 1fr);
        }
    
        body .wp-block-cover{
            min-height: 12rem !important;
        }
        body .wp-block-heading  {
            font-size: 1rem;
        }
        body .wp-block-group .has-background {
            padding: 0.5rem !important;
        }
    }

    You need to add this code in Appearance > Your Theme > Customize > Left Panel at the bottom “Additional CSS”.

    In case you don’t see any option like that, do let me know.

  • Unknown's avatar

    thanks. it worked a charm! thanks very much

  • Unknown's avatar

    actually, i noticed that this has affected all columns throughout the website. i only wanted the 2 accross on the above specified image section… is this possible to target only a specific section?

  • The theme you are using has generic class names for a lot of common elements. So yes that makes sense why that is happening.

    Can you share the name of theme you are using and I can construct a more viable solution for you?

  • Unknown's avatar

    the theme is called “The9 Store”

    its a free version I’m using.

  • Alright, let me have a look at it. I might offer you with few solutions that you can try. Alright?

  • Unknown's avatar
  • Alright let me provide you with a solution.

  • I am trying to write a whole article for help with images, but somehow forum isn’t letting me post it.

  • Unknown's avatar

    Will the forum let you upload it as a pdf document?

  • Alright, assuming you have used Gutenberg ( default editor ) of WordPress to design the cards manually, I am penning a solution for you.

    Follow these steps :

    Step 1: Open your page in editor ( the one which has these cards ).

    Step 2: I want you to select the main parent of these cards. Which in case is a group.

    You can select the main parent group by going to the top-left corner and see ‘Document Overview’ button > and click the main parent group of your cards. Please ensure you have selected the parent group before proceeding to the next step.

    Step 3: Now while main group being actively selected, go to the right settings panel and click on the Advanced drop down.

    Inside Advanced settings, you will see Additional CSS Classes(es) input box. Enter explore-cards inside of it and click on save button.

    Step 4: Paste the following code in Appearance > Your Theme > Customize > Left Panel at the bottom “Additional CSS”. ( Remove the previous code. )

    body .explore-cards {
        display: grid;
        grid-template-columns: repeat(1, 1fr);
        gap: 1rem;
    }
    
    @media (max-width: 768px) {
        body .explore-cards {
            grid-template-columns: repeat(1, 1fr);
        }
        
        body .explore-cards .wp-block-heading  {
            font-size: 1rem;
        }
        
        body .explore-cards.wp-block-group .has-background {
            padding: 0.5rem !important;
        }
    }

    This will apply the css to specific section only, as seen below.

    I tried imgur but it’s also not working today for images.

  • Unknown's avatar

    thanks for your hard work and suggestion, but unfortuantely it didnt change much. it’s now gone back to single cards per row.

  • Hey @zahidmakda1986,

    Did you select the parent group and add a custom class explore-cards to the it?

    In case you did, and it still doesn’t work. Don’t worry, I will try to get it running for you.

  • Unknown's avatar

    yes i did exactly as you said sir.

  • Unknown's avatar

    Should it not be #explore-cards instead of .explore-cards?

  • Since you added it to classes (explore-cards), the css for it should use a class selector.

    That goes like :

    .class-name { 
    
    }

    Also, I observed you added the an id-> “explore-cards” to the main group which is also fine. But I will recommend you using class instead.

    Also, on further inspection, I realized, you should be adding the class “explore-cards” not to the parent group, but the parent column.

    Group > Column > Column 1, Column 2, Column 3, Column 4

    Select Parent Column that consists all the card columns and add explore-cards class there.

    Then this following code :

    body .explore-cards {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 1rem;
    }
    
    @media (max-width: 768px) {
        body .explore-cards {
            grid-template-columns: repeat(2, 1fr);
        }
        
        body .explore-cards .wp-block-heading  {
            font-size: 1rem;
        }
        
        body .explore-cards.wp-block-group .has-background {
            padding: 0.5rem !important;
        }
    }
  • Unknown's avatar

    thanks. seems to be working now

  • Alright @zahidmakda1986, Please mark this topic as resolved.

  • The topic ‘Help needed with css for object layout’ is closed to new replies.