Align an element to the right side of the webpage using CSS

I've been struggling to align elements to the right side of the page using various methods like float and flex, but nothing seems to work. To make it easier to understand my issue, I've attached a picture that illustrates what's going on. I'm not sure if there's an error in my code, so I'd appreciate some help troubleshooting this problem. Thank you!

https://i.sstatic.net/sqjRh.png

Home.js:

import React from 'react';
import "./homeStyle.css";
import { Navbar, NavItem, NavDropdown, MenuItem, Nav, Form, FormControl, Button } from 'react-bootstrap';
import "./components/containers/Menu.css";
import "./homeScript";
import { Widget } from '@typeform/embed-react'
import logo from "./components/img/logo.png";

export default function Home() {
    return(
        <div>
        <div className='App tc f3'>
               <Navbar bg='dark' expand='lg'>
                 <Navbar.Brand href="">
                    <img src={logo}/>
                 </Navbar.Brand>
                 <Navbar.Toggle aria-controls="basic-navbar-nav" />
                 <Navbar.Collapse id="basic-navbar-nav">
                   <Nav className='ml-auto'>
                     <Nav.Link href="#home"><button type="button">Login</button></Nav.Link>
                   </Nav>
                 </Navbar.Collapse>
               </Navbar>
             </div>
              <section id="home">
              <div className="inner-width">
                <div className="content">
                  <h1 />
                  <div className="buttons">
                    <button>Not Prepare to Part Yet? Click to Learn More</button>
                  </div>
                </div>
              </div>
            </section>
          </div>
    )
}

CSS:

*{

margin: 0;
  padding:0;
  text-decoration: none;
  font-family: 'Montserrat', sans-serif;
  box-sizing: border-box;
}
#home .inner-width {
  display: flex;
  align-items: center;
  justify-content: right;
  height: 100%;
  text-align: center;
}

#home .content {
  width: 100%;
  color: white;
  float: right;
}

#home .content h1 {
  font-size: 60px;
  margin-bottom: 60px;
}

#home .content h1::after {
  content: " Family ";
  animation: textAnim 10s linear infinite;
}

@keyframes textAnim {
  25% {
    content: " If not Now, When ? ";
  }
  50% {
    content: " Just in case. ";
  }
  75% {
    content: " For your loved one.";
  }
}

Answer №1

Utilize css properties like position: relative and position: absolute to align items effectively.

Here is a brief explanation on how to use these properties. Assign position: relative to the parent element, such as a section with the id of 'home'. Then, assign position: absolute to the child element that needs alignment. You can then use properties like right, top, bottom, and left to adjust the positioning of the child element.

As an example:

#home {
  position: relative;
  width: 100%;
  height: 90vh;
}

.content {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  -webkit-transform: translateY(-50%);
}

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

Why is the size not showing when I use driver.find_elements_by_class_name('radio')?

Whenever I attempt to scrape this particular link https://hbx.com/brands/reebok/club-c-85-1 When I make the following calls: driver.find_elements_by_class_name('radio') or driver.find_elements_by_class_name('hidden-xs') or driver.fi ...

I'm struggling to understand how to interpret this. The v-tab function seems to be generating a button with various properties, but I'm unsure which specific property is related to

The V-tab below generates the button known as the right one on the v-app-bar: https://i.stack.imgur.com/DzNmq.png <v-tab :to="'/demo'" active-class="text--primary" class=&quo ...

When elements are passed through components in Next.js, their style does not get applied

