Align Horizontal Fixed Element

<html>
    <head>
        <style>
            #rectangle {
                position: absolute;
                right: 0;
                bottom: 0;
                width: 150px;
                height: 200px;
            }
        </style>
    </head>
        <body>
            <div id='rectangle' style='background-color:red;'></div>
            <div id='rectangle' style='background-color:green;'></div>
            <div  id='rectangle' style='background-color:black;'></div>
        </body>
</html>

This code demonstrates three boxes displayed side by side using CSS. The intention is to have these boxes positioned at the bottom-right corner of the page without affecting the rest of the content, accomplished through the use of position:fixed. These chat boxes are intended for communication purposes.

Answer №1

Check out the jsbin I made just for you: http://jsbin.com/ikulem/13/edit Remember, when working with multiple elements, use classes instead of IDs for styling.

Here is the CSS code:

#footer {
    position: fixed;
    right: 0;
    bottom: 0;
}
.rectangle {
    float: right;
    width: 150px;
    height: 200px;
}

And the HTML code:

<html>
<head>
</head>
<body>
  <div id="footer">
    <div class='rectangle' style='background-color: red;'></div>
    <div class='rectangle' style='background-color: green;'></div>
    <div class='rectangle' style='background-color: black;'></div>
  </div>
</body>
</html>

Answer №2

<html>
<head>
<style>
.rectangles {
    position:absolute;
    right:0;
    bottom:0;

}
.rectangle {
    width: 150px;
    height: 200px;
    float:right;
}
</style>
</head>
<body>
<div class='rectangles'>
    <div class='rectangle' style='background-color:red;'></div>
    <div class='rectangle' style='background-color:green;'></div>
    <div class='rectangle' style='background-color:black;'></div>
</div>
</body>
</html>

Note that it is recommended not to use IDs if the same styling is applied multiple times on a page.

Answer №3

Here is a quick and simple solution

<body>
  <div class='square' id="blue"></div>
  <div class='square' id="yellow"></div>
  <div class='square' id="purple"></div>
</body>

below is the css code

#container{
    position:relative;
    left:0;
    top:0;
}

.square {
    display: block;
    width: 100px;
    height: 150px;
}

.blue{
    background:blue;
}

.yellow{
    background: yellow;
}
.purple{
    background:purple;
}

view related jsfiddle: http://jsfiddle.net/abc/123/

Answer №4

Hey there! I just wanted to share that I managed to tackle this using a JavaScript function. Appreciate the help though!

    function realignChatWindows() {
        position=0;
        $(".shout_box").each(function(index) {
            console.log ( index );
            if (position == 0) {
                $(this).css('right', '0px');
            } else {
                width = (position)*(240+2);
                $(this).css('right', width+'px');
            }
            position++;
        });
    }

Answer №5

Initially, it is not permissible to utilize the same identifier thrice.

An alternative approach would be:

<div id='rectangle-01' style='background-color:red;'></div>
<div id='rectangle-02' style='background-color:green;'></div>
<div id='rectangle-03' style='background-color:black;'></div>

If you decide to adjust the identifiers, here is the corresponding CSS:

#rectangle-01 {
    position:fixed;
    right:0;
    bottom:0;
    width: 150px;
    height: 200px;
}

#rectangle-02 {
    position:fixed;
    right:150px;
    bottom:0;
    width: 150px;  
    height: 200px;
}

#rectangle-03 {
    position:fixed;
    right:300px;
    bottom:0;
    width: 150px;
    height: 200px;
}

A more efficient solution would involve utilizing classes. You could create a fixed-position div with 'right: 0' and 'bottom: 0', then include the chatboxes within:

<div id='chatboxes'>
    <div class='rectangle' style='background-color:red;'></div>
    <div class='rectangle' style='background-color:green;'></div>
    <div class='rectangle' style='background-color:black;'></div>
</div>

The corresponding CSS for this setup would be:

#chatboxes {
    positon:fixed;
    right:0;
    bottom:0;
}

#chatboxes .rectangle{
    float:left;
    width: 150px;
    height: 200px;
}

Answer №6

<html>
 <head>
  <style>
   #shape{
     bottom: 0;
     right: 0;
     position: absolute;
   }
   .rectangle{
     float: left;
     width: 150px;
     height: 200px;
   }
  </style>
 </head>
 <body>
  <div id="shape">
    <div class='rectangle' style='background-color:red;'></div>
    <div class='rectangle' style='background-color:green;'></div>
    <div class='rectangle' style='background-color:black;'></div>
  </div>
 </body>
</html>

This code functions as intended. Feel free to see it in action on this live demo!

To enhance the organization of the code, I suggest transferring the CSS rules to a separate file and avoiding inline styles for background colors. Instead, define classes in the CSS for each color:

CSS File:

.red{background-color:red}
.green{background-color:green}
.black{background-color:black}

HTML Code:

<div id="shape">
  <div class='red rectangle'></div>
  <div class='green rectangle'></div>
  <div class='black rectangle'></div>
</div>

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

How can I avoid anti-aliasing in browsers when enlarging images?

