The CSS 'top' attribute is without impact

As I begin my journey with CSS, I am eager to grasp some of its behaviors.

In the CSS file, the following code is defined:

#spa {
position : absolute;
top      : 8px;
left     : 8px;
bottom   : 8px;
right    : 8px;

min-height : 500px;
min-width  : 500px;
overflow   : hidden;

background-color : #fff;
border-radius    : 0 8px 0 8px;
}

.spa-shell-head {
  top    : 0;
  left   : 0;
  right  : 0;
  height : 40px;
}
.spa-shell-head-logo {
  **top        : 4px;
  left       : 4px;**
  height     : 32px;
  width      : 128px;
  background : orange;
}

.spa-shell-head-acct {
  **top        : 4px;
  right      : 0;**
  width      : 64px;
  height     : 32px;
  background : green;
}

The HTML file contains the following code:

<body>
  <div id="spa">
    <div class="spa-shell-head">
      <div class="spa-shell-head-logo"></div>
      <div class="spa-shell-head-acct"></div>
      <div class="spa-shell-head-search"></div>
    </div>
    <div class="spa-shell-main">
      <div class="spa-shell-main-nav"></div>
      <div class="spa-shell-main-content"></div>
    </div>
    <div class="spa-shell-foot"></div>
    <div class="spa-shell-chat"></div>
    <div class="spa-shell-modal"></div>
  </div>
</body>

I am puzzled as to why changing the bold properties in the CSS code does not reflect on the elements themselves, especially the background color I have set for them.

For the full code, you can visit: http://jsfiddle.net/fu6dmhdt/1/

Answer №1

Neither the .spa-shell-head-logo nor the .spa-shell-head-acct divs are positioned, which is why the CSS properties like top, right, bottom, and left are not having any effect on them.

These positioning properties only work on elements that have a position value other than the default static. You can try giving them a position of relative to observe the changes - check out this Example.

Answer №2

The functionality of the Top, Left, Bottom, and Right properties varies depending on the position assigned. These properties work effectively when combined with either absolute or fixed positioning.

Answer №3

To effectively utilize the properties of top, left, right, and bottom, it is essential to declare the positions of the elements as either absolute or fixed. Otherwise, margining will be necessary for proper alignment.

Additionally, keeping all CSS in one place is recommended to avoid confusion as you add more styles to your project. Consolidating your styles can greatly simplify maintenance and updates.

We hope this information proves helpful for your design process.

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

Change the navbar brand in Bootstrap to be hidden on small screens like mobile devices

I am facing an issue with the navbar on my website where it expands in height when viewed on mobile devices due to not fitting into a single line. I have observed that if I remove the brand, it fits perfectly. However, I want to keep the brand visible on l ...

I aim to showcase particular cookies within an input field using jQuery

I am seeking a way to create a responsive page that showcases cookies. My goal is to have the output of a function automatically appear in the input value upon loading the page, instead of requiring a click event. Here is the code snippet I have been worki ...

Get the div to occupy the rest of the available height

I am facing a challenge with two divs on my webpage. The bottom one contains content that expands the highest. The page is set to 100% height and width using the CSS property position: absolute. <style> body, html { height:100%, width:100% } ...

Hovering into Transition Time

My article card has a transition on the top attribute of the info div, which is supposed to be smooth and last for 0.3 seconds. However, the description suddenly appears during this transition. I'm trying to figure out why this is happening and how to ...

Having trouble implementing a circular progress bar with a custom Tailwind CSS library, the desired effect is not being achieved

I am on a mission to create a circular progress indicator. Recently, I stumbled upon the daisyui library and its component called radial progress - The documentation mentions that: "Radial progress requires the use of the --value CSS variable." ...

The functionality of multiple UI-Views is not meeting the intended outcomes

I'm facing an issue with integrating multiple UI-views in my AngularJS dashboard app. Despite following the directory structure, I am unable to get it working as expected. This is how my directories are organized: index.html app/ app.js dash ...

