What is the best way to align a div using position:absolute in a body that has a width of 100%, while maintaining equal spacing on the left and

How can I position a <div> with position:absolute so that it is spaced 20px from the left and right sides while maintaining a width: of 100%? Currently, I have applied margin: 0 20px 0 20px, but I am wondering if there is a way to achieve this without adding any additional inner or outer <div>. Can this be done within the existing structure?

(please do not remove the question, as I have already reviewed similar inquiries)

.navbar {

    position: absolute;
    width: 100%;
    height: 50px;
    background: grey;
    overflow: hidden;

}

.navbar ul {

    list-style-type: none;
    padding: 0px;
    margin-top: 0px;
    line-height: 50px;
}

.navbar ul li {

    float: left;
    margin-left: 15%;
    padding-left: 1%;
    padding-right: 1%;
    margin-top: 0px;

}


.navbar ul li a {

    color: white;
    text-decoration: none;
}


.navbar ul li:hover {

    background: #585858;

}

.daily {

    position: absolute;
    top: 70px;
    height: 110px;
    width: 100%;
    border: 1px solid black;
    margin: 0 20px 0 20px


}
    <div class="navbar">
        <ul>
            <li><a href="">HOME</a></li>
            <li><a href="">ABOUT</a></li>
            <li><a href="">INFO</a></li>
            <li><a href="">ME</a></li>
        </ul>   
    </div>
    <div class="daily">
    </div>
    <div class="aussen">

The left spacing appears correct, but I am having trouble achieving the same on the right side. What adjustments should I make to my code? - Open to suggestions for improvements as well :)

Answer №1

Here is a recommended solution:

.daily {
    position: relative;
    top: 70px;
    height: 110px;
    border: 1px solid black;
    left: 20px;
    right: 20px;
}

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

Is it possible to place this script above all of my content?

For instance, take a look at this script: I am currently working on designing my own homepage and I would like to include the above script. The homepage will consist of links, buttons, and other content. However, I'm facing an issue where the birds f ...

JavaScript still mentions a class that no longer exists

One of my elements has a class of .collapsed. When this element is clicked, a jQuery function is triggered to remove the .collapsed class and add the .expanded class instead. Even after the .collapsed class is removed, the function I have created continue ...

Tips on effortlessly updating the URL of your website

Despite seeing the question asked multiple times, I still find myself struggling to understand how to modify a URL or create a new HTML page that seamlessly integrates into a website without redirecting users. I am curious about achieving the functionalit ...

Trouble with aligning action buttons in rows or columns with CSS

I am working with an HTML table that has dynamically created rows and columns using AngularJS. I want to add an option where users can hover over a row or column and see a delete button icon that, when clicked, will remove that row or column. While this fu ...

Choose all div elements except for those contained within a certain div

Having trouble with an IE7 z-index fixer that's affecting specific elements. I'm attempting to select all divs, excluding those nested within a particular div. Below is the jQuery code I'm using, but it's not functioning correctly: & ...

Python Selenium is having trouble finding the elements

I've been struggling for hours to extract the specific text from a variety of elements on a website. I attached 2 images in hopes that they will help in identifying these elements by their similarities, such as having the same class name. The black un ...

Choose or deselect images from a selection

I am currently working on a feature for an album creation tool where users can select photos from a pool of images and assign them to a specific folder. However, I'm facing difficulty in selecting individual photos and applying customized attributes t ...

Determining the identity of an HTML element using its surrounding values

I have a webpage with a table displaying various services and their corresponding download buttons. Here is an example of the content: nov. service 1 [ click to download pdf ] nov. service 5 [ click to download pdf ] nov. service 3 [ ...

Obtain CONTENT from a separate CONTENT using JSExecutor

Having trouble selecting and clicking an element on a page due to the #document tag. Here is my latest attempt: var doc = (OpenQA.Selenium.Remote.RemoteWebElement)_driver.ExecuteQuery("return window.document"); doc.FindElementByXPath("//span ...

Utilizing JavaScript to target a specific div element and modify the href attribute

I am currently working on adjusting the links within my page using JavaScript. While I am able to select the div and the a element, I am encountering difficulties in changing the href attribute. Shopify utilizes a for loop to generate these objects, and i ...

Utilize the .mat-column-name attributes to apply custom styles to a nested component within Angular Material

Within the Child component, an Angular material table is created with columns passed as input: <table mat-table> <ng-container *ngFor="let col of columns" [matColumnDef]="col"> </table> @Input() columns: string[] T ...

Creating a dynamic table inside a flex-grow container without disrupting the layout: A step-by-step guide

Currently, I am in the process of designing a responsive layout using Bootstrap 5.3 which consists of a NavBar, SideBar, ContentPanel, and StatusBar. The goal is to ensure that the application always occupies 100% of the view-height and view-width, display ...

The dropdown menu is experiencing issues on a compact mobile display when using React Bootstrap

Utilizing a dropdown list on a compact screen such as mobile can result in a poor user experience when using the react bootstrap dropdown list. Are there any alternative libraries available that provide a more seamless action sheet appearance for Reactjs, ...

Utilizing PHP to Extract Information through cURL and HTML Parsing

Is there a way to search through an HTML page specifically for text contained within a particular div element? ...

Tips for including shared information across different ionic tabs

Is there a way to include some shared content, like a canvas, in between the content of different tabs in Ionic? I want this common content to be displayed across all tabs, while each tab still shows its own dynamic data below it. I attempted to add the c ...

A method for utilizing wildcards in conjunction with the .load function

Currently, I am utilizing jquery, jquery mobile, js, html, and css within Phonegap to develop my android/ios application. However, my understanding of js & jquery is somewhat limited. In my index.html file, I use .load to load other html files into s ...

What is the best way to showcase two div elements side by side within my carousel

/* Implementing slideshow functionality */ var currentIndex = 0; displaySlides(); function displaySlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); for (i = 0; i ...

Creating a custom loading spinner using HTML and CSS

I am looking to create a spinner using just the <input> element. The only element I can utilize is <input type="text" placeholder="Select Date" class="sel1" /> How can I use CSS to implement a basic spinner in this scenario? ...

What is the best way to arrange inline elements in RTL mode?

I'm currently working on creating an RTL version of the website, but I'm encountering a challenge with a specific layout: .content { width: 200px; } .content.rtl { direction: rtl; text-align: right; } <h5 class="content"> <sp ...

Soundtrack featured on the main page

Currently, I am trying to incorporate an audio file into my homepage without interrupting its playback when the user navigates to another page or title. Essentially, I want the audio .mp3 file to continue playing in the background seamlessly. I am currentl ...