I have a unique component for the hero section of every page with varying content and heights. export default function CustomHero({ height, children, }: { height: string; children: ReactNode; }) { return ( <div className={`flex flex- ...

The React render function fails to display the components it is supposed to render

Upon running npm start, the browser opens localhost:3000 but only displays a white page. To troubleshoot, I added a paragraph within the <body> tag in index.html. Surprisingly, the text Hello World! appeared for less than a second before disappearing ...

WebSocket connections are unable to be established within a GraphQL client

While attempting to retrieve data from a GraphQL server using subscriptions, it is necessary to first establish a websocket connection. However, I encountered an error when trying to do so: Error: WebSocket connection to 'ws://localhost:8888/' f ...

What are some alternatives to using iframes?

Currently, I am working on a project for a client where I need to display multiple websites on a single page in a browser. To achieve this, I initially used the iframe element, but encountered an issue with the openerp frame. Despite setting up the openerp ...

When using Angular with mdbootstrap, the mdb-tabs directive will move to the end if the ngIf condition is true

Currently facing a challenge with a significant amount of code here. It is referenced as follows: "ng-uikit-pro-standard": "file:ng-uikit-pro-standard-8.3.0.tgz", I am attempting to display a tab between 1 and 3 if a certain condition ...

Tips for identifying which specific custom React component was clicked?

I am looking to enhance the functionality of a high-level custom component by making it double clickable. The ultimate goal is to be able to identify which specific component was double clicked. To achieve this, I have started using CustomCard from the @mu ...

The arrangement of React Material UI radio buttons appears haphazard

Within each row, I have set up multiple Radiogroups. Each row contains 3 FormControlLabels: import React, { Component } from 'react' import FormControl from '@material-ui/core/FormControl'; import Radio from '@material-ui/core/Radi ...

What is the best way to retrieve the value from a custom attribute in a React element?

Here is the HTML I am currently working with: <select onclick={this.handleClick}> <option key="1" value="aaa" data-plan-id="test"></option> </select> Below is the code for my handleClick event: console.log(e.target.value); ...

Display the HTML code in its formatted text output

I am currently facing an issue while trying to take input from the user using the WYSIWYG text editor plugin. When I attempt to display the text in a label or paragraph, all the HTML tags become visible. For instance, @string str = "<b>sample text&l ...

What is the correct way to showcase a list of errors below my component?

In my React 16.13.0 and Bootstrap 4 project, I'm looking to show a list of field errors based on a specific variable in my component. The current code I have is as follows: {props.errors && props.errors[props.name] && ( <Form ...

What is the best way to parse a JSON file and create a dynamic webpage using jQuery with the data from the

As someone who is new to working with Node.js and JSON, I am encountering some issues when trying to extract data from a JSON file. Below is the code that I have written: 'use strict'; const fs = require('fs'); let questsRawData = fs ...

Solving the Cache Busting Problem in ReactJS and Express

Is there a way to prevent cache busting by incorporating version numbers in the index.html file name (like index.hash.html) generated with html-webpack-plugin? I'm facing the issue where the browser continues to retrieve the old cached index.html file ...

Navigating the Path: Strategies for Caching Server-side Rendering in Next Js

I recently developed a Next JS Project along with a REST API implemented in PHP. My website is heavily reliant on API requests, which has prompted me to consider caching certain data points. I want to minimize the frequency of API requests for improved ef ...

Operate a seamless resizing of container divs within the Bootstrap carousel to avoid any sudden "jump" in size adjustments

In my current project, I am faced with the challenge of smoothly resizing container divs as users switch between image or video assets of varying sizes/heights within a Bootstrap carousel. Currently, the resizing process appears to be abrupt and not visua ...

How can I align a button in the center using Bootstrap 4?

<div class="container"> <div class="row"> <div class="col-xs-12 col-sm-12 col-md-8"> <div v-for="job in job"> <div class="text-center"> <h1>{{ job.job_title }}</h1> <p> ...

Use the accelerometer in JavaScript and Cordova to control the movement of an object, such as a ball

Having trouble figuring out how to move a ball using the accelerometer. Any tips on combining the accelerometer values with the ball movement? Waiting for accelerometer... <div id="heading">Waiting for heading...</div> <div id="ball" ...

Building a slider component in React: A beginner's guide

Having some trouble creating a React slider component. Despite updating the index, the image displayed doesn't change upon clicking the button. The goal is to have the image update based on the index position when the button is clicked. Here's my ...

What could be the reason for the hover class not functioning properly in Tailwind?

Looking for some help with styling a button in Next.js using Tailwind. Specifically, I want the background color of the button to change when hovered over. I've been experimenting with code like this: <button className="rounded-full bg-gradie ...