How come these social buttons are refusing to align in a responsive layout?

Our website incorporates Twitter, Facebook, and G+ buttons using a responsive design in an ajax portfolio. While the buttons align perfectly with each other, we are facing an issue where we want all three buttons to be centered regardless of the size of the surrounding container.

In theory, this should be achievable by nesting Divs within each other, with the innermost Div containing the buttons floating centrally within a parent Div that spans 100% width. However, despite our attempts, the buttons consistently align to the left side. Below is the current code snippet:

For a live example, visit:

http://themixtapesite.com/#/joe-budden-a-lose-quarter 

To better understand the problem, try resizing your browser window on the example page to see how the social buttons stay aligned to the left instead of being centered as desired.

<!-- Social sharing buttons -->
    <div class="social-single">

    <div class="social-centre">     

    <div class="twit-button"><a href="https://twitter.com/share" class="twitter-share-button" data-via="mixtapes_4_free" data-lang="msa" data-related="realdannys" data-hashtags="mixtape">Tweet</a></div>

    <div class="fb-button"><iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode(get_permalink($post->ID)); ?>&amp;title=<?php wp_title( '|', true, 'right' ); ?>&amp;send=false&amp;layout=button_count&amp;width=71&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21&amp;appId=118471234925480" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width: 71px; height: 21px;" allowTransparency="true"></iframe>
                        </div>

    <div class="gplus-button"><g:plusone href="<?php echo urlencode(get_permalink($post->ID)); ?>" size="medium" annotation="bubble" width="50px"></g:plusone></div>

    </div> </div>

Below is the CSS for styling the social buttons:

/* Social Buttons */

.social-single {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 10px;
width:  100% !important;
}

.social-centre
{
margin-left: auto;
margin-right: auto;
}

.twit-button {
float:  left;
margin: 0;
margin-right: 5px;
width: 80px;
}

.fb-button {
float: left;
margin: 0;
width: 80px;
}

.gplus-button {
float: left;
margin: 0;
width: 50px;
}

Answer №1

Your use of margin-left: auto; and margin-right:auto; is commendable, setting everything up for responsiveness. One crucial aspect browsers consider for each element is its width and height. It's important to define these values separately to avoid unexpected results in the absence of child elements inside.

After reviewing your code, it seems like you only need to add one thing - assign a width to the .social-centre class. It would be beneficial if this width is set in percentages for better responsiveness.

.social-centre
{
margin-left: auto;
margin-right: auto;
width:50%; //example, adjust as needed.
} 

By making this adjustment, your layout should function correctly. I hope this guidance proves helpful to you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What happens when HTML5 Video quality starts to decline?

Exploring the capabilities of the HTML5 video tag has left me pondering the best approach for graceful degradation in cases where a codec is not supported. Handling older browsers (or IE) that lack support for the video tag altogether is quite straightfor ...

Live graph updating with x-axis scrolling in Chart.js version 4

