Ways to align text in a table row in a way that it remains positioned at the center of the screen's visible area

Can anyone assist me with this task? I need help centering text within a table row ('Some text here...') so that it always appears in the middle of the screen. The table will have horizontal scrolling.

.compare-content {
  max-width: 480px;
  overflow-x: auto;
}
.compare-content table {
  width: 100%;
  text-align: center;
  font-size: 12px;
}
.compare-content table caption {
  font-size: 14px;
  line-height: 39px;
  border-top: 1px solid #CECECE;
  border-bottom: 1px solid #CECECE;
}
.compare-content table tr {
  line-height: 25px;
}
.compare-content table td {
  padding: 0 10px;
  min-width: 145px;
}
.compare-content tr:nth-child(odd) {
  background-color: #F4F4F4;
  color: #898989;
}
<div class="compare-content">
  <table class="total">
    <caption>Summary</caption>
    <tr>
      <td colspan="100%">Some text here...</td>
    </tr>
    <tr>
      <td></td>
      <td>text1</td>
      <td>text2</td>
      <td>text3</td>
    </tr>
    <tr>
      <td colspan="100%">Some text here...</td>
    </tr>
    <tr>
      <td></td>
      <td>text4</td>
      <td>text5</td>
      <td>text6</td>
    </tr>
    <tr>
      <td colspan="100%">Some text here...</td>
    </tr>
    <tr>
      <td></td>
      <td>text7</td>
      <td>text8</td>
      <td>text9</td>
    </tr>
    <tr>
      <td colspan="100%">Some text here...</td>
    </tr>
    <tr>
      <td></td>
      <td>text10</td>
      <td>text11</td>
      <td>text12</td>
    </tr>
  </table>
  <div>

Answer №1

Let me provide you with an example, I have prepared a fiddle for you - https://jsfiddle.net/skyr9999/vuxzfvnu/

It works well if there is no vertical scrolling in your table. Here is the CSS and HTML code:

.compare-content {
  max-width: 480px;
  overflow-x: auto;
}
.compare-content table {
  width: 100%;
  text-align: center;
  font-size: 12px;
}
.compare-content table caption {
  font-size: 14px;
  line-height: 39px;
  border-top: 1px solid #CECECE;
  border-bottom: 1px solid #CECECE;
}
.compare-content table tr {
  line-height: 25px;
}
.compare-content table td {
  padding: 0 10px;
  min-width: 145px;
}
.compare-content tr:nth-child(odd) {
  background-color: #F4F4F4;
  color: #898989;
}

.total tr td
{
  border : 0px #000 solid;
}

.fix {
  position: absolute;
  width: 455px;
  left: 10px;
  border : 0px #000 solid;
}
<div class="compare-content">
  <table class="total">
    <caption>Summary</caption>
    <tr>
      <td colspan="100%">&nbsp;</td>
      <td colspan="100%" class="fix">Some text here.. 1.</td>
    </tr>
    <tr>
      <td></td>
      <td>text1</td>
      <td>text2</td>
      <td>text3</td>
    </tr>
    <tr>
      <td colspan="100%">&nbsp;</td>
      <td colspan="100%" class="fix">Some text here.. 2.</td>
    </tr>
    <tr>
      <td></td>
      <td>text4</td>
      <td>text5</td>
      <td>text6</td>
    </tr>
    <tr>
      <td colspan="100%">&nbsp;</td>
      <td colspan="100%" class="fix">Some text here.. 3.</td>
    </tr>
    <tr>
      <td></td>
      <td>text7</td>
      <td>text8</td>
      <td>text9</td>
    </tr>
    <tr>
      <td colspan="100%">&nbsp;</td>
      <td colspan="100%" class="fix">Some text here.. 4.</td>
    </tr>
    <tr>
      <td></td>
      <td>text10</td>
      <td>text11</td>
      <td>text12</td>
    </tr>
  </table>
  <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

Top method for saving information on page for Ajax calls

On my dynamically generated page, there is an array of data produced by php that I want to utilize for an ajax request. However, I am unsure of the best method to store this data on the page as it is not sensitive and does not involve a form. Currently, I ...

Is it possible to create a sticky element that stays fixed to the window without using JavaScript?

Using position: sticky has been a game-changer for me. It resolves many issues without the need for JavaScript. However, I've encountered a roadblock. I am trying to create a sticky element that is nested inside multiple <div> elements. Since po ...

Comparing the use of visibility: hidden with -webkit-transform: translate3d() within a PhoneGap application

Currently, I am creating a hybrid application using PhoneGap. As part of the design, I have several divs (each representing a page) that I toggle between by changing their visibility in CSS using "visibility: hidden" and "visible". However, I recently ca ...

