Interactive HTML/CSS Periodic Table with Dynamic Design

Recently, I have been immersing myself in learning about responsive design in HTML/CSS and decided to challenge myself by coding the periodic table of elements using HTML/CSS to hone my skills. While I have set up the basic structure of the table with div elements, I am struggling with making it responsive. I've experimented with percentages but haven't had much success. Any guidance on how to make it more responsive would be highly appreciated.

HTML:

    <!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="style.css">
        <title> Periodic Table of Elements, in CSS! </title> 
    </head> 
    <body>
        <section>
            <div id="container">
            <div id="panelOne">
                <div class="box"> H </div> 
                <div class="box"> Li </div> 
                <div class="box"> Na </div> 
                <div class="box"> K </div> 
                <div class="box"> Rb </div> 
                <div class="box"> Cs </div> 
                <div class="box"> Fr </div> 
            </div>
           <!-- Remaining HTML code omitted for brevity -->
        </section>
    </body>
</html>

CSS:

    
/* CSS styles go here */
body{
    font-size: 16px;
}
section{
    width: 1500px;
    max-width: 90%;
    margin: 0px auto;
}
#container{
    width: 1400px;
}
.box{
    border: 3px solid black; 
    max-width: 50px;
    max-height: 50px; 
    padding: 10px;
    line-height: 50px; 
    text-align: center; 
    font-size: 1.63em;
}

#panelOne{
    float: left; 
}
<!-- Additional CSS styles omitted for brevity -->

JSFiddle http://jsfiddle.net/cqkAd/

Answer №1

For those in need of a pure-css solution, look no further! I have crafted a solution free of floats and unnecessary classes. By setting negative margins on each column, the 'double border' effect is eliminated. Using percentage padding helps control box height, while trimming away unnecessary class names for a cleaner code structure (although you can always add them back). A small margin on the right can easily be removed with a negative margin adjustment. Additionally, a minimum width is applied to the table, but that can also be taken out with ease. The solution has been tested in Chrome, although other browsers might require additional testing. Feel free to reach out if you have any questions. Enjoy!

To view the HTML markup, check out the JSfiddle link. Below is the CSS snippet:

#periodic_table {
    width: 100%;
    min-width: 600px;
}

#periodic_table > div {
    margin-bottom: 2.5%;
}

#periodic_table > div > div {
    width: 5.5%;
    display: inline-block;
    margin-right: -7px;
}

#periodic_table > div > div > div {
    border: 3px solid black;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    text-align: center;
    background: red;
    margin-top: -3px;
    padding: 20% 0;
}

Answer №2

To achieve a shrinking effect on the boxes, adjust the width of your panel# classes to be in percentage units.

Answer №3

To ensure responsiveness, consider using percentage based widths in your CSS:

#container{
    width: 100%;
}
.box{
    border: 3px solid black; 
    max-width: 50px;
    max-height: 50px; 
    padding: 10px;
    line-height: 50px; 
    text-align: center; 
    font-size: 1.63em;
}
.panel{
    /* Divide 100% by the number of vertical panels */
    width: 5.5%;
}

Check out this fiddle with adjusted HTML and comprehensive CSS:

http://jsfiddle.net/cqkAd/1/

If the layout looks messy at lower widths, consider setting a fixed min-width (in px) and fine-tuning the padding.

Remember, avoid using spaces for padding and maintain consistency with your use of id and class.

Answer №4

After incorporating most of your suggestions, I successfully redesigned my own dynamic layout and I am extremely pleased with the outcome. Thank you for all your assistance! Here is the code snippet:

http://jsfiddle.net/KjgfV/

<!DOCTYPE html>
<html>
<head>
    <title> Periodic Table of Elements, in CSS! </title> 
    <link rel="stylesheet" type="text/css" href="style.css"> <!--Main StyleSheet -->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'> <!-- Google Fonts --> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <!-- jQUery -->
    <script type="text/javascript" src="js/jquery.js"></script>
</head> 
<body>
    <section>
    <div id="menu"> The Periodic Table of Elements </div> 
        <div id="container">
        <div id="panelOne">
            <div class="box"><a href="http://en.wikipedia.org/wiki/Hydrogen"> H </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Lithium"> Li </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Sodium"> Na </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Potassium"> K </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Rubidium"> Rb </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Caesium"> Cs </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Francium"> Fr </a></div> 
        </div>
        <div id="panelTwo">
            <div class="box"><a href="http://en.wikipedia.org/wiki/Beryllium"> Be </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Magnesium"> Mg </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Calcium"> Ca</a> </div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Strontium"> Sr </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Barium"> Ba </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Radium"> Ra </a></div> 
        </div>
        <div id="panelThree">
            <div class="box"><a href="http://en.wikipedia.org/wiki/Scandium"> Sc</a> </div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Yttrium"> Y </a></div> 
            <div class="box"><a href="#"> * </a></div> 
            <div class="box"><a href="#"> * </a></div> 
        </div>
        <div id="panelThree">
            <div class="box"><a href="http://en.wikipedia.org/wiki/Titanium"> Ti </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Zirconium"> Zr </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Hafnium"> Hf </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Rutherfordium"> Rf </a></div> 
        </div>
        <div id="panelThree">
            <div class="box"><a href="http://en.wikipedia.org/wiki/Vanadium"> V </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Niobium"> Nb </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Tantalum"> Ta </a></div> 
            <div class="box"><a href="http://en.wikipedia.org/wiki/Dubnium"> Db </a></div> 
        </div>
        
        (Additional panels continue...)
        
    </div>
    <div id="clear"></div>
    <div id="lowerContainer">
    
        (Bottom elements continue...)
        
    </div>
    <div id="infoContainer">
            This is the information. 
    </div> 
    </section>  
