Which HTML tag can prevent the number "1,008" from breaking onto a new line?

Currently, I am learning about HTML tables and working on creating a periodic table for my school project. I am facing some challenges with formatting the text. Ideally, I want the atomic number and mass to be displayed on the same line, with the atomic number on the left and the mass on the right. However, I'm unsure which tag to use (I am currently using div).

https://i.sstatic.net/o7lIj.png

This is what I have attempted so far:

<th class= hidrogenio>
    <div class= numeroatomico>
        1
        <div class= massa>1,008</div>
    </div>
    H
    <div class= nome>Hidrogênio</div>
</th>

Answer №1

Designing a periodic table using HTML and CSS can be quite challenging, especially for those who are new to creating tables. The key is to utilize nested tables: an outer table to structure the periodic table itself, with each cell containing an inner (nested) table to organize the element's layout.

The inner tables consist of three rows and two columns, where the second and third rows have cells spanning both columns.

<table>
  <tr>
    <td class="atomic-number">19</td>
    <td class="mass">39.098</td>
  </tr>
  <tr>
    <td class="symbol" colspan="2">K</td>
  </tr>
  <tr>
    <td class="name" colspan="2">Potassium</td>
  </tr>
</table>

https://i.sstatic.net/Hr9Fh.png

table {
  border: 1px solid #888;
  width: 6em;
}

td {
  border: 1px solid red;
}

.atomic-number {
  font-weight: bold;
}

.mass {
  font-size: 0.75em;
  text-align: right;
}

.symbol {
  font-size: 2em;
  text-align: center;
}

.name {
  text-align: center;
}
<table>
  <tr>
    <td class="atomic-number">19</td>
    <td class="mass">39.098</td>
  </tr>
  <tr>
    <td class="symbol" colspan="2">K</td>
  </tr>
  <tr>
    <td class="name" colspan="2">Potassium</td>
  </tr>
</table>

To complete the design, an outer table is needed to manage the entire structure. Here’s how you can start:

https://i.sstatic.net/Yxcjm.png

.periodic {
  border-collapse: collapse;
}

.periodic > tbody > tr > td {
  width: 6em;
}

.periodic > tbody > tr > td:not(.empty) {
  border: 1px solid black;
}

.periodic > tbody > tr > td >table {
  width: 100%;
}

.atomic-number {
  font-weight: bold;
}

.mass {
  font-size: 0.75em;
  text-align: right;
}

.symbol {
  font-size: 2em;
  text-align: center;
}

.name {
  text-align: center;
}

.alkali-metal {
  background: pink;
}

.alkali-earth-metal {
  background: lavender;
}

.transition-metal {
  background: aliceblue;
}
<table class="periodic">
  <tr>
    <td class="alkali-metal">
      <table>
        <tr>
          <td class="atomic-number">11</td>
          <td class="mass">22.989</td>
        </tr>
        <tr>
          <td class="symbol" colspan="2">Na</td>
        </tr>
        <tr>
          <td class="name" colspan="2">Sodium</td>
        </tr>
      </table>
    </td>
    <td class="alkali-earth-metal">
      <table>
        <tr>
          <td class="atomic-number">12</td>
          <td class="mass">24.305</td>
        </tr>
        <tr>
          <td class="symbol" colspan="2">Mg</td>
        </tr>
        <tr>
          <td class="name" colspan="2">Magnesium</td>
        </tr>
      </table>
    </td>
    <td class="empty"></td>
  </tr>
  <tr>
    <td class="alkali-metal">
      <table>
        <tr>
          <td class="atomic-number">19</td>
          <td class="mass">39.098</td>
        </tr>
        <tr>
          <td class="symbol" colspan="2">K</td>
        </tr>
        <tr>
          <td class="name" colspan="2">Potassium</td>
        </tr>
      </table>
    </td>
    <td class="alkali-earth-metal">
      <table>
        <tr>
          <td class="atomic-number">20</td>
          <td class="mass">40.08</td>
        </tr>
        <tr>
          <td class="symbol" colspan="2">Ca</td>
        </tr>
        <tr>
          <td class="name" colspan="2">Calcium</td>
        </tr>
      </table>
    </td>
    <td class="transition-metal">
      <table>
        <tr>
          <td class="atomic-number">21</td>
          <td class="mass">44.956</td>
        </tr>
        <tr>
          <td class="symbol" colspan="2">Sc</td>
        </tr>
        <tr>
          <td class="name" colspan="2">Scandium</td>
        </tr>
      </table>
    </td>
  </tr>
</table>

Answer №2

If you want to achieve this design, you can utilize flexbox:

.header { 
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
}

.element {
  padding: 10px;
  width: 100px;
  height: 100px;
  background: cornflowerblue;
 }
<div class="element">
<div class="header">
  <span>1</span>
  <span>1,008</span>
</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

Design interactive elements such as buttons and input fields inspired by the layout of Google websites

