Struggles with arranging elements in the right position

Currently, I am in the process of learning CSS and working on developing a game that involves time and score.

In short, here is what I aim to achieve:

This is what I have so far:

You can find my progress on jsFiddle: http://jsfiddle.net/yZKTE/

CSS:

#boxbuttons {
    /*text-align: center;*/
/*  margin: 20px;*/
    display: block;
        top:0;
    left: 0;
    right: 0;
    padding:50px;
    /*width:900px;*/
}
#boxbuttons .button {
    text-transform: uppercase;
    padding: 5px 10px;
    margin: 5px;
    border-radius: 10px;
    cursor: pointer;
}
#rezz
{ 
   background:url(../images/score.png) left top; 
   width:35px;
   height:35px;
   background-repeat:no-repeat;
}
#counter{
    margin-left:50px;
}
#time
{ 
   background:url(../images/time.png) right top; 
   width:35px;
   height:35px;
   background-repeat:no-repeat;
}
#ttime{
    margin-right:50px;
}

HTML:

  <span id="boxbuttons">
    <span class="button" id="rezz">
      <span id="counter">0</span>
    </span>
      <span class="button" id="time"><span class="button" id="ttime"></span></span>
  </span>

Answer №1

There are numerous factors contributing to this issue.

To address it, start by "shrink wrapping" your outer div. This adjustment ensures that any floated elements will align to the right of the parent div, rather than the outermost one. To achieve this effect, add the following CSS code and observe how the width of the #picbox div adjusts to fit its contents:

#picbox {
    display: inline-block;
}

The current #boxcard CSS includes margin: 0 auto;, which centers the div. Remove this line to align the #boxcard div flush against the left side. Introduce some margin-left instead to ensure proper alignment with the header, like so:

#boxcard {
    -webkit-perspective:1000;
       -moz-perspective:1000;
        -ms-perspective:1000;
         -o-perspective:1000;
            perspective:1000;
    display: table;
    margin-left: 50px;
    width: auto;
    z-index: 1;
}

Finally, adjust the positioning of the #time div by floating it to the right. Rename #time to #boxbuttons #time to overwrite existing #boxbuttons .button styles. Float the element to the right using float: right;, remove any set width for auto sizing, include padding on the left, and modify the background positioning to separate the time and clock image effectively:

#boxbuttons #time { 
   background:url("http://remake.hr/memtest/images/time.png") left top; 
   height:35px;
   background-repeat:no-repeat;
   float: right;
   padding-left: 30px;
}

These adjustments should cover all necessary modifications.

http://jsfiddle.net/yZKTE/6/

Answer №2

Revise the #time css as follows:

#time
{ 
   background:url("http://remake.hr/memtest/images/time.png") right top; 
   width:100px;
   height:35px;
   background-repeat:no-repeat;
   display: inline-block;
   float:right;
}

The default behavior of the span HTML element is display:inline, meaning that attributes like width and height do not apply. By changing it to display:inline-block, we can use the width attribute effectively. The width was adjusted to 100px for better visibility, and float:right was added to position the element on the right side within its parent container.

http://jsfiddle.net/yZKTE/1/

UPDATE:

To shift the time display to the right of the clock icon:

#time {
  background: url("http://remake.hr/memtest/images/time.png") left top;
  width: 145px;
  height: 35px;
  background-repeat: no-repeat;
  display: inline-block;
  float: right;
  line-height: 35px;
  padding:0!important;
}

#ttime {
  float: right;
  font-size: 35px;
  line-height: 35px;
  margin: 0!important;
  padding: 0!important;
}

http://jsfiddle.net/yZKTE/4/

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

Release a stationary element upon scrolling down the page

I have a calculator feature on my website which was coded in php. At the end of this calculator, there is a section that displays the results. While the results div works properly on desktop, I am looking to implement a fix for mobile devices. Specificall ...

Implementing Twitter Login with Vue, Vuex, and Firebase

Exploring a Twitter login option for my sports social media dashboard project, I followed a helpful tutorial. While I've successfully implemented the HelloWorld component and retained the app.vue and main.js components, I encountered an error stating ...

Using jQuery to dynamically add li elements with AJAX and using the Append and Prepend methods

Having a little trouble here. Here is the HTML snippet: <ul class="buildings-list"> <li class="gchoice_20_0"> <input name="input_20" type="radio" value="House" checked="checked" /> <label for="choice_20_0" id="label_ ...

