What makes my website image unresponsive?

As a newcomer to the world of programming, I recently embarked on the journey of learning about it just last month. Right now, I am fully immersed in creating my new website for a school project. However, I seem to be facing an issue with making the image responsive. Whenever I change the screen size, the image fails to adapt accordingly. Can anyone lend me a hand with this predicament? Your assistance is greatly appreciated. Below is the code snippet pertaining to the image:

 section.sec1{
        background: url(web.photos/pak2small.jpg);
        background-size: cover;
        background-attachment: fixed;
    }

Here's the head:

<!DOCTYPE html>
<html lang="en">
<head>
<title>2020 Web </title>
<meta charset="utf-8">
<meta name="viewport" content= "width=device-width, initial-scale=1.0">
<link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
    var zero =0;
    $(document).ready(function(){
        $(window).on('scroll', function(){
            $('.navbar').toggleClass('hide', $(window).scrollTop()
                > zero);
            zero = $(window).scrollTop();
        })

    })
</script>
</head>

here's the code for Html:

   <div class="overlay">
       <h1>Welcome to Pak courses</h1>
   </div>
</section>

<section class="sec2">
    <h4>About our school</h4>
        <p>For a general overview of learning at Pakuranga College, please read the 2018 Prospectus. You can also find out what Nigel Latta thought about our school in his documentary entitled ‘School Report’.</p>

        <h4>our philosophy</h4>
        <p>Our college provides a very special learning environment. It is focused on developing outstanding citizens who are moral and respectful. We place an emphasis on ownership of learning and being actively involved so that our students are well equipped to succeed in the future.Students are encouraged to be interactive with teachers, technology and their peers to develop real understanding and, most importantly, to apply their knowledge to problem-solving. Rather than becoming repositories of knowledge, we expect students to find out, investigate and create solutions using the many resources around them.</p>

        <h4>rules & expectations</h4>
            <p>At Pakuranga College, we have high expectations for our students that relate to all aspects of school life. We believe that young people are more likely to succeed when they develop self-management skills and have the opportunity to show leadership in all of their endeavors.</p>

    </section>
<section class="sec3">
</section>

Here's the Css code:

section{
    width: 100%;
    height: 100vh;
    box-sizing: border-box;


}
section.sec1{
    background: url(web.photos/pak2.jpg)no-repeat center;
    background-size: cover;
    background-attachment: fixed;
    padding-top: 42%;
}

