Ways to vertically align h1 and span elements within a list item

I've been searching for a solution to this issue, but have not been successful yet.

My goal is to vertically center the h1 and span elements within the description_content list item.

However, there's a complication. The span element only appears if the Phone variable is not empty. So I need to find a way to vertically center both Seller and Phone together, or just Seller alone if no Phone is present:

<li id="description_content">
     <h1>Seller</h1>
     <br>  <br>
     <span>Phone: </span> <br>
</li> 

Below is my current CSS:

#description_content{
    height:163px !important;
    font-size:16px;
    }

#description_content h1{
    font-size:16px;
    font-weight:normal;
    padding:14px 10px 20px 7px;
}

#description_content span{
    padding:0 10px 0 7px;
    float:left;
    font-weight:normal !important;
}

I have tried various methods, including using the code below, which centers the content but affects the subsequent list items as well:

display:table-cell!important;
vertical-align:middle!important;

Here is a link to a fiddle demonstrating the issue: http://jsfiddle.net/pazzesco/vykqv19j/

Any suggestions on how I can achieve the desired vertical alignment?

Answer №1

From the feedback, it seems you are aiming to avoid having all your li elements on one line.

To achieve this layout, consider structuring your code as shown below:

<li class="description_content">
    <div class="li-wrapper">
        <h1>Seller</h1>
        <span>Phone: </span>
    </div>
</li>

To then style your li elements as a table and vertically align the li-wrapper content in the middle, use the following CSS:

.description_content{
  display: table;
  width: 100%;
  height:163px !important;
  font-size:16px;
}

.description_content .li-wrapper {
  display: table-cell;
  vertical-align: middle;
}

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

Inaccurate sizing of popup dialogs on SharePoint 2010

Currently, I am in the process of revamping a SharePoint 2007 web application to SharePoint 2010. I was surprised to find that the popup dialog boxes for new items, edit, etc. have inline styles for fixed width and height. Below is an example where div.ms ...

Bootstrap 3 Dropdown Menu Not Displaying Items

I am currently facing an issue with the dropdown element in Bootstrap 3 as it is not displaying any elements. This problem arises due to a conflict in the CSS of the "wrapper" element. #wrapper { width:100%; height:100%; position:absolute; top:0; left:0; ...

Creating a FusionCharts time series with a sleek transparent background

Currently, I am attempting to achieve a transparent background for a time-series chart created with FusionCharts. Despite trying the standard attributes that usually work on other chart types and even hardcoding a background color, none of these seem to af ...

Issue with pop-up functionality on web page using HTML, CSS, and JavaScript

Recently, I created a unique popup using HTML. You can see the complete code (excluding CSS) here: https://codepen.io/nope99675/pen/BawrdBX. Below is the snippet of the HTML: <!DOCTYPE html> <html> <head> <meta charset=&quo ...

Mastering the use of divs in CSS-3

Is there a way to position div elements on a webpage in various locations? Which CSS property is most effective for managing this issue? I'm having trouble setting the positions of multiple divs at different points on a page. ...

Tips for Achieving a Smooth Transition Effect with jQuery while Modifying an Image's Attribute

I am facing an issue with the code I have written to change the image source on mouse hover. While it does change the image src, the effect is quite jerky and abrupt. Is there a way to slow down the animation effect? <script> $(document).re ...

Having trouble with Bootstrap 4 maintaining consistent width when affixing the sidebar

Hello there, I'm currently working with Bootstrap 4 and trying to implement affix on the sidebar. I have set up three columns for the sidebar and made them fixed under certain conditions. However, I am facing an issue where the width of the sidebar ch ...

Guide on aligning two boxes in the center with HTML, CSS, and Bootstrap

Is there a way to perfectly center two buttons or clickable boxes, creating a layout similar to the image shown below? https://i.sstatic.net/Va1z2.png This is what has been attempted so far: CSS file .container_1 .panel_1 { position: absolute; ...

No visible changes resulting from the CSS file

My project includes a CSS file named default.css, but it doesn't seem to be working or making any changes to my page This is the content of default.css: .feedbackText{ display: none; text-align: center; margin-left: 50px; color: blue; } In the HTML ...

Utilize CSS to freeze a variety of elements

I have three different elements positioned at the top of my webpage that I want to make responsive. Here is the code I am currently using: #prayer_time .page-header { position: fixed; top: 40px; left: 290px; right: 0; z-index: 99; } ...

Is there a way to set all offset sides in CSS simultaneously?

Is it possible to use the following syntax instead of setting each direction separately? sides:0px; ...

What is the best way to position a text input field at the top?

As a beginner in Html and Css, I am exploring how to position the text "Your Comment" at the top of an input field. https://prnt.sc/1k74619 <div class="comment"> <input placeholder="Your Comment" type="text&qu ...

Connecting CSS and JS files in JSP was a bit of a challenge

Just starting out with jsp and using Glassfish server via netbeans. Struggling to link my jsp file with css and javascripts. Below is the structure of my files: Web Pages --Web-Inf --assets --css --style.css --js --jquery.js ...

Attempting to simulate a camera shutter effect using div elements

I've been attempting to create a circular camera shutter, but I'm facing difficulties in making it look accurate. This is the desired outcome: https://i.sstatic.net/oS7gT.jpg The first 'petal' should be positioned lower than the last ...

Can inline styling be overridden with CSS?

<td class="subrubr" nowrap="nowrap" valign="bottom"> <a name=""></a> Some lengthy text to be shown here. </td> This snippet of code is automatically created by a PHP script. However, ...

CSS sticky inner container within a parent div

I am currently facing an issue with my HTML layout where I have a left menu and content in the right section. I want to make the submenu-2 within the left container stick to the top after scrolling down. I tried using position:sticky and top:0px but it doe ...

Angular UI Bootstrap: Enhance Your Sidebar with Sticky Functionality

Looking to implement a sticky sidebar similar to the one showcased on ng-bootstrap? Working with Angular 7.0 and Bootstrap 4.x, I'm eager to replicate the sticky sidebar featured in the components page of AngularUI (link provided above). Despite scou ...

Issue: Invalid element type detected: expected a string (for built-in components) or a class/function

Currently, I am in the process of learning how to make API calls using React Redux. I decided to practice by implementing an example in StackBlitz. However, I encountered an error after selecting a channel and clicking on the 'Top News' button. C ...

iOS reveals often have a foundation modal that appears behind the background

I am currently working on implementing a confirmation modal that pops up when a button is clicked. Although the modal appears, it seems to be positioned behind the background that darkens the rest of the page. Relevant CSS: .reveal-modal-bg { background ...

Steps for positioning a div with list items to match the height of its parent container

I've been grappling with this problem for a long time now. Within the parent div "wrapper," there is a child div called "sidebar-wrapper" that contains an ul with li elements. I'm trying to make the height of "sidebar-wrapper" adjust to match t ...