I have a graph created with Chart.js that updates every 500ms by checking for new data from the backend. When new data is found, it is added to the graph. setInterval(function(){ let num = pick_numb() num.then(function(result) { addData(my ...

Unexpected results appear when rendering HTML markup

There are two different ASP.NET Web form pages: Page1: This page is a normal ASP.NET page with no containers or database binding controls. It is rendered as: Content Content Source code (as displayed in browser tool): <p>Content&nbsp;Content& ...

Is there a different option to use instead of embedding two forms?

I'm currently facing an issue and seeking alternatives for it. In my admin panel, customers have the ability to manage buildings by adding, editing, or deleting them. I have a form with fields such as title, address, city, etc., along with a submit ...

JavaScript Sort function malfunctioning and not correctly sorting

I am having trouble sorting div elements by price values. The code seems to be working fine, but the sorting of numbers doesn't appear to be completely accurate. For example, in my jsfiddle, when the button is clicked, the number 21.35 is displayed a ...

The image disappears when I click on a link and then return to the main page, but this only happens in Mozilla Firefox

Upon opening the main page, everything functions flawlessly. However, if I navigate to another page through one of my href links and then return to the main page, my div with the class "bild" disappears. Oddly enough, this issue only occurs in Mozilla Fire ...

Adjusting the Scaling Value to Match the Browser's Scaling Value

I'm struggling with a problem in HTML where the initial-scale function is not working as expected. When I zoom in on certain pages, it saves the zoom level. However, when I navigate to another page and then return to the original one, the zoom level r ...

Creating spacious gaps between list items

I have been working on creating a scrollable horizontal list using iscroll. Although the list functions properly, I am encountering an issue with spacing between each li item. Despite trying various solutions, I have been unable to remove the space betwe ...

I am facing an issue in my Laravel project where certain colors are not displaying correctly or appear to be missing. I am unsure of how to

I am facing an issue in my Laravel project where some colors are not displaying or are missing. I have tried changing the color theme without success. Additionally, the syntax highlighting is not working properly even after trying the Laravel extension. B ...

Spring Boot application on Prime Faces is not displaying CSS after deployment to Heroku

I'm currently using a combination of Spring 3.1.3, Prime Faces 3.4.2, Hibernate 3.6.8, and Pretty Faces 2.0.4. When I deploy my application on a local server (Apache Tomcat 7), the CSS displays properly. However, when I deploy the same project to Her ...

Having trouble integrating RGraph into my HTML page with AJAX

As I work on developing a simple webpage layout with both a static header and footer, I'm encountering some challenges in updating content dynamically. The left side menu triggers an ajax request when clicked, which should update the text on the right ...

Trouble with JavaScript event listener/button functionality

Seeking a simple fix here. While I have experience in Java, I am slowly but surely delving into Javascript. Currently, I am working on creating a fun website. The specific task at hand involves utilizing the parse api. My approach (as there seemed to be ...

The Android XDK Intel Html5 is unable to display images of certain widths when the file path is set to file:///storage/sdcard0

When I tag a link on img src to put the file directly as file:///storage/sdcard0/myimg/test.jpg, the image appears in the Preview but not in the Android Build compilation. <img src="file:///storage/sdcard0/myimg/test.jpg"> It displays correctly in ...

ng-display does not display content when the condition switches to true

I am facing an issue with displaying an image and a YouTube video in my HTML. My goal is to show the image when the video is not playing, and switch to displaying the video when it starts playing. Upon loading the page, only the image is shown, which is ...

Switch between dark and light themes on the Tradingview widget

I have integrated a TradingView widget into my website and I am working on adding a dark/light mode switch to the site. I would like the widget color to change along with the background in the switch. See Widget Screenshot TradingView Widget - Widget sour ...

Customize Bootstrap Navbar to Enable Horizontal Scrolling Specifically for Dropdown Buttons

Specific requirements: - Only buttons should be horizontally scrollable - Dropdown of buttons should appear just below the button without shifting the paragraph below Things I have attempted: - Tried using overflow:hidden/auto, overflow-x:auto, and pos ...

Header Blocks that are Fixed While Scrolling in fullPage.js Sections Using the "scrollOverflow: true" Feature

I am experiencing an issue where a fixed header on my website prevents scrolling through sections when hovering, specifically when the setting scrollOverflow: true is enabled. However, everything works fine and scrolling through all sections is possible w ...

Adjusting Flexbox Sidebar to Match Content Height

I'm facing an issue with my layout where the sidebar sometimes becomes taller than the page body, extending beyond the screen height and continuing to expand vertically. Here's a snippet of my code structure: <div class="fb-col"> < ...

Utilize local storage to dynamically update the background color of a div section

Struggling to create a functionality on my website where users can input a color, save it to localStorage, and have a specific div's background set to that color across all pages. The main content div (with the same ID) needs to display this color con ...

Customize Color of Bootstrap Tooltips

Is there a way to customize the appearance of BootStrap tooltips by changing the color and aligning the text to the left? I've tried various CSS modifications from different posts, but none seem to work. Any idea on how to alter the CSS of the tooltip ...