by default, vertically aligning as an inline-block

I am working on implementing a horizontal social media bar at the bottom of my website. I want all the social media icons to align in a straight line. The parent div contains the social media icon divs and I am trying to center both the parent div and the icons within it.

When using the inline-block tag, the social media icons are aligning vertically in the middle of the parent div. I have also experimented with floating them but haven't been able to achieve the desired center alignment.

Any assistance on this matter would be highly appreciated.

HTML:

<div id="socialcontainer">
    <div class="facebook"><a href="https://facebook.com/"></a></div>
    <div class="twitter"><a href="https://twitter.com/"></a></div>
    <div class="google"><a href="https://google.com/"></a></div>
    <div class="linkedin"><a href="https://linkedin.com/"></a></div>
</div>

CSS:

#socialcontainer {
width: 100%;
margin: 0px auto;
text-align: center;
}


.facebook a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/facebook_dark.png');
}

.facebook a:hover {
background: url('../img/socialicons/facebook_active.png');
}

.twitter a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/twitter_dark.png');
}


.twitter a:hover {
    background: url('../img/socialicons/twitter_active.png');
}

.google a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/google_dark.png');
}    

.google a:hover {
    background: url('../img/socialicons/google_active.png');
}

.linkedin a {
height:64px;
width:64px;
display: inline-block;
background: url('../img/socialicons/in_dark.png');
}

.linkedin a:hover {
    background: url('../img/socialicons/in_active.png');
}

Answer №1

To properly format the links, make sure to apply the inline-block style to the DIV elements containing the anchor tags as shown below:

#socialcontainer > div{ display: inline-block;}

Answer №2

Why not give this a shot: include the CSS rule display:inline on every wrapping <div>.

Answer №3

Feel free to implement this updated CSS code into your HTML:

#socialcontainer {
position: relative;
width: 256px; // 64 * 4
left: 50%;
margin: 0 auto;
margin-left: -128px;
text-align: center;
}

.facebook, .twitter, .google, .linkedin { width: 64px; float: left; }

.facebook a {
height: 64px;
width: 64px;
display: inline-block;
background: url('../img/socialicons/facebook_dark.png');
}

.facebook a:hover {
background: url('../img/socialicons/facebook_active.png');
}

.twitter a {
height: 64px;
width: 64px;
display: inline-block;
background: url('../img/socialicons/twitter_dark.png');
}


.twitter a:hover {
    background: url('../img/socialicons/twitter_active.png');
}

.google a {
height: 64px;
width: 64px;
display: inline-block;
background: url('../img/socialicons/google_dark.png');
}

.google a:hover {
    background: url('../img/socialicons/google_active.png');
}

.linkedin a {
height: 64px;
width: 64px;
display: inline-block;
background: url('../img/socialicons/in_dark.png');
}

.linkedin a:hover {
    background: url('../img/socialicons/in_active.png');
}

Answer №4

If you want to center the inner content horizontally, consider creating a new div within the container to control its position. It's a simple solution which you can view in action on my JS Bin.

Check out the code I suggest for this solution

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

The toast feature in Bootstrap 5 seems to be malfunctioning as it does not display properly despite the absence of any

Why isn't the Toast displaying in the code snippet below? I'm using bootstrap 5. I'm puzzled because there are no errors in the developer's tools. Any assistance would be greatly appreciated. <!DOCTYPE html> <html lang="en"& ...

Using Inline Font CSS for FontAwesome 5 Unicode Compatibility

I am currently utilizing a library that does not support the font-weight property. Instead, the font style is defined by the font CSS property as detailed here. After trying to set the font style using the font CSS property with FontAwesome 5, I noticed t ...

What options exist for dynamically altering HTML/DOM within an iOS app using programming techniques?

I am currently working on processing various RSS feeds that contain summaries and URLs to target pages. I want to find a uniform transformation method for this task. Initially, XSLT seemed like the perfect solution as it can achieve what I need in a stand ...

"Placing drop-down animations in just the right spot

I'm currently working on adjusting the dropdown behavior for thumbnails when hovering over them. I want the drop-down to appear beneath the 'Caption Title' instead of above the image, but so far my CSS adjustments haven't been successfu ...

