What could be causing my elements to shift out of place?

Here is the box I created:

BOX

Now, I want to position another box near the input of the BET box.

<div id="x2"></div> <!-- HTML --->
/* CSS */
#x2{
    width: 40px;
    height: 40px;
    background: cornflowerblue;
}

The layout after adding the new box: BOX-AFTER

However, it seems to have affected the thin gray line and content below it. I am unsure why this happened.

Below is the HTML code:

<div class="gamebox">
        <div id="bet-and-chance-texts">
            <p id="bettext">BET</p>
            <p id="profittext"><i class="fa fa-btc" aria-hidden="true"></i> PROFIT</p>
        </div>
        <div id="bet-and-chance-input-boxes">
            <input class="default" id="userbet" onkeyup="checkBet()" value="0.00000000" placeholder="BTC" name="bet" autocomplete="off">
            <div id="x2">x2</div>
            <input readonly class="default" id="profitinput" onkeyup="" value="100" placeholder="BTC" name="bet" autocomplete="off">
        </div>
        <br>
        <div class="line-separator"></div>
        <div id="button-texts">
            <p id="roll">ROLL UNDER</p>
            <p id="payout">PAYOUT</p>
            <p id="chance">CHANCE</p>
        </div>
        <div id="buttons">
            <input class="hidden-boxed-input-roll" value = "50.00"/>
            <input autocomplete="off" id="newpayout" onkeyup="calculateChance()" class="hidden-boxed-input" value = "2.000"/>
            <input autocomplete="off" id="newchance" onkeyup="checkChance()" class="hidden-boxed-input" value = "50"/>
        </div>
        <br>
        <div id="rolldice-section">
            <button type="button" id="dicebutton" onclick="prepareRoll(authToken);" style="vertical-align:middle"><i class="fa fa-gamepad"></i> Roll dice</button>
        </div>
    </div>

And here is the CSS code:

.gamebox {
      height: auto;
      padding: 20px;
      width: 60%;
      font-family: Helvetica Neue;
      color: black;

      margin-top: 20px;
      margin-left: 20px;
      background-color: white;
  }
.line-separator{
    height:.5px;
    background: lightgray;
    border-bottom:.5px solid lightgray;
}
#x2{
    width: 40px;
    height: 40px;
    background: cornflowerblue;
    float: left;
}
input[class="default"]{
    padding: 12px 20px;
    margin : 0 auto;
    box-sizing: border-box;
    text-align: center;
    background-color: #E4ECF1;
    display: inline-block;
}
p[id="roll"]{
    display: inline-block;
    float: left;
    font-size: 13px;
}

p[id="payout"]{
    display: inline-block;
    margin-right: 25px;
    font-size: 13px;
}

p[id="chance"]{
    display: inline-block;
    float: right;
    font-size: 13px;
}
div[id=button-texts]{
    text-align: center;
}

I'm having trouble understanding why everything below the thin gray line is impacted. Any suggestions on how to resolve this issue?

Answer №1

Make this alteration:

<div id="y3">y3</div>

to :

<span id="y3">y3</span>

as the div element displays as a block and it is recommended to use the inline span instead

afterwards adjust your styling, eliminate float property and add some padding to #y3 :

#y3 {
   padding: 15px;
   width: 50px;
   height: 50px;
   background: skyblue;
}

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

What is the best way to replicate floats using flexbox?

Currently, I am exploring the possibility of using flexbox in a similar manner as floats. My main aim is to have one child element create a column on the right side, while the rest of the children form another column on the left side. The challenge is that ...

Having trouble with querySelector or getElementById not functioning properly?

Currently, I am in the midst of developing an experimental web application that features a quiz component. For this project, I have implemented a Python file to handle the questions and quiz functionalities. However, I have encountered an issue with the Ja ...

A guide on incorporating an event to multiple elements in vue.js

I am trying to implement a double-click event on multiple elements in Vue3. My goal is to create a table of contents data and add a double-click event to the checkboxes and favorite icons without using @dblclick="". I find it more convenient to assign a c ...

Is there a way to modify the border shape of items in the navigation bar?

