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

Formatting issue with selecting checkboxes in Primefaces DataTable filter menu

I decided to replicate the Primeface showcase for filters on my Local JBoss installation by referring to the link provided below: http://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml. However, I encountered an issue where my selectCheckboxMenu ...

Possible revised text: "Exploring methods for verifying elements within a div using Selenium

I have a situation where I need to verify elements within a div by using the following xpaths. The xpath for each item is as follows: Item 1:- //*[@id='huc-last-upsell-rows']/div[1]/div[2]/div[1]/div/div/a/img Item 2:- //*[@id='huc-last-u ...

What are some effective ways of using the parent, before, and children selectors?

<table> <tr><td><input type="text" value="123"></td><td><input class="here" type="text"></td></tr> <tr><td><input type="text" value="333"></td><td><input class=" ...

Cease the use of the jQuery.css() method

Does anyone know how to halt the jQuery css() function? I've successfully used the jQuery.stop() function to pause the animate() function, but I'm unsure about stopping css(). Any help is appreciated. Thanks! ...

Is there a way to modify the color of a checkbox within MUI?

I'm currently customizing the checkbox color in Material UI while using FormIk for data submission. I aim to change the default checkbox color to red, but I'm unsure about how to achieve this. <FormGroup> <Box display=" ...

Changing the background color of a PHP input based on the webpage being viewed - here's how!

I'm in the process of creating a website where each page will have its own unique background color. Additionally, I am using a PHP input for both the header and footer sections, which need to change their background colors based on the specific webpa ...

Mastering the use of v-if and v-else in Vue JS for <td> table elements

After exhausting my search efforts without finding a solution, I am turning to this platform for clarification on how to correctly implement the v-if and v-else directives within <td> elements in an HTML table in Vue. //assuming that the value of th ...

Align text to the right and do not include any images

I am attempting to align the images back to the left under the title, while only floating the description text to the right. I am struggling with clearing the image floats. HTML: <div class="title">System Displays</div> <div class="descrip ...

What is the process for invoking a websocket from an HTML client?

I have created a WCF Service using netHttpBinding binding and it is hosted on IIS 8 (Windows Server 2012). The interfaces for the service are as follows: [ServiceContract(CallbackContract = typeof(IDuplexCallbackContract))] public interface IHelloWebSocke ...

Is there an issue with JQM plugin due to jQuery's append() function?

I am just starting to learn about jQuery mobile as I develop an app using it. Whenever I click on the Add_details button, I want to add dynamic input fields only once. After saving, if I click on the Add_details button again, I need to append more dynamic ...

Share a URL and display small previews from it - php

Have you ever noticed that on certain websites, such as Facebook, when you post a link it automatically displays thumbnails from the linked website? Like in the image below: Ever wondered how to achieve that effect? ...

Can cells be divided in a Material UI table?

Is there a way to split a cell in a Material UI table?I am aware that I can create a component to achieve this, but I'm wondering if there is another approach that I may not be aware of. Splitting a cell means having two values separated by a line wit ...

Enhance your webpage with our jQuery plugin that allows you to easily make Ajax

I am currently working on developing a custom jquery plugin. One of the functions within this plugin requires an ajax-call to be made. However, I want to ensure that the function remains chainable, meaning that the ajax-call should only happen after a re ...

Tips on toggling the visibility of a div using jQuery and CSS via a toggle switch

Hey there, I need some help with toggling the opening and closing of a div when clicking on a toggle switch. $('.tog').on('click', function() { $('.cntr').show(); }); .switch { position: relative; display: inline-bloc ...

Errors occur when using jQuery Autocomplete alongside Angular HTTP

I have implemented an ajax autocomplete feature for my database using the jQuery-Autocomplete plugin. Below is my current code setup: HTML: <input ng-keyup="searchCustomer()" id="customerAutocomplete" type="text"> Angular $scope.searchCustome ...

Issues with Chrome causing Ajax synchronous requests to fail

Is the latest release of Chrome no longer supporting Synchronous Ajax calls? We're encountering an error with our Synchronous Ajax requests after updating to version 73.0.3683.103. Interestingly, Synchronous calls are still functioning properly on Fir ...

Implementing the passing of value from view to controller in CodeIgniter through an onclick feature

I need to pass the button's id onclick from the view to the controller using ajax, but I keep getting this error: 500 Internal Server Error This is my view: <a data-toggle="modal"data-target="#Add_Money_to_campaign" ><button onclick="add ...

Tips for achieving consistent text and image alignment through CSS styling

My table currently contains a default profile image. Initially, there might not be any text content and I have set up the CSS styling to allow text to wrap around the default image. I am facing an issue when trying to position the image statically in a wa ...

Exploring the Power of jQuery Event Attributes

Can someone explain the distinct difference between the keys delegateTarget and currentTarget in the jQuery event object? $(this).on('click',function(event){ console.log(event.delegateTarget); console.log(event.currentTarget); ...

Customizing CSS to override Semantic React UI styles

Is there a way to customize the default Header provided by react semantic UI? Currently, I have placed my Header within a div so that I can apply custom styles. <div className="portfolioTitle"> <Header as="h1">Check out this amazing ...