Creating a website with a responsive layout using CSS absolute positioning

Is there a way to make this css code responsive for a website? I believe I need to use:

@media (min-width: 700px) and (max-width: 1150px) {

    #div {position: absolute; left: 149px; top: 61px;}

    #div2 {position: absolute; left: 249px; top: 81px;}
    #div3 {position: absolute; left: 279px; top: 181px;}
    #div4 {position: absolute; left: 449px; top: 121px;}
}

However, I have multiple div tags that need editing. Is there a quicker solution? Making changes to around 45 divs seems like a daunting task. Any advice would be greatly appreciated as I am new to this.

Answer №1

In order to ensure responsiveness, it is recommended to avoid using px units and opt for using % values instead.

There are tools available such as the one found at that can assist in converting px values to % values.

Additionally, excessive use of absolute positioning may not be necessary for responsive design. Absolute positioning can hinder the floating effect that is essential for responsiveness.

Is there a quick method to style multiple divs?

You don't have to individually style each div. It might be more efficient to use a shared class instead of targeting each div separately with IDs like #div2 or #div3 if they have the same layout.

To apply css styles to all divs:

div {
   width: 40%
}

To apply styles to a specific container:

HTML:

<div id='unique'>content</div>

#unique {
   width: 40%
}

To apply styles to certain containers (but not all):

HTML:

<div class='flat'>content</div><div class='flat'>content</div>

.flat {
   width: 40%
}

or

#div2, #div3, .flat {
   width: 40%
}

For further information on CSS basics, consider this concise css introduction:

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

Issue with the Z-Index property not functioning as expected on unordered lists within a dropdown menu

I have a dropdown menu that opens to the left, but it is displaying underneath the content. I attempted adjusting the z-index of the content to 1 and the dropdown to 2, however, this did not resolve the issue. Here is a sample in jsFiddle: https://jsfiddl ...

Can a form be selected and submitted using only its class as a selector?

When trying to select and submit a form using only the class as a selector, I encountered an issue: $("form.class").submit(...) doesn't seem to work... however: $("form#id").submit(...) works perfectly fine. Any idea what could be causing this di ...

Ways to utilize gridster by accessing the nativeElement of ElementRef

This issue is specific to the Firefox browser and does not occur in Chrome. My goal is to access the nativeElement for the gridster element. The version of angular-gridster2 being used is v17.0.0. In the HTML code: <gridster [options]="opt ...

PHP consistently selects the final radio button element

Having an issue with submitting data from radio buttons to an ajax request for database transfer. -html <form class="siteInfo" action="ajax/site.php?nr=<?php echo $_GET['nr']; ?>" method="POST"> <input type="radio" name="transpor ...

Activate the fadetoggle function to smoothly transition and fade in

Is there a way to implement jQuery fading in when an element becomes visible? Check out this code snippet for reference: http://jsfiddle.net/IntelandBacon/nWscz/ $('.expand').click(function () { $(this).next().css("visibility", "visible"); ...

Is this the correct method for constructing a class in CSS?

What is the correct way to style a class with CSS and write HTML code? .first{ color:red; } Here is an example of HTML code: <class id=first> <p> some text </p> <p> some other text </p> ...

Adjust CSS property values using positive and negative numbers

My HTML content looks like this: https://i.sstatic.net/qEuVw.png I have a padding of 70. I attempted to decrease the padding by adding another CSS rule like this: padding-top: -20px !important What I'm trying to achieve is to combine the existing ...

Position the Bootstrap footer element at the bottom of the page

On a custom HTML page that I created, I decided to include a footer using Bootstrap. In this example, it demonstrates how the footer can be positioned at the bottom of the page without being placed inside a container element (directly within the body eleme ...

Having a fixed bottom line bar that does not affect the length of the div when

I am working on creating an input field with a rounded bottom line. My goal is to make the main div expand or contract based on the length of the input, with specified minimum and maximum lengths. https://i.sstatic.net/REqld.png Instead of taking up the ...

Is it possible to create several XMLHttpRequests for various <li> elements upon clicking on them individually?

Today, I was experimenting with XMLHttpRequest to fetch news headlines from 10 different countries using the NewsAPI. I created 10 <li> tags for each country and assigned them an onclick function that triggers a JavaScript function to append the coun ...

Achieve the sticky effect for text in a HTML div using CSS to keep it anchored to the

Seeking advice on how to create a floating box that remains in the bottom right corner of a div using CSS. Any tips or suggestions are appreciated! (Here's an example of what I'm aiming for: https://i.stack.imgur.com/DkD5C.png) ...

Achieving a fixed Bootstrap navbar at the top along with a sidebar: A comprehensive

As I work on developing a webpage that includes both a sidebar and a navbar, it is crucial for me to ensure that the navbar remains fixed at the top for an improved user experience. Problem Statement: However, when I utilize the built-in fixed-top Bootst ...

What is the best way to align a dropdown menu in Bootstrap 5?

When working with Bootstrap, I discovered two classes, 'dropdown-menu-end' and 'dropdown-menu-start', that almost perfectly suit my needs for a dropdown menu. However, what I truly desire is to have the dropdown menu centered on the web ...

Visual Studio is not recognizing at-rules

Currently implementing code found at this URL: This code includes: @-webkit-keyframes moveclouds { 0% {margin-left: 1000px;} 100% {margin-left: -1000px;} } @-moz-keyframes moveclouds { 0% {margin-left: 1000px;} 100% {margin-left: -1000px;} } @-o-keyframe ...

What is the best way to display a single instance of a React component that is declared in multiple locations within the app?

Imagine I have 2 main components, A and B. Now, component C needs to be created inside both A and B. How can I guarantee that the same exact instance of C is generated in both places? Essentially, I want them to stay synchronized - any changes made to one ...

Harvesting feedback from the Google Play Store app portal

import time from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys ...

Creating a dynamic menu structure by tailoring it to the specific elements found on each page

Currently, I am facing issues while attempting to generate a dynamic menu based on the elements present on the page. Is there a way to develop a menu using the following code structure?: <div class="parent"> <div class="one child" id="first"& ...

The CSS Scroll-Snapping feature seems to be overlooking one specific element that it should be snapping to

Currently, this website is designed to work exclusively for mobile devices. When viewed in Chrome's mobile view using the inspector, everything appears to be functioning correctly. However, when accessed through Safari or on an actual mobile phone, th ...

Choose a division of an element within an embedded frame

Two different pages on the same website, Home.html and Page2.html. Home.html contains the following code: <html> <iframe id="one" src="page2.html" style="display:none"></iframe> <div id="container"> <h1& ...

Error in Google Translate API AttributeError

Despite changing the gtoken on googletrans stopped working with error 'NoneType' object has no attribute 'group', I am still encountering the "AttributeError: 'NoneType' object has no attribute 'group'" error. Howeve ...