</body>

CSS:

(CSS continuation remains same as provided)

jQuery:

$(document).ready(function () {
var $ic = $('#infoContainer');
$ic.hide();
$('.box').click(function () {
    var newLink = $(this).find('a').attr('href'); 
    var left  = ($(window).width()/2)-(600/2),
        top   = ($(window).height()/2)-(400/2),
        popup = window.open (newLink, "Element", "width=600, height=400, top="+top+", left="+left);
    return false;
}); //End box click

}); //End ready

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

Tips to prevent elements from overlapping in Angular applications

I am facing an issue with my Angular-based app where I dynamically populate the page with table rows. There is an app-console element below the page that has a fixed position. Whenever I click the button to add a new row, it overlaps with the app-console. ...

Phonegap's JavaScript canvas feature is experiencing issues

Recently, I came across a JavaScript bouncing ball animation that works perfectly on the Chrome browser when used on a PC. However, when I tried running it using Phonegap Eclipse Android emulator, I encountered an issue where the canvas appeared blank and ...

Challenge in creating a responsive layout using Bootstrap framework

I'm working with Bootstrap, but I'm struggling to achieve the desired layout. My goal is to have the design adapt like this on different screen sizes: ---------------------- Headline | | | image | ----------| | B ...

Overlap with upper picture formatting

I've been struggling to create an ion-card with two images: a main picture and a small book cover. Any ideas on how to achieve this? Note: The layout should have 2 images, one at the top and another as a small book cover. Check out this sample on St ...

Table with Typewriter Style CSS Animation

I came across an interesting typewriter effect implementation using CSS in an article on CSS Tricks I decided to play around with it and see if I could apply it to a hero image, which I found an example of on Codepen However, I noticed that the blinking ...

Simple Way to Modify Color of Active Page Link - HTML, CSS, and JavaScript

I found a helpful example on how to change link colors for the current page here. Here is the script I added: <script> // current page highlight $(document).ready(function() { $("[href]").each(function() { if (this.href == window.l ...

Adjust the size of the Facebook share button

Is there a way to resize the Facebook share button? The default size provided by Facebook is way too small, and I'm struggling to make it larger. I've tried changing the class and even adding an ID, but so far nothing has worked as I hoped. Here ...

Animate.css plugin allows for owl-carousel to smoothly transition sliding from the left side to the right side

I have a question regarding the usage of two plugins on my website. The first plugin is Owl Carousel 2, and the second one is Animate.css. While using `animateIn: 'slideInLeft'` with Owl Carousel 2 is working fine, I am facing an issue with `ani ...

In Internet Explorer versions 7 and 8, a transparent overlay div enables click-through functionality

I am facing an issue with a div containing form elements and an invisible overlay mask. When using IE 7 and 8, the click goes through the overlay without background which is incorrect. To solve this problem, I added a background color to the overlay div w ...

Is it possible to conceal my Sticky Div in MUI5 once I've scrolled to the bottom of the parent div?

Sample link to see the demonstration: https://stackblitz.com/edit/react-5xt9r5?file=demo.tsx I am looking for a way to conceal a fixed div once I reach the bottom of its parent container while scrolling down. Below is a snippet illustrating how I struct ...

calculating the duration between successive PHP form submissions

I am trying to calculate the duration between when a user submits a PHP form and when they submit it again. The form reloads on the same page, essentially refreshing it. Additionally, the user may enter the same data again. I want the timer to start runnin ...

Issue with Chrome when using angled CSS gradient backgrounds

I'm encountering a problem with a CSS gradient background on a div that is set to 100% width and height. This issue only seems to be happening in Chrome. I have some content placed over the div, and when I hover over links within that div, the gradien ...

Issues with the menu pop-up functionality arise when utilizing the CSS class .active

When I have this code, the ".active" function doesn't work when clicked. However, if I change the div class from "top-menu-popup" to "top-menu-popup active" when opening the page, the menu is already activated. <div class="top-menu-popup"> ...

What are the various ways to incorporate material graphic elements on an HTML static webpage?

Currently, I am working on creating a static website that will be stored on CDs and USB sticks. This website serves as a manual for a specific product. I am considering using a graphic framework like Onsen UI, but I have found that I prefer Material UI. ...

Check if the element is located on the active tab using jQuery

I have implemented a tab system to organize a lengthy form with multiple input fields. The form consists of 4 tabs, and beneath them, there is a preview section displaying the user's selections. In this preview area, I added icons that enable users ...

I'm having trouble with getting my Bootstrap CSS and JS links to function properly

The paths for the Bootstrap CSS and JS files have been included in the code, but unfortunately, they are not working. Instead, I am getting the following errors in the console: GET http://127.0.0.1:5000/[https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist ...

Efficiently Organizing Data Using Coldfusion Loops in Columns and Rows

My issue lies in pulling data from a database to display on my website. I have three keys/attributes (columns) - PostedDate, DataImage, and Source that need to be shown together in one div with the posted date at the top, image in the middle, and source at ...

Looking to tilt text at an angle inside a box? CSS can help achieve that effect!

Hey there, is it possible to achieve this with CSS or JavaScript? I require it for a Birt report. ...

Navigating horizontally with buttons in VueJS

I am searching for a way to implement horizontal scrolling using buttons in VueJS. The idea is to have a container with multiple divs arranged horizontally, and I wish to navigate through them using the buttons. If you want to see a similar solution using ...

Enhance mix-blend mode or filtering effects in SCSS using an SVG component in VueJS

I am currently developing a fixed navbar at the top of a webpage with several SVGs inside anchor tags. I want the SVGs to appear black when displayed over lighter colored divs (other Vue components) and white when displayed over darker colored ones. The ba ...