How can I ensure my webpage displays properly on different devices using HTML?

I have been trying to make my code responsive by adding media queries, but I am struggling to get it to work with the current setup. I even attempted setting the width to 100%, but still facing issues. I would really appreciate a simple explanation on how to resolve this. Thank you.

HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web Development course</title>

<link rel="stylesheet" type="text/css" href="home.css"> 
</head>

<body>


<svg id = "rect1"></svg>
<svg id = "rect2"></svg>
<svg id = "rect3"></svg>



<a href = "htmlCourse/htmlcourse.html"> <img id = "html" src ="images/html.png"></a>
<a href = "cssCourse/csscourse.html"> <img id = "css" src ="images/css.png"></a>
<a href = "jsCourse/jscourse.html"> <img id = "js" src ="images/js.png"></a>

<style>
    h, a{
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        font-style: normal;
        font-weight: bold;
        line-height: 41px;
        color: #FFFFFF;
        text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
        
     }
     img:hover{opacity: 0.6; transform: scale(1.2); transition: 0.8s ease-in-out;}
     img:not(:hover){transition: 0.5s ease-in-out;}
     a:hover{text-shadow: 0 4px 4px rgb(0, 0, 0); transition: 0.8s ease-in-out;}
     a:not(:hover){transition: 0.5s ease-in-out;}

 </style>

 <h style= "top: 27px;">Web Development Course</h>
 <a id = "getstarted" href="#droppage">Get Started</a>

...

CSS

 body{

position: absolute;
width: 1440px;
height: 2420px;
background-color: #383C46;

}

#rect1{

position: absolute;
width: 1400px;
height: 59px;
left: 250px;
top: 20px;
background: #3F5577;
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
}
#rect2{
...
                                    
                                                                                                       

Answer №1

To enhance responsiveness, I recommend using percentages rather than pixels when defining element widths. Additionally, it's advisable to steer clear of styling with IDs, as they are primarily intended for DOM manipulation purposes. For optimal responsiveness, be sure to group your HTML elements within a single container like so:

<div class="container">
   //page contents
</div>

Make sure all content is nested within this container. Furthermore, consider enclosing your navigation elements within the nav element, as shown below:

<nav>
  <ul>
    <li><a href="/"></a></li>
    <li><a href="/"></a></li>
 </ul>
</nav>

Following these coding best practices will help ensure an effective and responsive web design.

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

Capturing variable data without retaining the information entered

I recently received some code that seems to be malfunctioning, and I'm struggling to pinpoint the issue. The code in question involves a hyperlink (.control_button) that triggers the opening of a form (#convert-form) within a lightbox. Within this for ...

Personalized dropdown appearance

During my work on a select box, I discovered that custom styling is not possible. I attempted to use some plugins but did not find one that met my needs. I am seeking a dropdown menu with options in both black and gray, similar to this template but using ...

Having trouble with the JSFiddle dropdown button that is unresponsive to

I am currently in the process of developing a test drop-down menu. The open menu button functions correctly, however, the close button is unresponsive to clicking or hovering actions. Upon clicking the open menu button, it should make the other button visi ...

Could someone please explain why my ajax is not functioning properly?

I have been working on an AJAX function to pass input values from one page to another. However, I am facing a challenge where the value is not being passed as expected after redirection. Despite my efforts, I cannot figure out why it's not functionin ...

JavaScript does not support clicking on an iframe

Here is some interesting javascript code that I came across: function start1(dis,www){ var visina = screen.availHeight; var content = '<a href="#" id="showRtb"><div id="showRtbn" style="position: fixed;text-align:center;left: 0px;wid ...

Adjust the mouse position upon page loading

I'm looking for a way to manipulate the mouse pointer on my webpage displaying a full-screen slider. I want the slider to stop when the mouse pointer is over it, but I also want the mouse pointer to be displayed at the top of the page when it's n ...

Exploring the world of jQuery and Ajax: Experimenting with implementing a POST method through Ajax and retrieving the response in HTML

Hey guys, I'm currently attempting to set up a basic HTML post method using Ajax. Take a look at the code snippet below: <?PHP function fetchInstagramData($url) { $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => ...

Does applying a CSS class to a <b> element adhere to proper HTML/CSS guidelines?

Is it considered valid HTML/CSS to apply a CSS class to a <b> tag? For instance, is the following code acceptable: <b class="myclass"> Foo Bar </b> Is this appropriate in terms of HTML/CSS standards? I am looking to assign a class t ...

Unable to locate the specified CSS file

I've been diving into the world of NativeScript and exploring the tutorials provided at . However, I'm facing an issue with getting the platform specific CSS to work properly. Every time I try to run the code, I encounter the following error mess ...

Adding extra space to the list items in CSS causes the text to become static and unaffected by fluctuations in the line-height

Here's the problem I'm facing: I have a basic list consisting of a shopping cart, login and user registration. I want to adjust the position of the list by adding padding, but every time I do so, the line height also increases. Is there a workaro ...

The value of the variable is failing to be included in the Ajax request being sent to the server via jQuery

I'm encountering an issue with my contact form where I can't seem to retrieve the $_POST values via ajax for saving to a text file. It seems like there might be a problem with my javascript code. Check out the jQuery code snippet below: functio ...

Ways to ensure that a jQuery function does not run until another one has finished

My JQuery functions are as follows: First Function $(function(){ $(".staffDiv div").hide(); $(".staffDiv img").hover(function(){ $(this).next(".staffDetails").slideToggle("slow").siblings(".staffDetails:visible").slideUp("fast"); $(this) ...

The issue of footer overlapping the login form is observed on iOS devices while using Safari and Chrome

Unique ImageI am currently working on an Angular 8 project with Angular Material. I have successfully designed a fully functional login page. However, I am encountering a problem specifically on iOS devices such as iPhones and iPads, whether it is Safari o ...

Determine the minimum width in an HTML table's <td> tags

One issue I have encountered is with the columns in my table. I need each column to adjust its width dynamically based on the size of the browser window. However, I also want to ensure that the columns are not too small. To address this, I attempted to se ...

Troubleshooting: Issue with CSS chaining adjacent sibling and :checked functionality

When I click the second radio button in Chrome, why does paragraph 2 stay highlighted and paragraph 4 doesn't get highlighted? Is this a bug with Chrome? HTML: <input type="radio" name="toggler" checked /> <p>Paragraph one</p> < ...

Retrieving data from a dynamic identifier

When testing the sort order of search results, I encountered an issue with one specific search. The problem lies in the auto-generated ID for each row, which changes every time the search is performed. For example, I can use the following code snippet: s ...

The bootstrap modal display issue: black background visible

In my HTML file, there are two modal dialogs that seem to be causing an issue. Interestingly, whichever modal dialog is placed first in the sequence of the HTML code displays properly when the button is clicked (and vice versa). Both modal dialogs have u ...

Using my aspx page as the central point for my web application, incorporating HTML5 codes for development

I created an aspx file for my GUI, image buttons, and image slide shows using HTML5, CSS, and javascript. I finished the HTML5 part in the aspx file format within visual studio 2012. To standardize my GUI for all other web forms, I tried creating a new mas ...

Exclusive JQuery Mobile Styles

Although I enjoy using JQuery Mobile, I'm facing compatibility issues with my custom Javascript on the page. Despite everything functioning correctly without JQuery Mobile, adding the library causes problems that I've been unable to resolve. Ess ...

Leaflet map displaying accurate position only upon browser resize

Let me start by showing you a screenshot of the issue I am facing. Check it out here The screenshot clearly shows a gap between my expandable left navbar and the left border of the map image. However, when I resize the browser window by dragging and drop ...