Formatting tabular rows to appear as headers

I am currently developing a mobile website that is specifically designed for older phones with minimal CSS and HTML support. Due to these limitations, I have decided to utilize tables in my design.

My goal on a certain page is to create a table row with a heading displaying a specific value, followed by another row in the same table that includes the value along with a link to edit it.

The issue I am facing is that the heading only spans one column, but I would like to style it with padding, margins, and a border.

Could someone offer some guidance on how to achieve this?

HTML

<div class="navalt">
    <table style="width:100%;">
        <tbody>
        <tr class="edHeading">
            <td><fmt:message key="editprofile.location"/></fmt:message></td>
        </tr>
        <tr>
            <td class="leftTd">USA</td>
            <td class="rightTd"><a href="">Edit</a></td>
        </tr>

CSS

.navalt {
    text-align:center;
    padding: 4px 0px 4px 4px;
    border-top: thin solid #C5C9D1;
    border- bottom: thin solid #C5C9D1;
}
.edHeading {
    padding: 4px 0px 4px 4px;
    background-color:#E9E1FF;
}
.leftTd {
    border-right: thin solid #C5C9D1;
    padding: 0px 0px 0px 5px;
    text-align:left;
    width:50%;
}
.rightTd {
    padding: 0px 5px 0px 0px;
    text-align:right;
    width:50%;
}

Answer №1

One way, as mentioned by Wabs, is to add a colspan to the td in the header.

Alternatively, for better styling separation, you can utilize the thead tag since you already have <tbody>.

Just a side note: make sure to include closing tags for your div, body, and table. I'm assuming they were omitted due to partial code copying?

Check out this fiddle: http://jsfiddle.net/f6NKt/2/

The code snippet:

HTML

<table style="width:100%;">
  <thead>
    <tr>
      <th colspan="2">Heading - using th tags for location</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="leftTd">USA</td>
      <td class="rightTd"><a href="">Edit</a></td>
    </tr>
  </tbody>
</table>
 

CSS - notice the use of thead:


.navalt {
   text-align:center;
   padding: 4px 0px 4px 4px;
   border-top: thin solid #C5C9D1;
   border-bottom: thin solid #C5C9D1;
}

thead {
   padding: 4px 0px 4px 4px;
   background-color:#E9E1FF;
}

thead th {
   font-size:20px;
}

.leftTd {
   border-right: thin solid #C5C9D1;
   padding: 0px 0px 0px 5px;
   text-align:left;
   width:50%;
}

.rightTd {
   padding: 0px 5px 0px 0px;
   text-align:right;
   width:50%;
 }

Answer №2

It seems like you could enhance the header <td> by including colspan=2 so that it covers the entire table, unless I am mistaken.

<tr class="edHeading"><td colspan="2"><fmt:message key="editprofile.location"/></td></tr>

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

Revise the "Add to Cart" button (form) to make selecting a variant mandatory

At our store, we've noticed that customers often forget to select a size or version before clicking "Add to Cart" on product pages, leading to cart abandonment. We want to add code that prevents the button from working unless a variant has been chosen ...

Launch a PowerPoint presentation in a separate tab on your web browser

If you have a link that leads to a .pdf file, it will open in a new tab like this: <a target="_blank" href="http://somePDF.pdf">Download</a> But what about a Powerpoint file, such as a .ppt? Is there a way to make it open in a new browser tab ...

Clicking the submit button on a PHP contact form will prompt the opening of

My project involves creating a custom contact form using html5 and php. I have successfully designed the form as per my requirements and now I am working on validating the entered values in the fields. To check if everything is functioning correctly, I am ...

Resetting Radio Buttons for Re-Selection

I've been puzzling over this issue for some time now and have tried various methods with no luck. I'm working on a Quiz that uses radio buttons hidden from view, where they are supposed to be checked by clicking the li element they are in. Altho ...

Identifying 404 image status in AngularJS triggering by a button press