Does anyone know how to achieve the sleek, lightweight buttons and text boxes seen on Google's web pages like Google Search, Google Plus, and Google Play? I am currently using JSP and CSS, but I am open to incorporating jQuery if necessary. Any help w ...

Ways to avoid text covering the button using CSS

Take a look at this image: https://i.sstatic.net/U7wGV.png In the image, you can see that I have entered text in the input box. However, since there is also a button placed inside the box, the text gets hidden behind it. Is there a way to prevent this i ...

Error message: "Link binding error in knockout collection"

In this example, you'll find my Knockout ViewModel. $(document).ready( function () { var Incident = function (CaseNumber, DateOfIncident, Description) { this.CaseNumber = CaseNumber; this.DateOfIncident = DateOfIn ...

``Can you provide step-by-step instructions on how to delete a particular item from

Currently, I am in the process of developing a simple comment list application using JavaScript and local storage. I have completed all the necessary details, but now I need to figure out how to remove a specific item that was created by the application ...

"I am looking for a way to retrieve dynamic data from a (click) event in Angular. Can

Within my component, I have a video loaded in an i tag on a click event. The challenge is accessing the video ID from the video.component.ts file in order to dynamically load a new video. The solution has been elusive so far. <li *ngFor="let video of c ...

Leverage an HTML table to serve as a data source for populating a Kendo UI template

My latest creation is a unique service that generates HTML tables based on request parameters. The current implementation returns the data as an HTML page in string format. Here's a sample output: <!DOCTYPE html> <html> <head> ...

Each time I load the page, it displays differently depending on the browser. I'm struggling to understand the reason

Trying to figure out how to make the navigation bar close when a link is clicked and directed to a section instead of a new page. When on a large screen, I want the nav bar to remain open but automatically close when on a small screen (for example, when th ...

I am having trouble getting Vue.js to function properly within HTML when using Django. Can someone please lend me a

The code run Here is the HTML document: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> <!--javascript extensions--> <script src=' ...

Strip away styles and scripts from PartialView

Looking to incorporate a Star Rating system using a PartialView named: @{ Html.RenderAction("Rate"); } The goal is to display and manage the star rating code separately from the current page, eliminating the need for the parent .cshtml's CSS and oth ...

Creating a visually appealing line design with customizable column widths using CSS

Currently, I am working on designing a user registration page for a testing application and facing some challenges with the layout. CSS has never been my strong suit, but I can manage to style most of the elements except for one - the birthday field. My fo ...

How can I achieve a full-width div without using the container-fluid class while still maintaining the width and structure of

I am looking for a full div without the container-fluid class while keeping the container width fixed. The structure of the container should not change as I need another div inside the container. The structure should remain as it is. .main { padding: ...

Guide on utilizing Thymeleaf for dynamic updates in a table

My code includes a segment like this: <div class="ui-table"> <div class="items"> <div class="justify-content-end d-flex"> <span class="text- ...

What is the best way to align the Storefront Menu in the center?

If you want to reproduce the issue I'm facing, visit the demo page of the storefront here: then remove the node <ul id="site-header-cart" class="site-header-cart menu"></ul> that contains the cart box (located next to the menu) so that on ...

JavaScript Mobile Redirect HTML

Despite numerous attempts, I have been unable to get the mobiledetector script to function as desired for my mobile viewers. My goal is to include a link on the mobile site that allows users to access the full site without being redirected back to the mobi ...

The functionality of my PHP code for email transmission is currently malfunctioning

I'm having trouble sending mail from my HTML form using PHP. I've uploaded the necessary files to my hosting server but the mail is still not being sent. Here is my HTML code: <!-- Form --> <form action="http://example.com/sendEmail.php ...

Header and footer remain unaligned

Bookstore.html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <style> ul { list-style-type: none; padding: 20px; overflow: hidden; background-color: black; width:1230px; p ...

Ensuring a fixed table with vertical scrolling only, no horizontal scrolling, while scrolling in either direction

I'm working with an HTML fixed design that contains a center-aligned table with extensive data scrollable both vertically and horizontally. To address the issue of keeping column headers visible when scrolling vertically, I used jQuery's clone() ...

Is it possible to apply a click effect to a specific child element of a parent using jQuery?

Struggling to figure out how to modify this jQuery code so that only the parent of the clicked button displays its child. Currently, all children are displayed when any button is clicked, not just the one within the targeted parent. I attempted using $(t ...

The @Html.Label feature fails to appear when the content includes a period (.) - Utilizing Bootstrap with MVC Razor

I am dynamically populating label text from a database source <div class="col-11 col-sm-11 col-md-11 col-lg-11 col-xl-11"> @Html.Label(@Model.Questions[i].DataText + ": ", new { @for = "dd" + @Model.Questions[i].Data ...

Tips for shifting objects from a horizontal row to a designated vertical column when switching to a smaller display

I am currently utilizing bootstrap to enhance my website layout for mobile view. The main challenge I'm facing involves transitioning items from a row to a column in a specific order. In this case, I have two items in a row and I would like the first ...