Center text vertically within a div using CSS

I need assistance with aligning my text vertically centered and left aligned to the logo in my HTML & CSS code. How can I achieve this with the code provided?

Link to Fiddle: http://jsfiddle.net/z6yet59f/

.slogan {
    background:#eaeaea;
    float:left;
    width:600px
}

.slogan img {
    cursor: pointer;
    width:92px;
    height:92px
}

.slogan div {
    float:left;
    margin-left: 35px;
}

.slogan div span {
    display:block
}
<div class="slogan">
    <div>
            <p>
                <span>Text here</span>
                <img src="https://cdn3.iconfinder.com/data/icons/rcons-social/32/blog_blogger_google-128.png" id="chat_link_35" title="click to start live chat ..">
            </p>
    </div>

    <div>
        <span class="heading">National Helpline</span>
        <span>Hello</span>
    </div>

    <div>
        <span class="heading" style="color:orange">National Helpline</span>
        <span>Hello</span>
    </div>
    
</div>

Answer №1

Here is the revised code to hopefully solve your problem:

.slogan {
    background:#eaeaea;
    float:left;
    width:600px
}

.slogan img {
    cursor: pointer;
    width:92px;
    height:92px;
     vertical-align: middle;
}

.slogan div {
    display:table-cell;
    vertical-align:middle;
    margin-left: 35px;
}
.slogan div p{display:block;}
   .slogan div p span{
    display:inline-block;
    vertical-align:middle;
}

.slogan div span {
    display:block
}
<div class="slogan">
    <div>
            <p>
                <span>Text goes here</span>
                <img src="https://cdn3.iconfinder.com/data/icons/rcons-social/32/blog_blogger_google-128.png" id="chat_link_35" title="click to start live chat ..">
            </p>
    </div>

    <div>
        <span class="heading">National Helpline</span>
        <span>Hello</span>
    </div>

    <div>
        <span class="heading" style="color:orange">National Helpline</span>
        <span>Hello</span>
    </div>
    
</div>

Answer №2

Simply include the .valign-middle class in your code

CSS

.valign-middle {
    -webkit-display: flex;
    display: flex;
    -webkit-flex-flow: row wrap;
    flex-flow: row wrap;
    -webkit-align-items: center;
    align-items: center;
}

HTML

<div class="slogan valign-middle">
    <div>
        <p> <span>Your text here</span>

            <img src="https://cdn3.iconfinder.com/data/icons/rcons-social/32/blog_blogger_google-128.png" id="chat_link_35" title="click to start live chat ..">
        </p>
    </div>
    <div> <span class="heading">National Helpline</span>
 <span>Hi</span>

    </div>
    <div> <span class="heading" style="color:orange">National Helpline</span>
 <span>Hi</span>

    </div>
</div>

CHECK OUT THE DEMO

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

Tips for creating a stylish scrollbar in a React Material-Table interface

Currently, I am utilizing the react material-table and looking to implement a more visually appealing scroll-bar instead of the default Pagination option. Although I have experimented with the react-custom-scroll package, it has not produced the desired ...

Linking Two HTML Components in Angular 4 with Identical Values

Recently, I've started working with Angular and encountered an issue. In a table row, the value item.md_id is bound like this: <tr *ngFor="let item of driverData"> <td class="align-right" id="md_id" [(ngModel)]="item.md_id" name="driverId ...

Enhance user experience by implementing an autocomplete feature for a text input field

Can you name the process in which a form is automatically filled using database information without needing to refresh the page? One common example of this technique is seen on platforms like Google or Facebook, where they predict friends you may be searc ...

Blurring a section of a circular image using a combination of CSS and JavaScript

I'm trying to achieve a specific effect with my circular image and overlaying div. I want the overlaying div to only partially shade out the image based on a certain degree value. For example, if I specify 100 degrees, I only want 260 degrees of the c ...

A crisscrossing dashed design running along the edges of the text block

