Powered by Blogger.
Have a great day!
Visit again!

CSS FOR PLACING MULTIPLE DIVS SIDE-BY-SIDE OR ONE-ABOVE-OTHER IN A RESPONSIVE DESIGN TO MATCH DIFFERENT SCREEN SIZES

   The greatest achievement of any science is to accomplish the most complicated things in the most cool and easy ways.    Here, we are considering four divs. They must fulfill following conditions:

   a. The arrangement should occur in the middle of the page.

   b. They must accommodate themselves on various screen sizes like mobile phones, tablets and laptops.

   c. They should be able to be arranged horizontally (side-by-side) as well as vertically (one-above-the-other)

   d. The html should apply to any number of divs

   Initially, I was able to achieve this after too much eye training and backbreaking efforts with a combination of 'float: left and media query' in the CSS. It was a near-perfect solution, but still not perfect. It was like going from London to Moscow via Sydney. Here, I will present a solution, much simpler than all the solutions described elsewhere and I think, there can be no easier way than this.

  
  Step-1
    

  By default, the basic CSS puts the divs one-above-the-other aligning them on the left side of the visible element. This is the basic html for the 4 different divs with different colors.

basic html & css for the multiple divs


basic html for the multiple divs

  This is the basic html for the 4 different divs a, b, c, d with different colors. 


  By default, the basic CSS puts the divs one-above-the-other aligning them on the left side of the visible element. 


  Step-2
   
   Each of these divs is a separate unit. Now let's add the property 'display: inline-block' into each div so that all these divs will be linked together like the carriages of a train or consider them like birds of the same flock where individual members may change their positions but won't leave the group.
adding display: inline-block to the html

  Step-3
   

   Now, let's put all these birds into one cage by applying a 'div id' to all four, so that any action applied to the cage will be automatically applicable to all of the accommodated individuals. Not to mention, the div id may not be visible on a white background as we have not applied the border tag to it.
The html will now look like –

applying 'div id' to the multiple 'div class'

  Step-4

   

   This is the final and very crucial step. Add align= "middle" (or align= "center" both mean the same) tag next to the id.
That's it! Now check the position of all the divs across different resolutions.

html for centering the divs
   
   THE FINAL OUTCOME


   On the small mobile phone where the screen is < 300 pixels, the colored divs will look like this. 
when the screen is < 300 pixels

   On the regular mobile or iPhone where the width is between 300 and 450 pixels, the arrangement will look like this. 
when the screen size is between 300 and 450 pixels

   On the tablet where the width is around 500 or 600 pixels, these divs will appear as: 
when the screen size is between 500 & 600 pixels

   On the laptops where the screens are always >600 pixels wide, the divs will stage themselves as:
when the screen size is always >600 pixels
* If you are watching this on your mobile screen, you may not get the full view.
  

Tip: You can replace align= "middle" with style="left: 50%; position: absolute;" or style="margin: auto; width: 75%;" to achieve almost the same results. 

  Also read this Great time & Money saver: A STEP-BY-STEP GUIDE TO FIX COMMON PROBLEMS AND ERRORS IN WINDOWS 10




 सत्यम्, शिवम्, सुंदरम् की मंगल परिभाषा युगों-युगों से जिसने दुनिया को सिखायी, क्या ऐसे सनातन धर्म के आप भी चाहते हैं? क्या हमारे देश की संस्कृति, परंपरा, सभ्यता और हमारी आधुनिक वैज्ञानिक उन्नति का आपको अभिमान है? तो जुड जाइए इस Telegram ग्रुप से जिसका नाम है - हम हिंदुस्तानी. CLICK TO JOIN


JaiShriram

1 comment:

Hey! Don't spread CORONA but you can share and spread this article and make it viral ! 😊

Click to Show EMOTICONS


Each smiley has its assigned code below it. You can type any code you like in your comments. The corresponding smiley will appear in your comment after it is published.

Popular Posts *click to read*

Touching Real Life Stories
successful weight losers
know your vitamin deficiency
what is spirituality
early evening raga based songs
depression
YOUNG AND HEALTHY health score
Uplift your mood audiovisual waves
Funny Google assistant
reincarnation of anne as borbro
alternative ways to heal cancer
Hi!  Search ANYTHING,
                      Buy ANYTHING! 
  
  Time for SHOPPING !
  Everything from A to Z 24x7


Subscribe by Email

(◔ᴗ◔) Note for Subscribers: Please make sure your activation link has not gone to the spam folder of your email.  

FEATURED

Touching Real Life Stories
successful weight losers
know your vitamin deficiency
what is spirituality
early evening raga based songs
depression
YOUNG AND HEALTHY health score
Uplift your mood audiovisual waves
Funny Google assistant
reincarnation of anne as borbro
alternative ways to heal cancer

Calculate Your BMI

Flag Widget

Online Dictionary

   Word Search
Dictionary, Encyclopedia & more
*
by:

Online Radio

• ONLINE RADIO ♪ ♬ 
VBS
RADIO VIVIDH BHARTI
• Old Is Gold ♪ ♩

Your Planetary Make-up