One question I have is about a button directive that I am working with: <button-data></button-data> The template for the button data directive looks like this: <div class="buttonDiv"> <a ng-show="!isSomthing" class="{{className}}" ...

Is there a way to access the font characteristics of a website?

I'm currently in the process of customizing my WordPress theme and I'm looking to adjust the font sizes for certain elements such as pagination. However, I'm finding the style.css file to be quite convoluted and I'm having trouble ident ...

Unable to substitute a value using the useState hook in React

Whenever I click a key, I attempt to update the value of a variable but it appears not to be working as intended. ↓ The current implementation is not effective and needs improvement import React, { useState, useEffect } from 'react'; const Li ...

React TSX file not recognizing JSON data stored in an HTML data attribute

I am having some trouble with implementing the password toggle component from the Preline UI. Here is how the component looks: "use client" import React, { ChangeEvent, MouseEventHandler, useEffect } from "react"; export default functi ...

Getting the list items separated from the unordered list in Selenium

My current task involves navigating a list and selecting the correct text entry. The list contains only 2 items: <ul> <li><span>first</span></li> <li><span>second</span></li> </ul> However, ...

Interactivity with SVG clip-path featuring multiple paths through hover events

I have a unique SVG demo image with multiple circles that are clipping an animated GIF. Can we detect hover events for each individual circle as the user mouses over them? For example, the top-left or middle-right circle? Is it also possible to change th ...

Get rid of the drop-down shadow effect

Currently working on a website project for a client and looking to remove the blue "shadow" effect from the dropdown menus. I believe the code that needs editing is as shown below: .main_nav ul.sub-menu { position: absolute; top: 65px; width: ...

Currently, my main focus is on finding a solution to adjusting the background color of the div element named *topnav* to properly match the width of the

I'm having trouble adjusting the width of the topnav background color to fill the entire page without any gaps. I hope that makes sense. Let me know if you need more information. Page displaying gap: Here is the HTML and CSS code: body {background ...

Dynamic loading of lists necessitates encapsulating nested lists

I'm currently working on a 3-level dropdown list that pulls content from a database for my project. I want the top level to resemble a tab menu, with a border surrounding the area underneath where the additional lists will appear. However, I am facing ...

Unable to find any matches when conducting a search through Google Apps Script

After spending days analyzing the code, I am encountering an error that states "uncaught reference error: google is not defined." This issue seems to occur specifically in line 360. Curiously, when inspecting the original code editor, line 360 simply conta ...

Is it possible to modify the text alignment of a div based on the dropdown selection

I'm having trouble getting the alignment to work with my dropdown list that styles the font of a div. It's frustrating because I usually find solutions easily on Google, but this time the align feature is really bugging me. <SCRIPT LANGUAGE=" ...

Can using display: none impact the SEO of a website's navigation menu?

Is there a difference in SEO impact between using display:none with CSS and using display:none with jQuery for menus? Appreciate the insights! ...

How to create a captivating image effect using CSS on hover

I am attempting to create an animated image on hover. The desired outcome is similar to the one showcased here: Check it out (scroll to view the image "Our Team") Essentially, I want a background where I can showcase information such as names and links ju ...

Transmitting form data inputted by the user to a modal that resides in the same component, all without the need for child or parent components or

In need of a solution where users can input answers to questions and have all the entered data displayed in a popup alongside the respective question. If a user chooses not to answer a question, I do not want that question or any related information to be ...

Tips for resolving the "Forbidden compound class names" error that occurs when trying to select an input field

As a newcomer to selenium, I am eager to start testing the login page. The text field below is where I need to input the username: <div class="WODM WNDM" data-automation-id="userName"> <div class="gwt-Label WBEM">Email Address</div><i ...

Incorporating image hyperlinks onto a designated webpage within a JavaScript presentation carousel

Working on an e-commerce website, the client has requested 3 slide shows to run simultaneously displaying specials or promotions. I have successfully set up the 3 slide shows next to each other, but I'm unsure how to incorporate image links that direc ...