How to center an image and text vertically within a div

Struggling to vertically align an image and text in a parent div? Check out my code snippet below:

Here's the link to my Fiddle:

jsfiddle

HTML Code Snippet:

<div class="social-cont">
    <div class="social-cont1">
        <img src="img/contact1.png" alt="contact1" width="21" height="30" />
    </div> <!-- end social-cont1 -->
    <div class="social-cont2">
        <h6 class="social-context">Pastoor de Leijerstraat 29, 5246JA, Hintham</h6>
    </div> <!-- end social-cont1 -->

</div> <!-- end social-cont -->

<div class="social-cont">
    <div class="social-cont1">
        <img src="img/contact3.png" alt="contact3" width="23" height="24" />
    </div> <!-- end social-cont1 -->
    <div class="social-cont2">
        <h6 class="social-context">XXXXXXXXXXXXXX</h6>
    </div> <!-- end social-cont1 -->
</div> <!-- end social-cont -->

CSS Styling:

.social-cont {
    height: 100%;
    width: 350px;
    border-bottom: 1px solid #c1c1c1;
    display: table;
    background-color: salmon;
}

.social-cont1 img {
    display: table-cell;
    vertical-align: middle;
    float: left;
}

h6.social-context {
    display: table-cell;
    vertical-align: middle;
    color: #404040;
    float: left;
}

When previewing the code in Coda, this is the result:

Answer №1

Avoid using float: left, and consider removing .social-cont1 and .social-cont2. Instead, you can apply styles directly to img and h6.

.social-cont1 {
    display: table-cell;
    vertical-align: middle;
}

.social-cont2 {
    display: table-cell;
    vertical-align: middle;
    color: #404040;
}

Check out the code snippet here.

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

Easy Steps to Build a Line Item Grid using AngularJS

I have a visual display that was initially designed using React to manage line items. Now, I am in need of recreating the same functionality utilizing AngularJS and HTML. Any assistance with implementing this with AngularJS would be greatly appreciated. T ...

Tips for showcasing devnagri script from user input on a php webpage

On one of my PHP pages, I have changed the font for input to Devnagri. Now, I need to display it on the next PHP page and also insert it into MySQL. The first page, index.php, contains the following details... <table width="535" height="54" border=" ...

Issue with background-image resizing and not spanning full width

I am in the process of creating my very first website, which will serve as a portfolio. I have designed three different background images for each section that alternate (home, about, skills, etc.). Utilizing SASS with SCSS syntax, I have encountered an is ...

Struggling to retrieve an integer value from user input?

Hey there! I am facing an issue where I receive data from a form via POST, and some fields need to be treated as integers. However, when I use: var_dump($_POST) All the data is returned as strings enclosed in double quotes, which I would like to remove. ...

Ways to display page number in the header of a printed webpage

Hello everyone! This is my first time seeking help here, so I would appreciate any assistance in better understanding. I am currently working on a project that involves creating computerized contracts for banks using HTML, which will then be converted int ...

JavaScript JQuery alert popup fails to display

I have been attempting to create an alert pop-up using JQuery that will display when a user clicks on submit without filling out the form. However, when I test my code by leaving the form empty and clicking 'submit', the page just refreshes with ...

Problem with JQuery Themes

Currently, I am having an issue installing a UI theme as the images are not displaying properly. The image folder is located at the same level of the .css file. Below is the code snippet that I am using: $(document).ready(function () { $("#datepicke ...

Elegant bespoke input box

I am looking to create a customized input text feature similar to StackOverflow's tag editor, but with some minor differences. The goal is for the input field to function like a regular text input until a word is enclosed in curly brackets. Once enclo ...

What is the best way to position the sign-in modal form on the top right corner of my website?

Hey there, I'm facing a bit of an issue and can't seem to figure out what went wrong. Recently, I inserted a Bootstrap Sign In modal in my HTML file. Here's the code: <div class="text-center"> <a href="" class ...

The automatic width feature in Firefox is malfunctioning and not behaving as expected

Here is my question: I have an image wrapped in a div (.indexWrap): <div id = "slider"> <div class="indexWrap"> <img class="indexImage" src=""> </div> ...

Alignment of Bootstrap thumbnails in a horizontal layout

After adding the thumbnail class to my thumbnails div, I noticed that some of the thumbnails were smaller in size than others. Wanting them all to have the same height, I decided to give each thumbnail a fixed height of 210px. However, this caused the sm ...

jQuery "ooze navigation" - precise pixel rounding

After successfully programming my jQuery slime menu, I am facing a minor issue. Although the menu works beautifully, I have noticed that when I move the arrow and the ending circle of the slime separately, they do not always connect accurately if the curso ...

Incorrect behavior of responsive background images

For the first time, I am working on a school project that requires me to create a responsive website. I am following the "mobile first" approach. On stackoverflow, I came across a helpful way of making background images responsive: background-image: url(. ...

How can a JS script determine the shape of a quadrilateral based on its properties?

Hi there! I'm new to coding and could use some guidance. I've been given a task to create a script that takes input for the length of each side and the angles of each corner in order to determine whether the shape is a square, rectangle, rhombus ...

Issue Setting Cookies on "localhost" versus "127.0.0.1" Domain - Cookies Disappear Upon Refresh

Encountering difficulties while attempting to set cookies with the domain specified as localhost. Here is what's happening: Upon setting the cookie with localhost as the domain, an error is triggered indicating that the domain attribute is not valid ...

Encountering a problem where Visual Studio 2008 IDE freezes or crashes when attempting to open a .aspx file that contains

While using Visual Studio (SP1), everything works perfectly until I attempt to view .aspx source files containing the lines <style type="text/css> </stlye> Once those lines are present, it freezes and becomes unresponsive, forcing me ...

Is there a way to position my image and text side by side?

My current objective revolves around implementing a specific design, as illustrated in this image. The issue I'm encountering in my code pertains to the utilization of the bootstrap grid system for ease of layout. However, when I incorporate both tex ...

The <hr> element creating a line beneath a connected div

Currently, I am in the process of designing a website with three main divs all on one page. To visually separate these divs, I have included a subtle horizontal line. The horizontal line between the first and second div looks correct as intended. However ...

Utilizing Java to extract dynamically generated content from an HTML page

I have an HTML page that looks like this: <html> <head> <!-- necessary java scripts --> </head> <body> <div id="content"></div> </body> After the page renders, a lot of dynamic html content is placed within ...

Verification of user input upon clicking the submit button within a form

I am encountering an issue with validating my form, as no errors are displayed in the console. I have followed the instructions provided by Bootstrap documentation but to no avail. My aim is to implement a feature where clicking on the button triggers an a ...