Mysterious actions that validate div elements using css

Consider Example 1 and Example 2. In Example 2, the balls are correctly displayed in two rows, while in Example 1, the balls start to appear in the wrong place with wasted space before the first ball due to a random change in the number of green balls. When the balls are in a single row, it fails; when they are in two rows, it works. Moving the border between the result and JavaScript fields so that Example 2 goes on a single line causes it to fail. Therefore, I need these balls to start at the beginning of the black border in a single row, just like they do when in two rows. The "Example" text also needs to remain in the exact position as seen in the examples.

It would be ideal if the black box could end immediately after the last ball in the row, instead of having almost a full-length of wasted space.

Check out the examples here: http://jsfiddle.net/xCG72/

HTML

<div class="container">
    <span class="text-location">Example 1</span>
    <div class="thesis">
        <div class="box"><div class="number">134234</div></div>
        <div class="box"><div class="number">2</div></div>
    </div>
</div>

<div class="container">
    <span class="text-location">Example 2</span>
    <div class="thesis">
        <div class="box"><div class="number">10</div></div>
        <div class="box"><div class="number">20</div></div>
        <div class="box"><div class="number">30</div></div>
        <div class="box"><div class="number">40</div></div>
        <div class="box"><div class="number">10</div></div>
        <div class="box"><div class="number">20</div></div>
        <div class="box"><div class="number">30</div></div>
        <div class="box"><div class="number">40</div></div>
        <div class="box"><div class="number">10</div></div>
        <div class="box"><div class="number">20</div></div>
        <div class="box"><div class="number">30</div></div>
        <div class="box"><div class="number">40</div></div>
    </div>
</div>

CSS

.number {
    background-color: #37A047;
    height:35px;
    width:auto;
    -moz-border-radius:100px;
    -webkit-border-radius:100px;
    border-radius: 100px;

    border:2px;
    border-style:solid;
    border-color:#FFF;
    float:left;
    margin-right:auto;

    text-align:center;
    color:white;
    line-height: 35px;
    font-weight: bold;
    font-size: 30px;
    font-family: sans-serif;

    padding-top:10px;
    padding-bottom:10px;
    padding-right:10px;
    padding-left:10px;
}

.thesis {
    position:relative;
    float:left;
    top:-10px;
    width:auto;
    overflow: hidden;

    border:2px;
    border-style:solid;
    border-color:purple;
}

.container {
    -moz-border-radius:9px;
    -webkit-border-radius:9px;
    border-radius:9px;  
    border:2px;
    border-style:solid;
    border-color:black;
    float:left;
    width:auto;

    margin-top:8px;
    margin-bottom:5px;
    margin-right:5px;
    margin-left:5px;

    padding-top:20px;
    padding-right:5px;
    padding-left:5px;
    padding-bottom:1px;
}

.text-location {
    position:relative;
    left:15px;
    top:-40px;
    width:auto;
    float:left;
    z-index:10;
    border:2px;
    border-style:solid;
    border-color:yellow;

    background-color: #CCC;
    text-align:left;
    color:black;

    line-height: 16px;
    font-weight: bold;
    font-size: 16px;
    font-family: sans-serif;
}

.box {
    width:auto;
    position:relative;
    float:left;
    overflow:visible;
    border:2px;
    border-style:solid;
    border-color:green;

    padding-top:3px;
    padding-bottom:3px;
    padding-right:5px;
    padding-left:5px;

    margin-top:2px;
    margin-bottom:2px;
    margin-right:2px;
    margin-left:2px;
}

Answer №1

When it comes to the behavior of your left margin on a single line, it appears that your text "example" is experiencing some issues.

To address this, make sure to update your CSS class .tekstinpaikka as follows:

.tekstinpaikka {
    position:absolute; /*UPDATED*/
    left:15px;
    margin-top:-40px;/* MODIFIED FROM 'TOP¨:*/
    width:auto;
    border:2px;
    border-style:solid;
    border-color:yellow;
    background-color: #CCC;
    text-align:left;
    color:black;
    line-height: 16px;
    font-weight: bold;
    font-size: 16px;
    font-family: sans-serif;
}

Check out the FIDDLE for more details.

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

Achieving and accessing multiple left panels in Jquery/CSS and automatically adjusting the main content container

Delving deeper into advanced CSS and JQuery for a unique layout, I've hit a roadblock. It seems like I might be overlooking something obvious or this could require more intricate scripting to achieve. Despite days of searching, I haven't come acr ...

Password confirmation on the login screen will be displayed in a single line

As someone who is relatively new to HTML/CSS, most of what I have learned has come from this platform or by searching for answers online. I am nearing completion of my assignment, but I am struggling to figure out how to display two label words on the same ...