<div class="search"> <p>SEARCH</p> </div> https://i.sstatic.net/yxOga.png I am attempting to incorporate a dashed lateral padding similar to the one shown in the image, but only on the sides of the text. Is there a method I can ...

Did the menu get shifted downwards on the mobile version by using bootstrap?

Here is the desktop version of a navigation bar. https://i.sstatic.net/e595L.png This image shows the mobile version after clicking on the hamburger button. https://i.sstatic.net/ng1tK.png I would like the menu to open when I click on the hamburger, bu ...

Superimpose one element on top of another

My current page layout includes the following code: <div class="card"> <div class="card-block"> <h4 class="card-title text-muted">UltimateWarrior15</h4> <h6 class="card-subtitle text-muted"> Ad ...

Iterate over the HTML elements within a class and retrieve a specific property in JSON

Currently, I am in the process of developing a straightforward application that involves making an Ajax request to retrieve a Json object and then passing it to an HTML document. Essentially, this application functions as a vending machine where the produc ...

Experiencing issues with retrieving information from the database

I have a form and query set up to retrieve information from a database. The issue I'm encountering is that it works perfectly when the studentcode is a number, but fails when it's a letter. I'm unsure of what might be causing this problem. A ...

The jQuery scroll function is not working for the span class I specified. What could be causing this issue?

I attempted to implement a scroll-to plugin to move between elements on a page when clicking previous and next buttons. The source demo works differently from my modified version, and I am struggling to figure out where I went wrong. Source demo: My Curr ...

Changing textarea html content to an iframe in real time with the use of jQuery

Is it possible to use jQuery to transfer HTML content entered into a textarea to an iframe in real time, without refreshing the page? I have searched for a solution but have not found a clear direction. Any code snippet and explanation would be greatly ap ...

Triggering div visibility based on jQuery select change event

I am currently working on a form feature that involves showing a div when a specific option in a select element is chosen, and hiding the div when the option is not selected. Here is the current structure of my markup: Here is the current HTML markup I ha ...

What is the most effective way to implement a single modal throughout my web application without having to duplicate HTML code on each page?

After realizing I was repetitively adding the same div to every page for a modal dialog, I decided to place a single div in the site.master page and call it when needed. This method worked fine until I began implementing ajax with partial page updates. H ...

Obtaining data with jQuery.Ajax technology

I am attempting to retrieve real-time data from a different URL and display it in a text field every second without refreshing the entire page. The content of the URL is constantly changing, so I want the field to update accordingly. However, despite my ef ...

Display a list in thumbnail format on Wordpress

On my website, , the homepage thumbnail post does not display the text in a bulleted list like it does when I enter the post directly at . Can you explain why this is happening? I want to note that the theme admin supports Custom CSS which allows me to ad ...

Creating a persistent footer in a modal: A step-by-step guide

I'm currently working on a react-modal that slides in from the bottom of the screen with an animated effect. The challenge I am facing is getting the footer of the modal to stay fixed at the bottom of the browser window. Despite using the standard CSS ...

Using JQuery with the latest version of Google Sites is a game-ch

My coding knowledge is very limited, especially beyond VBA. I've hit a roadblock and it seems like I'm overlooking something obvious. What I'm attempting to accomplish: I need this code to be integrated into a New Google Sites page (which h ...

Turn off automatic resizing of iframes

I'm currently dealing with a webpage that contains an iframe. The iframe contains quite a bit of data, and every time it loads, its height adjusts to match the content within. Unfortunately, this is causing my page layout to be disrupted. Is there a w ...

Can we utilize conditions to both select and deselect items using JavaScript and PHP together?

I have a selection list with checkboxes that is dynamically generated based on certain conditions in the code snippet below. if ($data_inteiro_01 <= $data_inteiro_02) { if ($parcela[$i] === 0) { $display = 'disabled'; } } els ...

What is the best way to verify a v-if condition with an array in Vue.js HTML?

I am looking to dynamically add rows based on multiple options selected from a dropdown menu. When I select one option at a time, I am able to get the desired result. However, when I select multiple options, no rows are added. For example, if I select opt ...