section.sec2{
    padding: 100px;
    height: auto;
}
section.sec2 h3{
    margin: 0;
    padding: 0;
    letter-spacing: 5px;
    color: #111;
}
section.sec2 p{
    font-size: 15px;
    color: rgb(99, 99, 99);
}
section.sec3{
    background: url(web.photos/pak3.jpg);
    background-size: cover;
    background-attachment: fixed;

Answer №1

Utilizing CSS frameworks such as Bootstrap, Bulma, PureCSS, and others can be extremely beneficial. These frameworks come with pre-defined classes that can simplify your coding process.

To get started, you simply need to include this code in your HTML:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

For example, Bootstrap3 offers a class called img-responsive which automatically adjusts images based on the device screen ratio. You can also experiment with the img-thumbnail class for different effects.

If you prefer not to use predefined classes, here's an alternative method to make your images responsive:

.myImage{
  display: block;
  height: auto;
  max-width: 100%;
}

I hope this information proves helpful.

Answer №2

You have the option to specify a particular screen width at which the section will display in a smaller size.

For instance, the code snippet below adjusts the height of the sec1 class to 300px when viewed on screens with a width of 600px or less.

@media screen and (max-width: 600px) {
  .sec1 {
    height: 300px;
  }
}

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

The v-menu closes before the v-list-item onclick event is detected

I have set up the following menu using vue and vuetify: <div id="app"> <v-app id="inspire"> <div class="text-center"> <v-menu> <template v-slot:activator="{ on }"> ...

At what times do screen reader users utilize tabs?

Did you know that screen reader users often rely on specific keyboard shortcuts rather than tabs for navigating web pages? For example, in VoiceOver they may use CTRL + OPTION + Arrow Keys instead. This challenges the idea of optimizing for tabbable naviga ...

Building a ranking system

I have a vision to develop an app featuring my unique tableView showcasing the top high scores of the public community. Instead of opting for the standard look, I am eager to customize the leaderboard. Is there a viable method to build this from the ground ...

What is the best way to access the current scope's DOM element within an AngularJS controller?

In my scenario, I have a collection of outerItems each containing a list of innerItems that are dynamically sorted. Whenever the mouse hovers over an innerItem, I need to display a popup window directly above that specific element. To achieve this, I hav ...

Using JQuery to load a table and inject it with html()

I am looking to populate an HTML table within a specific div element. The HTML code is being loaded using the following jQuery function: $("#table_wrapper").hide(); $.get("<?echo base_url();?>schichtplan/employee_fields/"+plan_id+"true",function(da ...

Encountered a JQuery error in the application: trying to call the 'open' method on dialog before initialization is complete

I am having trouble integrating a dialog box into my application and encountering the error mentioned above. Here is the jQuery code I'm using: $( "#dialog" ).dialog({ autoOpen: false, width: 450, modal: true, ...

Developing a custom JavaScript function to iterate through a group of html elements

In my mission to create a function that loops through a set of HTML elements and gathers their values, I aim to then utilize those values to produce an HTML textarea. Thus far, I've established a series of HTML input boxes and a JavaScript function f ...

What could be causing the bootstrap columns to automatically shift onto separate lines?

Check out my code snippet: html, body { width: 100%; height: 100%; margin: 0; padding: 0; overflow-x: hidden; } .row { width: 100%; height: 80%; margin: 0px; padding: 0px; } body { background: #EFEFEF; } .container-fluid { wid ...

What is the best method for eliminating a specific line from numerous HTML pages?

I have a series of HTML pages, each with a line at the top that reads: <?xml version="1.0" encoding="UTF-8" ?> When I was working on localhost, the pages opened without any issue. However, now that I have uploaded the files to the server, I am enco ...

Customizing button widths in CSS for landscape and portrait orientations with Bootstrap styling

How can I make multiple buttons in a container have equal width and resize when in landscape mode or on a wider screen? My goal is to achieve the following: https://i.sstatic.net/J8opN.png https://i.sstatic.net/NZSjj.png However, when I switch back to ...

Update Relative Links using JQuery or JavaScript

Currently, I am employed by a company that specializes in building websites using a specific platform. We have encountered an issue related to relative URLs within this platform. The platform exclusively utilizes relative URLs and I am looking for a way t ...

Improving methods for handling AJAX requests in PHP

I am facing an issue with a JavaScript file that sends an AJAX request to a PHP file to fetch data from a database. When the PHP file does not find any record based on the query, it returns a message like "no match found" instead of a JSON object in the ...

How do I update an SQLite database in Android?

I am currently working on developing an app that will have a local database storage and I want to implement the functionality where it can update the database from an online remote database whenever changes are made. It's not necessary for the app to ...

Guide to creating a see-through right border for vertical tabs using Bootstrap 4

I have been working on creating vertical tabs in Bootstrap 4 and have almost completed the task. However, I am facing an issue with making the right border of the active tab transparent. Despite several attempts, I have not been successful in achieving thi ...

Ember - Initiate a GET request to access a list of trees from an API endpoint

I have a project that utilizes Ember and Ember-Data with a requirement for a lazy-loaded tree-list. Within the API, there is an endpoint called /roots which contains children such as /roots/categories and /roots/components. These children are not fully lo ...

FBLikeControl doesn't display the like button

I've been troubleshooting this issue with the like button for the past couple of days. I followed Facebook's developer documentation to implement the Facebook Like button, but for some reason it's not showing up on my view. Has anyone else ...

The functionality of CSS transform appears to be malfunctioning on Firefox browser

My website, located at , features a logo that is centered within a compressed header. I achieved the centering effect using the following CSS command: .html_header_top.html_logo_center .logo { transform: translate(-63%, -2%); } This setup works perfe ...

Searching through the use of autocomplete with alternative parameters

In the example below, - https://codesandbox.io/s/g5ucdj?file=/demo.tsx I am aiming to achieve a functionality where, with an array like this - const top100Films = [ { title: 'The Shawshank Redemption', year: 1994 }, { title: 'The Godfa ...

Exploring the syntax for navigating with JS Angular and HTML, such as when using the code snippet: ng-click="save(userForm)"

I am struggling to grasp the functionality of a specific part of this code. Despite my efforts to find tutorials, I have been unable to locate relevant information. There are two lines in particular that puzzle me: <button type="submit" class="btn btn ...

Execute a jQuery function every time the class of the parent container div changes

I am seeking to trigger the function below whenever its containing div parent <div class="section">...</div> transitions to an "active" state, for example: <div class="section active">...</div> $(".skills-grid__col").each(function ...