Align content in the middle of a floated division that has a variable height

How can I vertically center text within floated divs in a slider without setting the height of parent elements?

<div class="floated">
  <div class="table">
    <div class"table-cell">
       <p>text</p>
    </div>
  </div>
</div>

.floated{
  float:left;
}

.table{
  display:table;
  vertical-align:middle;
  height:100%;
}

.table-cell{
   display:table-cell;
}

Please note that I am unable to set the height of any parent elements.

Answer №1

.aligned { vertical-align:middle; }
.table { display:table; height:100%; }
.table-cell { display:table-cell; }
<div class="aligned">
  <div class="table">
     <div class="table-cell">
         <p>text</p>
     </div>
 </div>
</div>

vertical-align property is placed on table-cell element, not the table itself

Answer №2

There was an error in your code, you forgot to include the "=" sign in this line: <div class"table-cell">

Answer №3

You have a small mistake in your div and consider adding some margin to improve the display of your table

 <div class="floated">
      <div class="table">
         <div class="table-cell">
             <p>text</p>
         </div>
     </div>
    </div>

    .floated{
      float:left;
    }

    .table{
      display:table;
      vertical-align:middle;
      height:100%;
      margin: 0 auto;
    }

    .table-cell{
       display:table-cell;
    }

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

Exploring the ins and outs of utilizing pseudo selectors with material-ui

I've been attempting to accomplish a simple task. I wanted to toggle the visibility of my <TreeMenu/> component in material UI v1 using pseudo selectors, but for some reason it's not working. Here is the code: CSS: root: { ba ...

Show a row of pictures with overflow capabilities

I am looking to develop my own image viewer that surpasses the capabilities of Windows. My goal is to design an HTML page featuring all my images laid out horizontally to maximize screen space. I also want the images to adjust in size and alignment as I z ...

Step-by-step guide to forming a rotating half-circle encompassing text

I have a unique shape in the center of my webpage that I want to rotate 360 degrees. Currently, I can adjust the width to make part of it spin, but I'm looking for a way to achieve a full rotation. Ideally, I would like to accomplish this using only C ...

A collection of items displayed in an unordered format across two columns

I need help creating a list that displays in two columns. One column for odd numbers, the other for even numbers. Here's an example of what I'm trying to achieve: +----------------------------------------------------+ | col- ...

What is the best way to activate a button based on the presence of a cookie?

As I develop my web application, I am faced with the challenge of catering to both guests and registered users. I want to provide a 'Log out' button exclusively for registered users after they have logged in. One solution I am considering is to d ...

Ways to increase the spacing between several menus

Need help with spacing between menus Tried using margin left and margin right but it's not working File: _Layout.cshtml <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport&quo ...

Navigating tables with Selenium WebDriver

I am struggling to locate and interact with a specific element in a table using Selenium WebDriver. The issue is that the table IDs are constantly changing, making it difficult for me to click on the desired element. For instance, consider the following t ...

Is it possible to manage HTML checkboxes without using javascript?

Can dynamically created checkboxes in HTML be managed without the use of Javascript? PHP is responsible for displaying these checkboxes and my knowledge of Javascript is limited. Are there any basic functions that can identify if a user has clicked on a s ...

Unable to Trigger Click Event on Div Element in Angular 9

Take a look at my HTML code snippet <mat-grid-list cols="3" rowHeight="150px"> <mat-grid-tile *ngFor="let tile of tiles;index as j;" [colspan]="tile.cols" [rowspan]="tile.rows" ...

Examine the spans and delete the first-child node

Basically, this functionality allows the user to cycle through hidden information by clicking on it. Here is how you can structure your HTML: <div id="facts"> <span>click to cycle</span> <span>fact 1</span> <s ...

Access rights for subdirectories in HTML

My website is up and running with separate folders for ico, img, css, and js within the html directory. However, I've noticed that when a user navigates to mydomain.com/img, they are able to see a list of all the images in that folder. This doesn&apos ...

Display only the spans that contain text or are not empty

I need a solution to hide only those spans that are empty. <div class="img-wrapper"> <div class="showcase-caption" style="display: block; "> <span id="MainContent_ImageCaption_0">This one has caption</span> </div> ...

Implement HTML code within WordPress labels

Seeking assistance with customizing certain menu items in a WordPress website. Wondering if it's feasible to include HTML/CSS in the title label? My current situation is as follows: I only want one result to be highlighted in blue. I attempted to ...

What causes the footer element to shift outside of the paragraph tag?

When viewing this FIDDLE, you may notice that the <footer> tag appears outside of the <p> tag despite being placed inside it in the HTML. What could be causing this unexpected behavior? HTML Code: <p>Lorem ipsum dolor sit amet, consect ...

Conceal the vacant area located at the top of the page

By clicking on the "Run code Snippet" button or visiting this link, you may notice a significant amount of empty space at the beginning of the page. The images only become visible once you start scrolling down. I am looking for a solution to hide this emp ...

Ways to repair the mat-tab header

Within my application, I have five mat-tabs each containing a large amount of data which requires scrolling. Is there a way to fix the header of the tab while allowing the content to scroll? I attempted adding position:fixed; and position:sticky within: ...

The navigation bar vanishes from sight while scrolling underneath other sections

UPDATE: Problem solved! I discovered that the 'overflow:hidden' inside the #main for the media query was causing the navigation to disappear. I have a scroll navigation positioned at the top of my webpage. However, as I scroll down, the navigati ...

Issue with AngularJS: Not able to get second app in template to function properly

I have encountered a puzzling issue with my two nearly identical apps. The first one seems to be running smoothly as expected, while the second one doesn't appear to be executing at all. Here is my code (jsfiddle): <div ng-app="passwdtool" ng-con ...

A guide on extracting data from a Script element in an HTML file and saving it to a CSV file using Python Selenium

Looking for help with optimizing a Python script that extracts data from the Script tag on an HTML web page. The current output saved in a CSV file is not meeting my requirements: (1) the format is incorrect, and (2) there is unnecessary content included. ...

The AngularJS dropdown menu is refusing to expand

https://i.sstatic.net/GYpNe.png I have created a dropdown select menu using AngularJS's ng-options. The selection and submission processes are functioning correctly. However, as shown in the image, the dropdown menu does not collapse as intended; it ...