Establishing a pixel width for a cell within a table

I've encountered an issue where setting a width to a div with the display: table-cell property is not working as expected.

Here is my code:

<header class="header layers">
        <div class="wrap">
            <h1 id="title"><?php echo $blogtitle;?></h1>
        </div>
</header>

And here is the CSS I used:

.layers {
  position: absolute;
  display: table;
  top: 0;
  left: 0;
  overflow: hidden;
  box-sizing: border-box;
  table-layout: fixed;
}

.wrap {
  height: 100%;
  margin-right: auto;
  margin-left: auto;
  overflow: hidden;
  display: table-cell;
  vertical-align: middle;
  width: 1040px;
}

.header {
  height: 80px;
  width: 100%;
}

#title {
  font-size: 30px;
  color: black;
  font-family: 'Roboto', sans-serif;
}

I have used this approach successfully before, but for some reason it's not working this time. When inspecting the element, the width of the wrap class is being set to 100% without any errors showing up.

If anyone has any insights or suggestions, please do share. Your help is much appreciated.

You can also view the fiddle link here.

Answer №1

To address the query mentioned in the comments, I have provided an illustration showcasing the utilization of display: flex (flexbox) for vertically aligning text (which was attempted previously with display: table-cell). Additionally, it is feasible to define the width and height of a flexbox effortlessly, akin to a traditional block element.

The implementation of the display:flex feature effectively centers the text vertically, while also allowing for setting a precise width of 1040px.

* {
  box-sizing: border-box;
}
html, body {
  height: 100%;
  padding: 0;
  margin: 0;
}
div#container {
  display: flex;
  align-items: center;
  height: 100%;
  width: 1040px;
}
div#centered {
  height: 20px;
  width: 100%;
  text-align: center;
}
<div id="container">
  <div id="centered">Vertically-centered using <code>display: flex</code>.</div>
</div>

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

I am looking for assistance constructing a task management application using vue.js

I am facing an issue with developing a to-do list using Vue.js. The goal is to add tasks to the list by entering them and clicking a button. Once added, the new task should show up under "All Tasks" and "Not finished". Buttons for marking tasks as " ...

Issue with JavaScript Variable Not Reflecting Changes in Progress Bar

I'm in the midst of developing a game and have incorporated a progress bar to facilitate the incrementation of certain values on my HTML page. However, once the progress bar hits 100%, it updates the cost and level only once. After that initial update ...

Verify if the value of localStorage matches the specified value, then conceal the element

This is my second query and I'm hoping it covers everything. My knowledge of javascript is limited, which has made it difficult for me to get my code working properly. Despite trying various different approaches, I have been unable to resolve the issu ...

"Enhance your code editing experience in Eclipse with HTML, CSS, and JavaScript syntax

Hi there! I'm looking for a way to enable syntax highlighting for HTML/CSS/JS in Eclipse. My main focus is on developing in Python using the PyDev package, but currently I am working on creating Cheetah templates which are difficult to read without pr ...

Tips for creating horizontal dividers with CSS in Vuetify using <v-divider> and <v-divider/> styling

Currently, I am working on a project using Vue.js and adding Vuetify. However, I need to use a component. .horizontal{ border-color: #F4F4F4 !important; border-width: 2px ; } <v-divider horizontal class=" horizontal ...

IE10 has a problem with the height being set to 100%, but it seems to work fine in Quirks mode in IE and all

Check out this page for reference: I've noticed an issue with scrolling in Internet Explorer, while other browsers seem to be fine. Can you help me understand why IE is causing the scroll and how I can fix it? Thank you, Judson Here's the cod ...

What advantages and disadvantages come with choosing between using vh and vw for responsive text?

My main inquiry is centered around the various techniques for creating responsive text. Is there a particular method that stands out as the best option for general use, or do different methods serve distinct purposes? ...

Is it necessary for block-level elements in HTML to always contain <a> tags within them?

When working with HTML, there is often a debate on whether block-level elements should always enclose <a> tags. What if it's necessary for the <a> tag to wrap around the block-level element in order to ensure that the correct styles are ap ...

Is there a way to verify the file extension in a multi-input form during an upload process?

I am looking for a solution that requests users to upload 4 different files when filling out the form. Check out this example of one of the inputs: <div class="custom-file"> <input type="file" class="custom-file-input" accept="video/*" id="v ...

Setting the button name using setAttribute("name", "Button Name") is currently not possible

I have been working on adding a button to my webpage, but so far I haven't had much success. Every attempt either results in an error or the button not displaying any text (refer to the screenshot below). There should be a button labeled "BUTTON NAME" ...

Content is not centered with Bootstrap's flexbox

The alignment of content is not centered using bootstrap flex <div class="d-flex flex-row bd-highlight mb-3"> <div class="p-2 bd-highlight text-left"><i class="fa fa-chevron-left" aria-hidden="true"></i></div> <div cla ...

Avoiding the use of mailto links in PHP

One problem I encountered is with a mailto link in my PHP code: <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f5a525e56537f5b50525e5651114b535b">[email protected]</a>?subject=<?php rawurlencode ...

How can you refresh the .replaceWith method in jQuery?

Is there a way to reset the .replaceWith function so that the html, css and javascript elements are restored to their original state? I am looking to have an icon replace the text when the user clicks on "contact", and then have the text return when the u ...

Generate a chart using the REST object by organizing the information in a column format

I am currently working with a REST service that returns a specific object with multiple values and IDs. Here is an example of the object: [ { "id": 100, "value": "2452" }, { "id": 100, "value": "2458" }, { "id": 1, "value ...

Finding and Selecting Dynamic CSS Elements with CSS Selector Techniques

Utilizing a tool called Stonly for adding tooltips, the CSS Selector is used to locate the HTML element for identifying the tooltip. Depending on the user input, a dynamic task list is generated. The challenge arises when trying to pinpoint a specific task ...

What are the recommended practices for server-side Java when compiling CSS to SWF?

Users of my project have the ability to design custom CSS for our flexible application. When it comes to converting the CSS into SWFs on the server side: Is it recommended to utilize the flex2.compiler.css.Compiler class in mxmlc-3.5.0.12683.jar? Altern ...

Is the meta viewport exclusively meant for mobile phones?

Is it possible to configure the general responsive meta viewport setting specifically for phones? Our website appears fine on 7" and larger tablets in both portrait and landscape modes without the meta tag, but it is a bit inconvenient on smaller devices. ...

PDFMAKE: A Guide to Duplicating Elements in the 'Content' Array

I have an Array within Items. My goal is to display them in a Table format using PDFMake. table: { multiple pages headerRows: 2, widths: ['auto', 100, 200, 'auto', 'auto', 'auto'], body: [ ...

ASP Table extends into adjacent column

Having some trouble with the table layout here. In the screenshot, you'll notice a grid view within another gridview. There are currently 3 grid views - the main one and one in each table. I'm looking to move the description to the Price 2 column ...

Tips for keeping the hover effect of a sibling element in Material-UI

Card Component import image from "../../Assets/pic.jpg"; import React, { useState } from "react"; import { makeStyles } from "@material-ui/core/styles"; import Card from "@material-ui/core/Card"; import CardActionAre ...