How can I create a responsive design for my div elements?

I am facing an issue with responsiveness in my div container. Inside the square-shaped frame, I have a h2 tag that does not adjust properly when viewed on different devices such as mobile and browsers. Despite setting up media queries to make it responsive, the h2 tag remains outside the frame when shrunk. How can I ensure that the h2 tag stays inside the frame and adjusts its size accordingly?

View picture

home.js:

function Home() {

  return (
    <div className="home-page">

      <div className="home-header">

        <div className='home-first>
          <h2>BAROO</h2>
      
        </div>
      </div>
    </div>


  )
}

export default Home

Home.css:

.home-page {
    display: flex;
    flex-direction: column;
    flex: 0.65;
    max-width: 100%;
    width: 100%;
    background-color: #00ACFE;
  }

.home-header {
    flex-direction: column;
    display: flex;
    border-radius: 20px;
    background-color: rgb(200, 244, 244);
    max-width: 90%;
    margin-left: 65px;
    margin-top: 0px;
    height: 700px;
    width: 100%;
  }

  
  h2 {
    font-size: 100px;
  
    transform: translate(-50%, -50%);
    margin-left: 700px;
    margin-top: 200px;
  }
  @media screen and (max-width: 800px) {
    .home-header {
      max-width: 90%;
      margin-left: auto;
      margin-right: auto; 
      
    }
    .home-first >h2{
      font-size: 100px;
      width: 100%;
    }
    
  }

Answer №1

It appears that the use of transform: translate(-50%, -50%) and margin-left: 700px was somewhat confusing, considering you wanted the content centered. I have resolved this by adding align-items: center; to the .home-header section.

Check it out on codesandbox for more details.

Answer №2

Ensure center alignment on mobile screens by setting margin-left:auto; margin-right:auto;

@media screen and (max-width: 800px) {
  .home-header {
    max-width: 83%;
    margin-left: auto;
    margin-right: auto;
  }
}

Answer №3

Consider deleting the flex-direction: column; property within the .home-header {} selector.

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

Iterate over the object to verify if the field contains an empty array, then output null

Looking for help with handling empty arrays in an object: productDetails: { cislife: [], prime: [] } Is there a way to have null returned instead of an empty array if no values are available? For example, I'd like to determine if either t ...

What is the best way to eliminate a vertical line from an HTML table?

I am looking to remove specific vertical lines from an HTML table. There are only 3 vertical lines in total, and I want to remove the first and third lines. Below is my code: <html> <head> <style type="text/css"> .table1{ background: ...

Utilizing JavaScript, HTML, and CSS to incorporate images within circular frames

After finding inspiration from this question about rotating objects around a circle using CSS, I decided to modify the code to include images of Earth orbiting the Sun. The challenge was to make one image orbit another like a planet circling its star. Ear ...

IframeResizer.js is automatically readjusting its position to the top left corner (0,0) when a javascript event or

Within our internal web environment, I have implemented IframeResizer.js in a rather basic manner. The child page contains a table generated by a third-party application with mouseover/hidden and javascript tags associated with the TH elements (including a ...

What is the reason that I have to submit my mapped function twice in order for the updated state to show after modifying the array content?

When I try to display an image for the current value in the array item, the image does not display when I submit my value. I have to submit twice to display the value. Additionally, when changing the value and pressing submit, the content in the div does ...

What is the best way to clean HTML in a React application?

I am trying to showcase HTML content on the React front end. Here is the input I have: <p>Hello/<p> Aadafsf <h1>H1 in hello</h1> This content was written using CKEditor from the Admin side. This is how it appears on the React fro ...

Unexpected results with mix-blend-mode difference

I am struggling with making a black text element overlap a black div while ensuring that the overlapping part of the text appears white. I attempted to use the mix-blend-mode property, but it does not seem to be working as expected. Why is this happening? ...

Utilizing Ruby interpolation to dynamically select elements in Capybara's CSS selectors

Having trouble with invalid selector errors when attempting to locate an element using capybara This method is successful: page.find("#widget_amount_Standard") But I encounter issues when trying any of the following: credit_type = "Standard" page.find( ...

SSR with Material UI Drawer encounters issue during webpack production build meltdown

When I attempted to utilize the Material UI SSR example provided by Material-UI (Link), it worked successfully. However, my next step was to integrate the Material-UI Drawer into this example. To do so, I utilized the Persistent drawer example code also pr ...

Struggling to retrieve scope data within directive from controller in AngularJS

As a newcomer to AngularJS, I have utilized a service to retrieve data from the backend and received it in the controller. Now, my task is to parse these values and dynamically generate elements in a directive. However, when attempting to do so, I am encou ...

Facing a react-native-camera issue during android compilation

After attempting to update my react native project to the latest version (0.59.2), I encountered an issue when trying to execute react-native run-android with this error: Could not establish the dependencies of task ':app:preDebugBuild'. > Co ...

Miscalculation in PHP MySQL: Incorrect output when adding field 1 and multiplying field 2 by

In my MySQL table, there are 4 fields: product price cost, selling price, stock of products, and earnings per unit. For example: If the cost of our product is $100, we sell it for $120, and we have a stock of 10 units, the following code calculates the e ...

Deselect Radio buttons using Material UI

Is there a way to implement the functionality of unchecking radio buttons? For instance, when clicking on a radio button it gets checked, but if another field is clicked, that field gets checked instead. However, if a field that is already checked is cli ...

Remove a specific line from a PHP script

I have developed a system of alerts that allows users to delete an alert if they choose to do so. Below is the code for the delete button and table: <button type="button" name="Delete" Onclick="if(confirm('Are you sure you ...

Where did the match parameter go in the props?

I'm in the process of developing my first react application and I am looking to implement a Switch element to display components based on different routes. One of the routes includes a parameter. However, I have encountered an issue where the match at ...

Creating a seamless and interactive online platform

I am in the process of designing a website that has a sleek and dynamic layout, rather than just a static homepage. Let me explain further: Here is my current setup so you can understand what I am trying to achieve. By dynamic, I mean that when the page ...

Retrieve the store location value when clicked (Javascript)

I'm currently struggling to capture the value of a click in my Javascript code and I could use some help understanding how to achieve this. <span class="s-link"> <a class="s-link-pim-data" href="javascript:void(0);" target="_blank" title="O ...

What is the best way to rate a particular image?

while ($row = mysqli_fetch_array($result)) { echo ""; echo "<div id='img_div'>"; echo "<i class='fas fa-times'></i>"; echo "<img class='photoDeGallery' s ...

Combining two ng-model inputs in Angular for seamless data integration

New to Angular and seeking some guidance. I currently have two input fields, one for the area code and the other for the number. // Input field for area code <input area-input type="tel" required="true" name="area" ng-model="employee.home.area">&l ...

What could be causing the issue with the 100% height and 100% width not functioning properly on my ASPX page?

The CSS and HTML code work perfectly in an isolated test environment: body, html { height: 100%; min-height:600px; min-width:800px; overflow:hidden; margin:0;padding:0; } html {overflow:auto;} .fill {height:100%; width:100%; backgro ...