Align text in the center of a static container

I am facing the challenge of aligning four h4 tags in the center of their respective fixed divs, all set to width: 100% to ensure their background-color: rgba(255, 255, 255, 0.5); covers the entire browser width. Despite trying various combinations of CSS ...

Authentication using a singular input

Struggling to design an input for a verification code with just one input instead of four. However, I am facing some challenges: The input is not responding correctly when clicked, it's a bit buggy and requires clicking at the end of the input to typ ...

Angularjs - Repeatedly reloading identical images

Whenever I use ng-src in the <img> tag and change the ng-src by clicking next or previous buttons, the browser reloads the image even though it's already loaded. This results in a not-so-smooth experience as the image is downloaded again before ...

How to Duplicate a Select Box Option in MySQL without Copying the Entire Field (Duplicate Only One Option)

I am in the process of setting up a database for an upload system, specifically using a select box to restrict the number of categories added to the database. <select name="category"> <?php $conn = mysqli_connect("localhost", "blah", "blah") or d ...

What are some techniques to ensure a bookmark retains its original style even when the cursor hovers over it?

My CSS skills are limited, so I am facing what may seem like a basic issue. On my website, I have a table of contents with links structured like this: <a href="#user-interface">User interface</a> Additionally, there is a bookmark in another ...

Changing a variable in an HTML file using a JavaScript file

I am working with JavaScript code that has been imported from another file containing a variable that I need to update in my HTML file. Is there a way to update the variable without directly inserting the JavaScript code into my HTML document? JavaScript ...

"Include the 'unsafe' prefix at the start of the URL in AngularJS

Whenever I attempt to access app://csttree?featuretype=cst_issue&verticalid=2132321&l1=3213&l2=3242 within my app, the URL gets parsed as ==> unsafe:app://csttree?featuretype=cst_issue&verticalid=2132321&l1=3213&l2=3242 Is ...

Having difficulty making Skrollr compatible with BootStrap 3 single page wonder

I am completely new to JavaScript, which is why I decided to use Skrollr. However, I have been facing some challenges in getting Skrollr to work properly on my webpage. I added the following code at the end of my page: <script type="text/javascript" sr ...

The function getComputedStyle(elem).getPropertyValue('fontSize') returns incorrect values when the font size of the element is specified in em units

My current issue involves trying to obtain the font size of an element in the following manner: getComputedStyle(MyTargetElement , "").getPropertyValue('font-size') The result is coming back as 16px, when it should actually be 14px. W ...

Utilizing jQuery to dynamically add or remove a class based on the selected radio button option

I am trying to achieve a functionality where checking one radio button will add a class to the label of another radio button, and unchecking it will remove that class. I have provided a Plunker example here. It seems simple but I'm having trouble gett ...

Ensure that the divs are properly aligned and construct columns within a single column

I've been working on creating a step bar that needs to adapt to any number of steps provided by the backend. Here's what I have so far: https://i.sstatic.net/cj4qZ.png It looks fine, but connecting the circles with bars would be beneficial. How ...

What is the best way to resize an HTML element to fill the remaining height?

I'm struggling with adjusting the height of a node-webkit app to fit the current window size. See below for an image depicting what I am aiming for. Intended Goal : HTML Markup : <body> <div class="header"> THIS IS A HEADER W ...

Innovative Tools for Interactive Sites and Dynamic Animations

I'm interested in developing interactive websites soon and I'm curious about the various technologies I can use to create an engaging web page. I know that HTML5 now supports drawing on a Canvas, even in 3D. Can you recommend any helpful tutoria ...

I'm having trouble making my carousel smaller and centering it on the page. How can I adjust it to be a more subtle feature on the page?

I'm having trouble adjusting the width and height of my images in the code. Whenever I set them to less than 100%, it messes up the layout and the images get cropped. I want them centered without taking up so much space. I've resized all my imag ...