How can I modify this code to be more responsive using float or relative positioning without introducing any errors?

I'm currently struggling to create a responsive web page that adjusts to any screen size automatically. Here is the code I have so far, including both HTML and CSS. What changes can I make to ensure the elements are properly placed regardless of the screen size? When you view the full-page preview of the code snippet, you'll see how the final layout should appear. While I understand that the design may not be identical across all screens, it should maintain a clean and organized appearance without any overlapping or width issues. The goal is to achieve responsiveness through relative positioning and floats. Any solutions involving media queries are welcome, as long as they incorporate float and relative positioning. I've experimented with various approaches found online, but none seem to work effectively. Some even suggest that using relative positioning can hinder responsiveness - is this true? Introducing floats into the mix presents its own set of challenges, such as element overlap and background separation from elements. Even without floats, issues arise where only one between min-width and max-width seems to take effect while the other is chosen by the browser. Many resources advocate for using min-width and max-width properties to create responsive designs, yet when implemented in my code, inconsistencies and unexpected errors emerge that were not addressed in online tutorials. By exploring the provided code snippets and attempting to enhance their responsiveness, you will encounter unique challenges that require innovative solutions beyond conventional methods.

body {
  background-color: #d2691e;
  padding: auto;
}

header {
  padding-left: 32em;
}

h1 {
  text-decoration: underline red dotted;
  padding: 0.5em;
  background-color: black;
  color: yellow;
  width: 5.6em;
  min-width: 1.83em;
  max-width: 6.1em;
}

h2 {
  margin-left: 1.2em;
  width: 6.3em;
  background-color: #7cf000;
  min-width: 2.1em;
  max-width: 6.8em;
}

#duped {
  float: left;
  position: relative;
  left: 22em;
  min-width: 5em;
  max-width: 20em;
}

#mad {
  float: right;
  position: relative;
  top: 1px;
  min-width: 5em;
  max-width: 13.5em;
}

footer {
  float: right;
  background-color: #7cf000;
  min-width: 5em;
  max-width: 11em;
  position: relative;
  top: 16em;
  left: 11em;
}

#crushed {
  margin-top: 3.6em;
  background-color: #7cfc00;
  position: relative;
}

#rushed {
  outline: 3px solid orange;
  background-color: black;
  color: yellow;
  position: relative;
  top: 0.2em;
}

.groped {
  width: 7.5em;
  outline: 3px solid orange;
  background-color: black;
  color: yellow;
  min-width: 2.5em;
  max-width: 8.1em;
}

#success {
  outline: 3px solid orange;
  background-color: black;
  color: yellow;
  max-width: 8em;
  min-width: 2.5em;
}

#stoned {
  float: left;
  min-width: 2em;
  max-width: 11em;
}

#yes {
  background-color: #7cfc00;
}

#backoff {
  background-color: #7cfc00;
}

a {
  text-decoration: none;
}

a:hover {
  color: yellow;
  text-decoration: none;
}

a:active {
  background-color: black;
}
<!DOCTYPE html>

<html>

<head>

  <title>About me</title>
  <link rel="stylesheet" href="about me.css">

</head>

<body>

  <header>

    <h1>Crysis Surya</h1>
    <h2>Never give up.</h2>

  </header>

  <article>


    <section>

      <div id="stoned">

        <h3 id="rushed">Education</h3>

        <div id="crushed">
          <h4>High school</h4>

          <p>Raghava talent school</p>

          <h4>Intermideate College</h4>

          <p>Narayana Junior College</p>
        </div>

      </div>

    </section>

    <section id="mad">

      <h3 class="groped">Work experience</h3>

      <div id="backoff">

        <p>I worked at ice cream stone.</p>

        <p>I worked as a news distributor.</p>

      </div>

    </section>

    <section id="duped">

      <h3 id="success">Favourite things</h3>
      <div id="yes">

        <h4>Favourite foods</h4>

        <ol>
          <li>Veg biryani.</li>
          <li>My own recipe of sunfeast yipee noodles.</li>
          <li>Chapati</li>
        </ol>

        <h4>Favourite Websites</h4>

        <ul>
          <li><a href="https://courses.edx.org" target="_blank">Click me:- Edx</a></li>
          <li><a href="https://www.lumosity.com" target="_blank">Click me:- Lumosity</a></li>
          <li><a href="https://www.cambridgebrainsciences.com" target="_blank">Click me:- Cambridge Brain Sciences</a></li>
          <li><a href="www.facebook.com" target="_blank">Click me:- Facebook</a></li>
        </ul>

      </div>

    </section>

  </article>

  <footer>My contact information:-<br> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="780b19110b191508190c104b4a4j1da58eefce88949c">[email protected]</a>
    <br><br> fb/suryasaisampath
  </footer>

</body>

</html>

Answer №1

To implement responsive design, you can utilize media queries as shown below

@media only screen and (max-width: 768px) {
/* For mobile phones: */
body {
width: 100%;
}
/* Adjust the styles for tags, classes, and IDs based on your needs */
.class{
}
<tag>{
}
#id's{
}
}

If the viewport width is less than 768px, the above media queries will come into play.

Looking for more information? Check out this potential duplicate post: CSS Layout not working on mobile device

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

Generate a fresh row in a table with user inputs and save the input values when the "save" button is