Transforming RGBA, HSL, and HSLA color values into RGB format, or encapsulating them within a java.awt.Color instance

Seeking information on algorithms that can convert RGBA, HSL, and HSLA colors to RGB colors, or a Java library that performs this conversion and returns a java.awt.Color object. Any recommendations or assistance would be greatly appreciated! ...

When clicked, the size of a link will adjust

Having trouble with my code and CSS. The pagination in Vue is working fine, but the links are changing size on certain pages. When clicking on the first or second number, the links remain the same size. However, when clicking on the third or fourth link, ...

Using a loop to alter the selected value of a dropdown menu with jQuery

Presently, I am using a dropdown menu that displays all the years from 1970 to the current year. Currently, this functionality is achieved through embedded JavaScript within the HTML. My aim is to achieve the same result using an external file and jQuery, ...

Positioning a fixed div can result in the page being cut off on certain mobile browsers that are not

While there are numerous similar issues out there, the bug I am encountering feels unique. This issue involves a page with a div in position:fixed style, specifically affecting certain less common mobile browsers like Star Safari, DU Browser, and Tint Brow ...

Incorporate div classes based on conditions in XSLT version 1.0

Utilizing my database software, I can export my albums collection to HTML using an XSL template. After modifying the XSL template to support Bootstrap 4, I attempted to incorporate an alphabetical filter. Although I managed to create a JavaScript for filte ...

Using jQuery to insert a div class with PHP referenced

My variable stores a color name. Here is an example: <?php $myvar = blueColour; ?> I want to apply this value to the body of an html page using jQuery: <script type="text/javascript"> jQuery(body).addClass("<?php echo $myvar; ?>"); < ...

A guide to extracting row and column information from tables using div tags

I need assistance with extracting data from rows and columns that are represented by div tags within a table. This table does not use traditional tbody, tr, and td tags but instead presents the data in a UI grid view using div tags. Can anyone provide gu ...

Having more than one FAQPage featured snippet displayed on a single webpage

We are looking to incorporate FAQPage featured snippets using JSON-LD format. By utilizing the "See Markup" link on Google's page, we were able to generate a sample featured snippet that suggests all questions should be within one <script> tag. ...

The function does not get activated when mouseover event is triggered with AddEventListener

I am attempting to create a series of radio buttons, each with its own AddEventListener function. However, I am encountering issues while using the code below within a while loop that retrieves data from a MySQLI table: echo ' <script> do ...

Emphasize the content within the table cell

Currently, I am working with an HTML table that is being generated by Java. My goal is to highlight the text within a table cell without changing the background color of the entire cell. I should mention that I am aware of the option to achieve this by ma ...

Alter the color of the span text without affecting the :before or :after elements

Can you change the text color of a span without affecting its :before and :after colors? Is it possible to modify the color of the main text in a span element without altering the colors of the elements that come before and after it? Here is an example o ...

Does Javascript move beyond the for loop and then return to it?

Currently, I am working on creating a stopwatch in JavaScript that counts by milliseconds using setTimeout. However, I encountered an issue during the initial setup: var time = 0; function main() { for (var i = 0; i < 5; i++) { setTimeou ...

How about concealing one div and revealing another?

There are two divs, one named #loading and the other named #main; <div id="loading"></div> <div id="main"></div> The goal is to use JavaScript to display #loading for five seconds, then hide it and show the #main div. The #main di ...

You can submit a photo to a form as an attached file

I had a code that looked like this My goal is to simplify the process for users by allowing them to fill out additional information in a form without having to upload an image separately. I want to display the canvas image from the previous page in the fo ...

Video Player for Android Phones

I've been struggling with the HTML5 video tag for hours now and nothing seems to be working, despite checking various answers on this site. My goal is to load a video file on Android phones running version 2.3 and above. Any assistance would be great ...

Guide on extracting the multiline HTML content from a contenteditable div

insert this within ed lorem ipsum then press the button. Outcome: lorem<p>ipsum</p> how can I achieve this: <p>lorem</p> <p>ipsum</p> I'm using Chrome, latest version document.execCommand("defaultParagraphSe ...

Methods to disregard class prefix in css document

When I inspect elements in the Chrome console, I notice styles applied to certain divs/buttons like this: /* Sample Chrome browser styles */ .ItemClass1-0-3-171.ItemClass2-0-3-173: { background-color: "red" } I'm wondering how I can def ...

Specialized dropdown selection function not triggering upon click

I am facing a challenge in triggering an on-click function whenever a user selects an item from a dropdown menu. This is necessary because the default styling of the dropdown cannot be modified. My objective is to update a field with the selected item&apo ...