Achieving a 100% width input with Flexbox: Tips and tricks for success

Check out this flexbox form I created using bootstrap 4: https://jsfiddle.net/kkt0k2bs/1/ I have implemented a media query to adjust the form elements for smaller screens. For larger displays, I want the form items to be displayed inline. However, on sm ...

Update array when checkbox is selected/deselected

Using angular-google-maps, I am creating a map with various types of markers. Below the map, there are checkboxes in a simple form: <div class="mapOptions"> <form action="" class="form-inline" style="text-align:center"> <label for=""& ...

Utilizing Ajax and Jquery within Zend framework

I'm working with the Zend framework using PHP and attempting to submit a form via ajax/jquery. Below is the structure of the .phtml file: <form id="find"> <input type="text" name="name"> <input type="submit" id="submit" value ...

I am looking to automatically add a line of HTML text to the notifications list without requiring the user to manually refresh the page

Having trouble articulating the correct term or language I need, making it difficult to search. Q: How can I push a line of text from the server side to the user? I am developing an MVC 4 application using asp.net and c# in .net4. One page will feature a ...

Change the class name on a RichFaces 4 component to utilize themeroller functionality

Before I dive in, let me mention that I have thoroughly gone through the following content: Stackoverflow:how can i remove the css classes from a richfaces component However, my concern lies with version 4 as opposed to v3.x which was discussed in the re ...

Using CSS to Showcase the Art Gallery Page

This is my unique gallery display: https://i.stack.imgur.com/RddD8.png Here is the look I am going for https://i.stack.imgur.com/kuOye.png I want to showcase images in a slightly messy yet awesome way However, I encounter an issue when some images have ...

The reason why setting height to 0 is ineffective in a CSS definition

Within my current project, I am utilizing vue.js 2 and have implemented an img component. Below is the code for this component: <template> <div class="banner"> <img class="banner-img" :src="bannerImg"/> </div> </template> ...

Identify input elements that specifically contain an onclick event

Several of the input elements on my page have a function called setSomeFunction() that either shows or hides certain divs when clicked. I know I can locate all the input elements using document.getElementsByTagName("input") and store them in an array. How ...

Converting data from Random.org into an integer using JavaScript

I have been working on a small web application to experiment with CSS animations. Although it's functioning, I'm seeking more genuine randomness. To achieve this, I am exploring the use of Random.org. How can I import the output from Random.org i ...

Create two div elements containing responsive images using HTML and CSS

Can someone assist me in creating responsive DIVs with images inside? Currently, the second div is appearing below the first one, and I'm struggling to make them scale based on mobile and tablet screen sizes. Here is the code snippet: .new_ba ...

The problem of heavy images not uploading persists when using Ajax/Jquery, as the FormData appears to

I have encountered an issue while running this code for images. It works perfectly for small images up to 2.5mb each, and the form is supposed to handle a maximum of 8 images. However, when I try to upload images larger than 4mb, or more than one such imag ...

The argument 'TabsCtrl1' is throwing an error as it is not recognized as a valid function and is showing as

I have encountered a problem with my controller, and I am seeing the following error message: Error: [ng:areq] Argument 'TabsCtrl1' is not a function, got undefined http://errors.angularjs.org/1.3.0-beta.11/ng/areq?p0=TabsCtrl1&p1=not%20a%20 ...

What measures can I take to ensure that users cannot tamper with the PayPal code?

I've integrated a "Pay Now" button from Paypal onto my website. However, there is an issue where users can easily alter the payment amount before proceeding. Below is the code PayPal has provided: <form action="https://www.paypal.com/cgi-bin/webs ...

PHP and JavaScript are two powerful programming languages that are

While I understand that PHP and JavaScript operate in different locations, I am curious to know if there is a way to incorporate some PHP code into my JavaScript file. I need to create unique URLs for linking to profiles and news posts, such as /#/news/IDH ...

Text that is superimposed onto an image

Struggling to implement a hovering text over an image? I attempted to follow a tutorial, but couldn't adapt it to my project. While I managed to create a fixed overlay, I aim for a responsive solution that adjusts with resolution changes. My goal is t ...

Create a Bootstrap layout with three columns and three rows, where the third column has a height

I am trying to achieve a specific layout using the col-lg-4 class. My main goal is to make the third column span across all three rows without creating excessive white space between them. The current layout looks like this: Is it possible to do this in B ...

Guide to "flashing" an image momentarily on the screen using PHP

I'm looking for a way to display an image on my simple website for 3 seconds and then prompt the user to indicate if they recognized the image or not by clicking a button. I don't need help with the button, just how to create the timer. While I ...