Encountering a syntax/parse error while utilizing jQuery within Velocity code

<script type="text/javascript> (function($, win) { function myCustomInit () { var self = this; var options = { 'params' : "userId=" + userId; }; self.init = function() { self.initButtonAction(); }; ...

Issues with React in a Production Environment

After successfully developing a react app and express API that worked correctly in localhost, I decided to move my API to a digitalocean droplet. The droplet only had an IP address and used HTTP. While utilizing the API from the react app in development m ...

The JS Map displays only the final outcome

Could someone help me understand why the map function is only displaying the last result instead of all? let err = { email: false, password: false, surname: false, lastname: false, firma: false, url: false }; ...

What is the process for fetching the chosen outcome from a subsequent webpage using HTML?

How can I display selected cities on a different webpage after clicking a button? Currently, I can only get the results on the same page. For example, if a user selects NYC and Delhi, those cities should be displayed on another HTML page. ...

Execute a jQuery function every time the class of the parent container div changes

I am seeking to trigger the function below whenever its containing div parent <div class="section">...</div> transitions to an "active" state, for example: <div class="section active">...</div> $(".skills-grid__col").each(function ...

I'm seeking guidance on how to delete a specific ul li element by its id after making an ajax request to delete a corresponding row in MySQL database. I'm unsure about the correct placement for the jQuery

I have created an app that displays a list of income items. Each item is contained within an li element with a unique id, along with the item description and a small trash icon. Currently, I have implemented code that triggers an AJAX call when the user cl ...

Transitioning with a CSS cubic-bezier function results in a noticeable jump of the content

My transition in an accordion list is using cubic-bezier(0.68, -0.55, 0.265, 1.55), but the issue I am facing is that the content below is also 'jumping'. Does anyone have suggestions on how to create space below my accordion (ul list) so that w ...

Dealing with errors in React by utilizing the setState function

Encountering an issue while trying to update the state of a single component. A warning message states: Each child in an array or iterator should have a unique "key" prop. The list was created within the state. The intention is to update the list upon c ...

Extracting data from an array using Angular

Currently, I am developing an Angular application that involves handling an array structured like the one below. [ { Code: "123", Details:[ { Id: "1", Name: "Gary" }, { ...

Tips for implementing jQuery functions such as lightbox and other features on a page loaded via ajax requests

I have a specific requirement for my page. I designed a section to display various departments, where clicking on $('.getDetails') will reveal a list of employers from each department along with some details. Furthermore, clicking on an employer& ...

Create a custom key in SJCL that has an expiration time set for automatic deletion

My current project involves encrypting and decrypting data on the client-side using the SJCL library. However, I have a specific requirement that the encryption key must expire after a certain scheduled time. So my question is this: Can a key with an e ...

Is there a way to refine results based on geographic location?

Hello fellow coders! I need assistance finding a lightweight JavaScript code that can filter based on geographical location. This script needs to first determine if the GPS is enabled or not. If disabled, redirect to www.no.com. If enabled, it should chec ...

Is there a way to set up a local npm module directory without using symlinks

Here is a breakdown of the file structure in a simple way. /my-module ..package.json /my-app ..package.json I am trying to have my-app install my-module locally. This is what I have attempted: "dependencies": { "myModule": "../my-module" } The opti ...

Could my HTML security measures be vulnerable to exploitation?

I have successfully developed a function that accomplishes the following: It accepts a string as input, which can be either an entire HTML document or an HTML "snippet" (even if it's broken). It creates a DOMDocument from the input and iterates throu ...

What methods can be used to construct components using smaller foundational components as a base?

Is there a more elegant approach to constructing larger components from smaller base components that encompass common functionalities, akin to an interface in the OOP realm? I'm experimenting with this concept, but it feels somewhat inelegant. Repor ...

Encounters a fault while processing the php output

Displaying an error in the query The browser is showing the correct answer. $.ajax({ type: "POST", url: url, async: true, contentType: " charset=utf-8", dataType: "XMLHttpRequest", success: func ...

What is the title of a document that is linked behind an HTML link?

I am seeking a way to automatically retrieve documents from web pages using a Python script. The links in the HTML pages appear as follows: href="https://foo.bar/view.php?id=123456" When clicked on in a web browser, these links open the document with its ...