Back in April 2012, Google's Chart Image API became deprecated but it was possible to generate QR codes using it. Although I know that I can adjust the size of the image produced by the API, I prefer to simply use CSS along with the width and height ...

Attempting to grasp the correct method for understanding For loops

Lately, I've been diving into teaching myself Node.JS and it has been quite an enjoyable experience. However, I've hit a frustrating roadblock that is really causing me some grief. For some reason, I just can't seem to grasp the concept of F ...

The alias for the last item in a nested ng-repeat loop will consistently evaluate to true

Within my code, I am utilizing two nested ng-repeat functions and I am looking to change the $last variable to something different for each level - let's say outerLast and innerLast. I attempted to achieve this by using ng-init="outerLast= $last" and ...

Using the CSS property `absolute` can result in the input element shifting when entering text in Chrome

My grid layout is causing some issues with the search box placement. Whenever a user starts typing in the input box, it jumps to the other side of the page. After investigating, I realized that the culprit is the position: absolute property. Oddly enough, ...

Is there a way to logout when the select event occurs using the key?

I am trying to figure out how to log out the key value when the select event is triggered. Specifically, I want to access the key={localState.id} within the <select></select> element in my HTML. This key value is crucial for a conditional stat ...

AngularJS allows users to easily select and copy all text from both div and span elements within a specified range. This feature makes it

I am working on implementing a select all feature using AngularJS for text displayed in a structure similar to the one below. Once all the text is selected, users should be able to press ctrl + c to copy it. <div ="container"> <div class="header ...

The positioning of the text appears to be in the center, but it is actually

Currently, my text "lorum ipsum" is centered in CSS, but I want to align it to the left and add padding on the right later. Can someone explain what I've created here? #ubba { font-family: "Open Sans", sans-serif; font-size: 20px; ...

Customizing the layout of div elements with Twitter Bootstrap for a responsive design

Utilizing Bootstrap's responsive style sheet, I have organized 4 squares in divs that span 12 columns - |3|3|3|3|. However, when I access this layout on a mobile browser, it displays as: |12| |12| |12| |12| My desired display format is: |6 ...

Bootstrap struggles to create panels of uniform size

Here is the code snippet I am currently working with: <div class="col-md-4"> <div class="panel panel-default"> <div class="panel-heading"> <h4><i class="fa fa-fw fa-tasks"></i> Extreme Performance</ ...

Tips for defining a dynamic class variable in React with Flow

I am working with a map that assigns a reference to items, specifically in this scenario it is a video. const ref = this[`video-${index}-ref`]; I am seeking guidance on how to properly type this using Flow. The number of indexes may vary. ...

Issue with Angular / SCSS where animation is not being executed on the specified element

I have created a post component with a comment section. However, when I click on the comments, I want them to display smoothly with a nice animation effect. Even though I have added the necessary code for animations, it doesn't seem to work as expecte ...

The process of generating an efficient build gets stuck and never finishes

I am currently facing an issue while attempting to build my React app. Whenever I execute "npm run build," the terminal gets stuck at "Creating and optimized production build..." and doesn't complete the process. I have tried running this on a system ...

<a href> click here to append a new query parameter to the existing ones

Is there a way to create a link that will add a query parameter to the current URL instead of replacing all existing ones? Here's what I'm looking for: If the current URL in the browser is example.com/index.html, clicking on it should lead to ...

Experiencing a lack of desired outcome in Outlook when using simple HTML with table elements

When creating a template for Outlook, I encountered an issue where the logo appeared on the right and the link text was on the left, which is the opposite of what I wanted. How can this be resolved? <center> <table width="600px;" style="margin:au ...

To link the information within the angularJS controller

I've recently generated a div element dynamically within the controller function of my AngularJS application. However, I'm facing an issue where the data is not binding as expected inside this div element. Here is a snippet of my code: function ...

How can I showcase the selected file using jQuery's querySelector?

I have successfully implemented a file upload feature using jQuery querySelector. Now, I am looking for a way to display the selected file name in a span element after the user selects the file. Here is my HTML code: <span id="filename"></span&g ...

An error has occurred with TokBox: OT.Session is unable to connect because the session has already been declared as

I encountered a similar issue but I'm struggling to make sense of what's going on. I have created a .Net page that includes all the necessary TokBox methods for subscribing. The process involves launching a new window (video monitor for multiple ...

Resetting the form and validation in AngularJS post form submission

I need help resetting a form and all validation messages after submission. Check out my code on plunker: http://plnkr.co/edit/992RP8gemIjgc3KxzLvQ?p=preview Here is the code snippet: Controller: app.controller('MainCtrl', function($scope) { ...

Forward the value of the selected radio button

Currently, I am focusing on this code snippet. <html> <script> var submit = document.getElementById('btnFormSubmit'); submit.addEventListener('click', submitForm); function submitForm(event){ event.preventDefault(); event. ...

Using Framework7 and AngularJS to efficiently load pages

When creating a phone application using phonegap, AngularJS, and Framework7, I encountered an issue with the page swapping functionality of Framework7. The problem arises because Framework7 injects new HTML pages into the DOM dynamically when a user click ...