What is the best way to implement a CSS rule that is influenced by the number of siblings present within an element?

Is there a way to style an element differently based on the number of subelements it contains? <div class="wrapper"> <div class="element" /> </div> or... <div class="wrapper"> <div class="element" /> <div class="el ...

The misaligned navigation bar and distortion on mobile devices are causing issues with the website's layout

The logo, search bar, cart, login, and sign up are not aligned on the same line. When I try to view it on mobile, distortion occurs. The search bar and other elements get messed up. In mobile view, nothing happens when clicking on the menu collapse butt ...

Updating Django database records with ajax

I'm currently working on a feature that involves filtering table data and updating the table using ajax. Here's what I have so far: Filter Form: <form id="search" method="POST" action="{% url 'article-filter' %}"> <input ...

Styling web pages with HTML and CSS directly from a MySQL

I'm facing a challenge in crafting a solution for a intricate issue. My project involves building a website that generates HTML templates containing both CSS and HTML files. Users will have the ability to create multiple templates/sites. In an effort ...

Issue with Swiper JS: The buttons on pages three and beyond are unresponsive

I'm having trouble with the functionality of the "Back" button on pages 2 and 3 of my website. Can anyone help me figure out why it's not working? My goal is to create a website that resembles a game menu, similar to Deus Ex The Fall. I'm u ...

Creating Engaging Web Pages with Dynamic Background Images per Section in WordPress

Currently, I am in the process of designing a webpage that consists of 5 sections, each with a height of 720px. My goal is to assign a unique background image to each section and have the ability to change these images through the WordPress backend. To ac ...

Simple way to extract the values from every input element within a specific <tr> tag using JQuery

Is there a way to align all input elements in a single row within my form? For example, consider the snippet of code provided below, which includes a checkbox and a text input box. I would like to retrieve the values from both of these input types and pres ...

What would be more efficient: inputting all items in a form at once or adding them one by one consecutively

My mind is preoccupied with a dilemma: is it better to have all possible items already on the form, or should items only be added when the user requests them? Let me elaborate - Imagine I have a form with 4 input fields and one textarea. Alongside that, t ...

Tips for customizing the focus border of a TextField input with the Material-UI theme

Struggling to customize the TextField border color and width in my own theme using Material-Ui v.5.4.0. After hours of research, I couldn't find a solution that works. It made me wonder if it's even possible to achieve this customization within t ...

Ensure that dynamically generated fields are verified whenever one of them is modified

I am working on a program that generates text boxes and drop down lists dynamically. I need to find a way to validate these fields only when one of them is changed. The validation should occur if a date is entered in the text box, it should then check if t ...

Replacing strings with file_get_contents in PHP is a common practice for retrieving

Currently, I am working on replacing a specific string within a file and so far everything seems to be going well. The file in question is an htm file formatted in html, but that shouldn't pose any issues. This is what my script looks like: $file = & ...

Sophisticated Sidebar Design using Bootstrap 5

Looking to design a responsive sidebar for navigation on my page, with selected and hover properties. Visualizing the selected option to appear like this: Selected (active) option in sidebar The goal is to have the image cover the left side of the backgr ...

Clicking on the title link will open the content in an iframe, but the image

Having trouble with a previous post but I've created a codepen to illustrate the issue. Hoping someone can help me out! Check out the codepen here: "https://codepen.io/Lossmann/pen/GRrXyQY" ...

When adjusting window size, the input shifts towards the left

Is there a way to prevent my input and login button from moving to the left when resizing the window? I am new to HTML and CSS and would appreciate any tips on keeping them in place. Below is my CSS code: #absolute { position: absolute; top: 411px; le ...

Developing a dynamic row that automatically scrolls horizontally

What is the best method for creating a div box containing content that automatically slides to the next one, as shown by the arrows in the picture? I know I may need jquery for this, but I'm curious if there's an alternative approach. oi62.tinyp ...

What causes the layout of an application to become distorted when I extend the theme in Tailwind.css?

I had the idea of incorporating an animation into my website design using tailwind.css for styling. module.exports = { content: ["./index.html", "./src/**/*.{js,jsx}"], theme: { colors: { primary: "#E51114", ...