HTML: <tbody> <tr id="hiddenRow"> <td> <button id="saveBtn" class="btn btn-success btn-xs">save</button> </td> <td id="firstName"> <input id="first" type="tex ...

Remove any javascript code from the ajax modal when it is closed or hidden

I am in the process of creating a music website that showcases songs along with their lyrics. One of the features I have added is a lyrics button that, when clicked while a song is playing, opens up a modal displaying the live lyrics. Everything works per ...

Elements listed are often ignored by HTML

My website sends a URL and xpath query to the server in order to extract data from the URL based on the xpath query. While it is functioning properly, I am encountering a singular issue. When I specify an xpath query for href,text, it displays a list of a ...

Adjust the div height to 100% in Bootstrap to center text, even with the presence of a navbar

I'm currently using Bootstrap 5 and facing an issue with getting text centered vertically on the page. I attempted to make the container of the div take up 100% of the page by using h-100, but it resulted in overflow due to the navbar occupying some s ...

Using the ng-app directive value with HTML and CSS can sometimes cause issues and the styles may not apply

angular.js:38 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=mainapp&p1=Error%3A…ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A19%3A463) <body ng-app=""> It was working fine unt ...

Tips for adjusting border colors based on the current time

Trying to change the border color based on the opening hours. For example, green border from 10am to 9:29pm, yellow from 9:30pm to 9:44pm, and orange from 9:45pm until closing at 10pm. The issue is that the colors change at incorrect times beyond midnight. ...

The .media object in Bootstrap 3 does not experience overflow issues with .dropdown elements

Dropdown menu not displaying fully https://i.sstatic.net/G38cL.png I have a dropdown menu but it seems to cut off halfway through displaying its content. <div class="media-body"> <h4 class="panel-heading" style="margin:0;"> <div ...

Avoid opening the page when attempting to log in with jquery, ajax, and php

I am facing an issue with my code. I have a file named "index.html" which contains a login form. Another file called "dash.js" retrieves the username and password from the login form and redirects to "connectdb.php" to check the login credentials with the ...

The z-index property fails to function properly when used with a relative parent and after/before pseudo-elements

Here is the code snippet (prototype) that I am working with: .headerz { position: relative; padding: 5rem 0 0 5rem; margin: 3rem 0 0 0; color: #000; font-size: 3.8rem; text-transform: uppercase; z-index: 24; } .headerz::before { content ...

Grid of squared CSS elements contained within a wrapper div that is set to a maximum

When attempting to create a CSS grid layout with square boxes, I encountered an issue. While the first row of squares remains square when setting the maximum height of the wrapper, subsequent rows are cropped into rectangles instead. The culprit seems to b ...

Checking if the group of radio buttons has been selected using JQUERY

Need help with validating a group of radio buttons. If none are checked, display an error message in the span element to prompt users to select an option. The strange issue I am facing is that the validation code works only when placed below the radio butt ...

A guide on integrating variables into a MySQL table using PHP

I am currently working on a project where users should be able to select their schedule. Here is the code that I have written so far: <?php //if form has been submitted process it if(isset($_POST['submit'])){ $servername = "localhost"; ...

"Classes can be successfully imported in a console environment, however, they encounter issues when

Running main.js in the console using node works perfectly fine for me. However, when I attempt to run it through a browser by implementing an HTML file, I do not see anything printed to the console. Interestingly, if I remove any mentions of Vector.ts fro ...

When developing a website with HTML/CSS, is it recommended to utilize tables for organizing content

Seeking guidance as a novice in web development. I am planning to design a table with input fields that will be sent to the server upon submission. What is the preferred method for achieving this? Is it advisable to utilize html-tables or would it be more ...

What is the best way to ensure an input field and a button are aligned perfectly within the same div tag and of equal height?

During a recent HTML-CSS project, I encountered an issue where I struggled to ensure that two elements within a div tag were the same height. The elements in question were an input field and a button with an icon. Here is a snippet of the relevant HTML cod ...

"Crafting a sleek card design using Material UI components in React JS

Exploring the world of material UI and looking to create a card with an image and footer. However, I'm facing challenges as there is no default option for adding a footer in the card. https://i.stack.imgur.com/xlxyb.png I want the image to be center ...

What could be causing my col-x to not function correctly in Bootstrap?

I am trying to modify my Bootstrap navbar by adding a Login button, but I encountered an issue. When I use col-x classes inside the navbar to separate elements equally, they only cover 50% of the width and no more. However, using col-x classes outside the ...

Is it possible to use jQuery to load an HTML file and extract its script?

I have a navigation bar with five buttons. Whenever a button is clicked, I want to dynamically load an HTML file using AJAX that includes some JavaScript code. The loaded file structure resembles the following: <div> content goes here... </div& ...

Utilizing AngularJS $anchorScroll for navigating to an anchor tag on a different page

On my AngularJS Home Page, I am trying to scroll to an anchor tag on another page. Both pages are loaded as partial html files into the ng-view component based on the URL. When I start the server, the home page loads and then I need to navigate to the FAQ ...

Customizing number input types in Angular 2 - the perfect solution

Attempting to incorporate a time picker using HTML5 input type number in Angular2. The code snippet below illustrates the setup: <input type="number" [(ngModel)]="hour" (change)="checkHours();" name="one" min="1" max="12"> <input type="number" ...