Centering 2 DIV's side by side on Responsive Layout |
Centering 2 DIV's side by side on Responsive Layout |
Terminator |
May 11 2015, 12:04 AM
Post
#1
|
Advanced Member Group: Members Posts: 218 Joined: 19-March 15 Member No.: 22,398 |
I have 2 div's with text in them, I am trying to get the div's centered side by side on a Responsive Layout but cant figure it out.
Here is what my CSS is for the 2 div's: div.blk1 { float: left; margin: 15px; } I did float: left in order for them to be side by side, otherwise they are on top of each other. I was thinking maybe wrap these 2 div's in a container and center the container, but cant use text-align because then it centers the text within the 2 div's. thanks. |
Frederiek |
May 11 2015, 04:03 AM
Post
#2
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
You also need to give the DIVs a width.
To center the container, give that a width too and use margin: 0 auto;. |
pandy |
May 11 2015, 05:18 AM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
Also see CSS: centering things .
|
amitwadhwa |
May 11 2015, 09:05 AM
Post
#4
|
Newbie Group: Members Posts: 14 Joined: 15-November 12 From: Dublin Member No.: 18,106 |
I would do it this way - http://jsfiddle.net/11dbft28/
|
Terminator |
May 11 2015, 10:30 AM
Post
#5
|
Advanced Member Group: Members Posts: 218 Joined: 19-March 15 Member No.: 22,398 |
Thanks for the code. I needed them centered side by side though, blk1 on the left and blk2 on right, then on mobile view they will move on top of each other. I guess I cant use float: left; with the way you coded it can I? |
Frederiek |
May 11 2015, 11:21 AM
Post
#6
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
Open the result page in a new browser window or tab and you'll see they are side by side. Though they slightly seem to overlap.
But you can use float too. Use that instead of the display: inline-block;. Then, in the media-query, add a float: none;. Be sure to clear the float too after these DIVs, or use Nicolas Gallagher's micro clearfix, see http://nicolasgallagher.com/micro-clearfix-hack/ . |
Terminator |
May 11 2015, 03:14 PM
Post
#7
|
Advanced Member Group: Members Posts: 218 Joined: 19-March 15 Member No.: 22,398 |
Thanks, I got it to work just the way I wanted.
|
Frederiek |
May 12 2015, 03:18 AM
Post
#8
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
Good. You're welcome.
|
Lo-Fi Version | Time is now: 25th April 2024 - 01:14 PM |