• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

HTML table column alignment different when sent by sketch??

Q&A Forum › Category: ESP32 › HTML table column alignment different when sent by sketch??
0 Vote Up Vote Down
Roger Wilson asked 3 weeks ago

Hi RNT team. I am using code adapted from your “Build an All-in-One ESP32 Weather Station Shield” to just display 3 parameters from my different sensors (SHT45 and BMP390)and it is working nicely. One change I made was to store index.html in LittleFS in flash memory instead of on an SD card but when I just open index.html directly in my browser all of the items in the table are centre-aligned but when I run the sketch and open the WiFiServer URL in my browser, all of the items in the readings rows are left-justified while the headings row remains centre-aligned. What is the source of that difference? I’m assuming it must be altered by the sketch somehow since the index.html file is the same. I’d like to fix it so that the heading row and data rows are the same. Can you help me? Images illustrating this issue are here: https://imgur.com/a/512Qgxk
 

Question Tags: HTML discrepancy
8 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi.
When you access the web page on your browser, open the console: CTRL+SHIFT + J

Click on the Elements tab.
Now, you can see the HTML file the browser is loading and compare it with the original one to see if any changes were made during the process.
 
I hope this helps.
 
Let me know if you need further help.
 
Regards,
Sara
 
 

0 Vote Up Vote Down
Roger Wilson answered 3 weeks ago

Thanks for that tip Sara. I found through the elements tab that in the sketch URL version <table> section that the test-alignment was not ‘inherited from body’ ie it is crossed out but I don’t know why this is handled differently from when just opening the html file directly. I added a ‘test-align: centre’ statement into the table section of the <style> block immediately below the body section which also has that statement and this has corrected the problem. All of the labels and readings in the table are now centre-aligned. It would be good to know why it is not inherited.I have attached a couple of images showing this. https://imgur.com/a/5ZP0oA8

0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi.
That’s a very strange issue.
And unfortunately, it’s hard to understand what might be causing it without further information.
Can you share your files?
Regards,
Sara

0 Vote Up Vote Down
Roger Wilson answered 3 weeks ago

Ok.
Here are the index.html and my sensor sketch adapted from your code to use LittleFS instead of an SD card and to read from my sensors:
https://drive.google.com/file/d/1KvKKMsyat81pbh8CltynGPS2loLcmVmN/view?usp=sharing
Index.html is unchanged except for the addition of the text-align statement in the table section to correct the left alignment of the readings rows to be displayed centre-aligned.
 

 
0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi again.
I didn’t get the index.html file.
I was asking for the one that wasn’t working to try to understand why it didn’t inherit the style.
 
It is has probably something to do with escape characters or something like that.
 
Regards,
Sara

0 Vote Up Vote Down
Roger Wilson answered 3 weeks ago

Hi Sarah. The index.html file was there. Just close the first file displayed with X at top left and then both files are listed. However, here is another link with only index.html in the folder. This is the version (your original) that doesn’t work properly when invoked from the sketch although I have added comments in lines 50-53 about the addition I made to correct the problem but the correction line itself is also commented out here. 
https://drive.google.com/drive/folders/1x3XEb_dL6dq-lZt8Rz3w0iQf1LIO33hi?usp=sharing
 

0 Vote Up Vote Down
Roger Wilson answered 3 weeks ago

Hi Sara, I think I have found the answer … my further investigations suggest that the text-align property specified in the body is actually inherited by the table element, but the alignment for content inside table cells (td) and header cells (th) is then overriden by the browser’s default stylesheet and left-aligned. This is avoided by setting the text alignment again in the table section or more directly in the table cell sections eg th, td. 
Furthermore, apparently a different ‘engine’ is used to display html files viewed directly in a browser than within an application like a sketch ?

0 Vote Up Vote Down
Sara Santos Staff answered 3 weeks ago

Hi.
Thanks for letting me know.
I think that as long as you’re using the same browser, the final result should be the same.
I have no idea why it behaves differently in those scenarios.
 
Regards,
Sara
 
 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 Version 1.7 November 28, 2025
  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 V1.6 September 9, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.