What steps can I take to make sure that the content on my website is properly sized to fit within the browser window?

I'm currently working on a website project for my college assignment and I could really use some assistance with a significant issue that I've encountered.

Whenever I open the html file of my website on my MacBook, which has a screen resolution of 2880 x 1800 at home, I need to adjust the view size to 80% on Google Chrome in order for the webpage to appear in proper proportion. However, when viewed at college, the website automatically adjusts itself to the correct proportions. My concern is that when someone else reviews my website, it may not display correctly due to sizing issues.

Is there a way to write a code that will automatically adjust the website view based on the user's monitor size?

I've seen other websites utilize certain types of HTML code like the following. Do these codes help position the content to fit and adapt to different monitor and browser dimensions?

.image:hover {
  -webkit-transform:scale(1.2); 
          transform:scale(1.2);

max-width: 100%;

When I use the "Enter Responsive Design Mode" feature in the "Develop" option on my MacBook to view an online portfolio, it's clear that the way I coded the content is not maintaining its size proportions and alignment.

To give you an idea of the correct view I'm aiming for, here are links showing how I've adjusted the view in Google Chrome (https://i.stack.imgur.com/CJtUK.png) and Safari (https://i.stack.imgur.com/U1VOH.png), and a web developer's portfolio for reference where the content fits perfectly in all resolutions (https://i.stack.imgur.com/vcQRg.png).

In summary, I'm seeking advice on whether there exists a code that can ensure my website content fits perfectly on screens across different browsers and devices like the example portfolio mentioned above.

Finally, here is the snippet of my HTML & CSS code for anyone willing to review and suggest any improvements or corrections to help me achieve my desired outcome:

HTML

<!DOCTYPE html>
<html>
<head>
    <html lang="en">
    <meta charset="UTF-8">
    <title>Liam Docherty Digital Portfolio</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
</head>
 <body>
        <nav class="navbar navbar-default navbar-fixed-top"> 
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#"><img src="http://placehold.it/60x60" alt="Your Brand Name"></a>
                    <h1 class="nav-title">Liam Docherty's Digital Portfolio</h1>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                            <li><a href="#">Home</a>
                            </li>
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="true">About Me <span class="caret"></span></a>
                                <ul class="dropdown-menu">
                                    <li><a href="#">Action</a>
                                    </li>
                                    <li><a href="#section3">Contact</a>
                                    </l...
        
</footer>     
</body>
</html>

CSS

<style>
    body {
      margin: 0;
      padding: 0;
    }
    .navbar.navbar-default {
      background-color: #4D5061;
      height: 10vh;
      z-index: 100;
    }
    /* Remaining CSS styles follow... */
    </style>

Answer №1

Consider updating the head section of your HTML file with this meta tag:

<meta name="viewport" content="width=device-width, initial-scale=1.0">

You may also want to explore CSS Media Queries. These can help adjust the style based on screen size for a more dynamic experience.

<!DOCTYPE html>
<html>

<head>
  <html lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Liam Docherty Digital Portfolio</title>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="css/style.css">

  <style>
    /* Your CSS styles here */
  </style>

</head>

<body>
  <nav class="navbar navbar-default navbar-fixed-top">
    <!-- Navigation content -->
  </nav>

  <section id="section1" class="section1">
    <!-- Section 1 content -->
  </section>
  
  <section id="section2" class="section2">
    <!-- Section 2 content -->
  </section>

  <section id="contact-me" class="contact_section section3">
    <!-- Contact section content -->
  </section>

  <script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <footer>
    <div class="footer">
      <!-- Footer information -->
    </div>
  </footer>
</body>

</html>

If you're encountering issues with sizes, check the margins applied to the 'shape' and 'shape2' div elements.

Answer №2

Learning about the Bootstrap Grid is key for creating responsive webpages, making it an essential CSS-framework to dive into.

To customize your webpage's responsiveness, delve into using media queries in your CSS code.

For instance: The following CSS snippet targets browser windows ranging from 520px to 699px, adjusting styling accordingly within this specified range.

@media screen and (max-width: 699px) and (min-width: 520px) {
    ul li a {
        padding-left: 30px;
        background: url(email-icon.png) left center no-repeat;
    }
}

This insightful example was sourced from w3schools. Find further details here.

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

Tips for utilizing a particular style from a font collection?

I am currently in the process of building my first website and I am experimenting with different fonts available on fontsquirrel. However, I am encountering an issue where I am only able to utilize certain fonts that I have downloaded from the site. One ...

Is there a way to determine if a container is overflowing at the top?

Currently, I am using Puppeteer to scrape Slack. My goal is to confirm whether I have scrolled to the very top of the channel feed. The issue arises because the channel feed does not actually scroll, making it impossible for me to utilize the method outli ...

What is the process for deselecting a checkbox?

I am facing a situation where I need to uncheck a checkbox that is always checked based on user input from another section of my form. Specifically, I have implemented an onChange="functionName" event on a select box. Can someone guide me on how to accom ...

Changing color of Font Awesome Icons upon hover, without any animation

I need assistance with changing the color of font awesome icons on hover without any animation. Specifically, I want the icon colors to transition from indigo to blue and finally red when a user hovers over them, without the colored icon appearing abruptly ...

PHP is having trouble updating the database when multiple radio buttons are selected. It appears that only the most recent radio button selected will be updated in the database

In my form, there are 2 numbers and 4 radio buttons for each. Only one option can be selected per number. When the form is submitted, only the database for question 2 will be updated. However, if question 2 is left blank, then question 1's database w ...

Connecting an Angular application to a URL hosted on localhost

I am currently working on an Angular project where one of the links needs to redirect to a different website. During development, this link points to a localhost URL like localhost:4210. However, due to security reasons in Angular, using such URLs is cons ...

Switching the background image of a div by clicking on a different div

To start, you can locate all of my code right here. http://jsfiddle.net/yfukm8kh/1/ The issue I'm encountering pertains to the following section. var changePic = function (direction, id, array) { var intID = parseInt(id); var intDir = pars ...

Seeing <br> elements being inserted into a <div> element in the page source

I have encountered an issue where my code does not contain any br tags between the beginning of the div tag and table tag, but when I view the source, several br elements appear. Below is the code snippet from a .php file: <div id='tx_addAccountp ...

Utilizing Tailwind CSS for creating a responsive layout on a Next.js application

I'm just getting started with Tailwind CSS and I decided to build the user interface of my nextjs application using a "mobile first" approach like everyone suggests. I got the flex direction and background color working perfectly on mobile screens, so ...

What is the best way to combine table cells in HTML to create a "T" shape?

Is there a way to merge the two blank cells (one above 'Be' and one above 'B') with a large blank space in the middle? I attempted using colspan and rowspan in various ways without success. https://i.stack.imgur.com/tw5SE.png This is m ...

Loop through the elements of a class in JavaScript and choose all except for the one that was

Imagine having 5 div elements, each with a similar onclick-function that hides the other divs when clicked. HTML: <div id="1" class="divs" onclick="hide()"></div> <div id="2" class="divs" onclick="hide()"></div> <div id="3" cla ...

Is there a way to streamline the process of uploading an image and storing its details in a single HTML form with just one submit button?

Here is the code snippet I have: <form id="registration_form" action="AddProductServlet" method="post"> <div> <label> <input placeholder="Product ID" name="pid" type="text"> ...

Python's web scraping with Selenium

I have encountered an issue while trying to extract data from an HTML table. Although I was able to successfully count the rows, the problem arises when I attempt to print the data as it ends up repeating the same row multiple times. Can someone please h ...

The issue arises when trying to implement CSS keyframes with a CSS image slideshow

I'm currently troubleshooting a CSS slideshow that isn't functioning properly. The issue lies within the keyframes. I'm attempting to make the images come down from the top mask and then have the previous image go back up into the mask. This ...

Adjusting table dimensions according to webpage dimensions

When looking at the image below, you will notice a div that contains a table with some content. However, when resizing the web browser's page, the table goes beyond the boundaries of the div. My goal is to reduce the size of the table as it scales do ...

Ways to display an image overlay on hover using sprite sheets

Is there a way to make a line appear, around 10px in size, when hovering over an image at the bottom of that image? I came across this effect on MTV's website within their "You would also like these" section below each post. They utilized css-backgro ...

Maintain the default material-ui class styles while making customizations to override others

Currently, I am working on customizing the material-ui tooltip and specifically need to adjust the margin for the tooltipPlacementTop class: const useStyles = makeStyles(theme => ({ tooltipPlacementTop: { margin: '4px 0' ...

Utilizing checkboxes for toggling the visibility of buttons in Angular

I want to dynamically show or hide buttons based on a checkbox. Here is the HTML code I am using: <input class="form-check-input" [(ngModel)]="switchCase" type="checkbox" id="flexSwitchCheckChecked" (change)=" ...

Adjust the background color of child divs when the parent div is being hovered over

I am facing a challenge with my current setup: <div class="parent"> <div class="child"> </div> <div class="child"> </div> <div class="child"> </div> </div> My goal is to change the background co ...

"Can the form and action occur on the same page, or should they be

When it comes to form actions, what is more effective: having the action on the same page or a different page? See the sample code below: <form action="act.php"> html code </form> <form action=""> html code </form> < ...