Is there a way to achieve this particular shape when the current page is being displayed? https://i.stack.imgur.com/HELTM.jpg This is how my current code looks: current { transform: skew(-20deg); border: 1px solid white; color: black; background ...

Newbie: Troubleshooting Vue Errors - "Vue is not recognized"

I'm currently at the beginning stages of learning Vue and am practicing implementing it. However, I keep encountering the errors "vue was used before it was defined" and "Vue is not defined". Below are excerpts from my HTML and JS files for reference. ...

Adapting a CSS design

Having some trouble with creating a CSS style. Here's what I have so far: http://jsfiddle.net/WhNRK/26/ Originally designed for a label, but now attempting to modify it for something like this: <input type='radio' name='mcq' ...

Set the class of an element dynamically using ng-class and detect changes with ng-change

I want the input field to initially have the class .form-control-error. When the user clicks on the field and starts typing, I would like it to change to .form-control-success. I attempted the following code but couldn't get it to update. The ng-chan ...

An unusual visual anomaly (a small line appears) when hovering over a button in the web browser

There is a peculiar issue with some buttons on a web page where a strange line appears on the right side when hovering over the button. This problem only affects the first two out of three buttons, possibly because there is no fourth button to trigger the ...

Sliding out the sidebar menu with Jquery

Hey there! I'm currently working on implementing a swipe feature for the side menu bar. I have already added a click method in my code, but now I also need to incorporate a swipe technique. When the side bar is opened, I want to remove the inside im ...

The total height of the document's body in jQuery is not equal to the sum of the viewport height and the window's scroll top position at the bottom of the document

Why does the document height appear smaller than the window scroll top value plus the viewport height when I reach the end of the document? Shouldn't they be equal? I've been struggling with this issue for hours and can't seem to figure it o ...

Methods for concealing the title and date when printing web content using JavaScript

When utilizing the window.print method to print out a specific screen, I encountered an issue. I need to hide the date in the top left corner of the image as well as the title (not the big heading) which has been intentionally blurred. I've come acro ...

Is there a way to dynamically alter the background style of a div by clicking on it multiple times using Javascript?

I am attempting to create a calendar where each day changes its background color between blue and green when clicked, using JavaScript and CSS. It should function similar to a toggle feature. The default color is blue, and I have successfully made the days ...

showing errors in case the username does not match the specified pattern

As I work with symfony, one of the challenges is displaying errors when the username does not fit the specified pattern. How can this be achieved? {{ form_widget(form.username, {'attr':{'pattern': '[a-zA-Z]*'} }) }} ...

The Mysteries of Key Codes in JavaScript

I'm curious about the character codes used for keyboards. Recently, I came across an informative article discussing this topic. In particular, I am interested in finding out which key code to use when a user presses both the alt and down arrow keys s ...

Is it possible to exclusively focus on the specified data attributes?

Is there a method to specifically target the 'data-season' attribute with the value "winter"? This is my HTML: <li data-season="summer">summer <ul class="groups"> <li data-item="beach">beach</li> <li data-item ...

Updating values using jQuery when tags in a single table row are changed

In my current setup, I have a table structured as follows: <table> <tbody> <tr> <td> <input type="text" class="identifier" /> </td> <td class="name"> Some value < ...

The POST request did not yield an HttpResponse object; instead, it returned None

When I submit a selection from a dropdown form to views as a POST request, and then use this selection to query data from Django, I encounter an issue while trying to map Django models data to Highcharts following this approach. The error message "the view ...

After pressing submit, any associated links should automatically open in a separate tab

I have a homework assignment that requires creating a form with multiple elements, including a checkbox. Once this checkbox is checked, the links displayed on the resulting page should open in a new tab. The catch? I can only use HTML and CSS - no JavaScri ...

How can I extract the text enclosed in <li> tags using JavaScript?

Can someone help me with retrieving the text content of li tags? I managed to get a list of lis, but I'm having trouble assigning the text content to my country object. Snippet var lis = document.getElementById("navbar").getElementsByTagName("l ...

CSS3 columns causing <li>s to be cropped

I'm attempting to implement css3 columns with a list (<li>), but I'm running into some issues getting it to function properly. I have wrapped the <ul> in a div like this: .ul-container { -moz-column-width: 310px; -moz-column-gap ...