0

I'm brand new to web development and I have build a little website with 3 pages. My goal is to use @media tags to make it responsive for the following: max-widths: 980px, 768px and 640px. I did the first page and it's been acting weird. How can I make the entire website responsive? Please to assist. My code for all 3 pages and the media is attached. Thanks.

/*first page */
     <head>
         <title>AboutMe</title>
         <link rel="stylesheet" type="text/css" href="assets/css/style.css">
         <meta name="viewport" content="width=device-width, initial-scale=1">
        </head>
        <body> 
         <div class="container">
           <div class="top">
            <div class="myname">
             <h4 class="firstlast">name</h4>
            </div>
            <div class="list">
             <ul>
              <li class="contact"><a href="contact.html">Contact</a></li>
              <li class="portfolio"><a href="portfolio.html">Portfolio</a></li>
              <li class="about">About</li>
             </ul>
            </div>
           </div>
        
           <div class="middle-about-me"> 
            <div class="center">
             <h3>&emsp;About Me</h3>
             <hr>
             <p class="myinfo">Hi my name is ..... and I was born on October 9th, 1971 in ......
              <img src="assets/img/author.jpg" width="150px" height="150px"><br>
              &thinsp;&thinsp;To briefly introduce the... to you I would say it is a country located on the........>
              &thinsp;&thinsp;&thinsp;&thinsp;shares the same borders with ....... It is the world largest<br> 
              &emsp;producer of coacoa used for chocalate and lotions. In one word, it's the country where chocolate tastes like<br> &emsp;real chocolate. Since the last discovery of petrol in the country, it's been a little agitated as France and the<br>US want to control the discovery. After obtaining my masters in Business Management, I worked as the marketing representative for an american company before moving to the US to pursue a degree in Mathematic at UNT Dallas and worked for...,...., and.... as a Math instructor. My goal in this program is to learn to build websites from scratch and later on to build apps from scratch. I've got the right instructional staff and the right TAs to help me reach that goal. All I have to do is to go to work.<br> &emsp;&emsp;"Impossible is nothing",  Muhammad Ali.</p>
              <p class="smile"><i>hover on my picture and start smiling</i></p>
            </div>
           </div>
           <div class="footer">
            <p class="footer-copyright">Copyrigtht &copy; 2019 Portfolio "name" All rights reserved.</p>
          
           </div>
         </div>
        
        </body>
    
    
    
        /*second page */
        <body> 
         <div class="container">
           <div class="top">
            <div class="myname">
             <h4 class="firstlast">name</h4>
            </div>
            <div class="list">
             <ul>
              <li><a href="contact.html">Contact</a></li>
              <li>Portfolio</li>
              <li><a href="index.html">About Me</a></li>
             </ul>
            </div>  
           </div>
        
           <div class="middle">
            <div class="center-portfolio">
             <h3>&emsp;Portfolio</h3>
             <hr>
             <div class="div1"><img src="assets/img/career1.jpg" height="120px" width="150px"></div>
             <div class="div2"><img src="assets/img/chocolatour.jpg" height="120px" width="150px"></div>
             <div class="div3"><img src="assets/img/guildhouse.jpg" height="120px" width="150px"></div>
             <div class="div4"><img src="assets/img/career2.jpg" height="120px" width="150px"></div>
             <div class="rotateIn div5"><img src="assets/img/Abidjan1.jpg" height="120px" width="150px"></div>
             <div class="div6"><p><i>please to hover on the images</i></p></div>
             <div class="banner1">career picture 1</div>
             <div class="banner2">chocolate tour</div>
             <div class="zoomIn banner5">Abidjan</div>
             <div class="banner4">career picture 2</div>
             <div class="banner3">Guild Brussels</div>
            </div>
           </div>
           <div class="footer">
            <p class="footer-copyright"> Copyrigtht &copy; 2019 Portfolio "name" All rights reserved.</p>
           </div>
         </div>
        
        </body>
        
        
        /*third page */
        <body> 
         <div class="container">
           <div class="top">
            <div class="myname">
             <h4 class="firstlast">name</h4>
            </div>
            <div class="list">
             <ul>
              <li>Contact</li>
              <li><a href="portfolio.html">Portfolio</a></li>
              <li><a href="index.html">About Me</a></li>
             </ul>
            </div>
           </div>
        
           <div class="middle">
            <div class="center">
             <h3>&emsp;Contact</h3>
             <hr>
              <form>
               &emsp;&thinsp;Name:<br>
               <input id="namebox" type="text" name="name" required="" placeholder="your name">
               <br><br>
               &emsp;&thinsp;Email:<br>
               <input id="emailbox" type="Email" name="email" required="" placeholder="example@yahoo.com">
               <br><br>
               &emsp;&thinsp;Message:<br>
               <textarea id="messagebox" style="height: 200px; " name="message" placeholder="Enter massage here" required="">
               </textarea>
               <br><br>
               &emsp;&thinsp;<input type="submit" value="submit" name="submit">
              </form>
              <br>
            </div>
           </div>
           <div class="footer">
            <p class="footer-copyright">
             Copyrigtht &copy; 2019 Portfolio "name" All rights reserved.
            </p>
           </div>
         </div>
        
        </body>
    
    
    
    /* Width at 768px and below */
    @media screen and (max-width: 768px) {
    
      body {
      background-color : #E9967A;
      }
    
      .container {
       background-color: green;
       border-style: none;
        width: 50%;
      }
    
     .middle-about-me,
     .footer, .top{
       width: 50%;
      }
    
      .middle-about-me{
        width: 50%%;
      }
    }
    
     /*Width at 640px and below */
    @media screen and (max-width: 640px) {
    
      body {
      background-color : #E9967A;
      }
    
      .container {
       background-color: green;
       border-style: none;
        width: 50%;
      }
    
     .middle-about-me,
     .footer, .top{
       width: 50%;
      }
    
      .middle-about-me{
        width: 50%%;
      }
    
    }
sabeen kanwal
  • 607
  • 1
  • 5
  • 16
Leealp
  • 3
  • 3
  • Possible duplicate of [Why are my CSS3 media queries not working on mobile devices?](https://stackoverflow.com/questions/7859336/why-are-my-css3-media-queries-not-working-on-mobile-devices) – Mike Doe Mar 17 '19 at 16:54

2 Answers2

0

Start out by removing fixed width properties. I am having a hard time seeing how you need width: 50% on everything. Then start by just addressing the styles of your .container element.

A good techniques is setting the max-width to the width you have in mind for the site to be viewed on a normal desktop screen, in the demo I used 600px but you can use any value that feels right.

Then in you media query assign a new max-width value that is appropriate for the screen size in the query, here i used 80% becuase typically on small screens you want the content to mostly fill the width of the screen with a little space on the sides, but again you can configure this to your needs in a variety of ways.

The main thing here is that your container element is now responsive and the content inside can fill up the space however you like from there. Run the snippet and click the Full page link to play around with the screen width and see the behavior working.

.container {
  max-width: 600px;
  margin: 0 auto;
}

@media screen and (max-width: 640px;) {
  .container {
    max-width: 80%;  
  }
}
<div class="container">
  <div class="top">
    <div class="myname">
      <h4 class="firstlast">name</h4>
    </div>
    <div class="list">
      <ul>
        <li class="contact"><a href="contact.html">Contact</a></li>
        <li class="portfolio"><a href="portfolio.html">Portfolio</a></li>
        <li class="about">About</li>
      </ul>
    </div>
  </div>
  <div class="middle-about-me"> 
    <div class="center">
      <h3>&emsp;About Me</h3>
      <hr>
      <p class="myinfo">Hi my name is ..... and I was born on October 9th, 1971 in ......
        <img src="assets/img/author.jpg" width="150px" height="150px"><br>
                            &thinsp;&thinsp;To briefly introduce the... to you I would say it is a country located on the........>
                            &thinsp;&thinsp;&thinsp;&thinsp;shares the same borders with ....... It is the world largest<br> 
                            &emsp;producer of coacoa used for chocalate and lotions. In one word, it's the country where chocolate tastes like<br> &emsp;real chocolate. Since the last discovery of petrol in the country, it's been a little agitated as France and the<br>US want to control the discovery. After obtaining my masters in Business Management, I worked as the marketing representative for an american company before moving to the US to pursue a degree in Mathematic at UNT Dallas and worked for...,...., and.... as a Math instructor. My goal in this program is to learn to build websites from scratch and later on to build apps from scratch. I've got the right instructional staff and the right TAs to help me reach that goal. All I have to do is to go to work.<br> &emsp;&emsp;"Impossible is nothing",  Muhammad Ali.</p>
          <p class="smile"><i>hover on my picture and start smiling</i></p>
        </div>
      </div>
      <div class="footer">
        <p class="footer-copyright">Copyrigtht &copy; 2019 Portfolio "name" All rights reserved.</p>
    </div>
</div>
BugsArePeopleToo
  • 2,976
  • 1
  • 15
  • 16
  • Will I need to do the same thing for the other pages? – Leealp Mar 17 '19 at 17:51
  • If you use the class `.container` on the outer div on each page then you will get consistent behavior across all your pages. – BugsArePeopleToo Mar 17 '19 at 18:10
  • It's not working on my site. 0When I set the container max width to 600px, there is an overflow. everything get out of it. And the screen on my computer becomes as if I was viewing it with a tablet. – Leealp Mar 17 '19 at 18:23
  • There are different issues with the layout inside the container. My answer is not a complete solution to making all your code perfect, it is the answer to how to approach your whole site being responsive. Once the container is responding to changes in screen size correctly then you can start working on the layout inside. Overflowing content usually means you are forcing fixed widths that add up to greater than 100% (the width of the container). – BugsArePeopleToo Mar 17 '19 at 18:32
0

I wish you had a sketch of what the final product will look like it would have been very helpful. There is more to making a page responsive than writing just valid HTML tag and corresponding styles and mind typos because from your code the extra % sign will make

  .middle-about-me{
   width: 50%%;
  }

misbehave. There a couple of things you need to know to be able to make a page responsiveness effective and very close to what you want. Firstly you should consider resetting the default styles that the browser naturally applies to valid HTML tags by using normalize.css or utilize the power of universal selector which is almost as good in modern browsers, something like:

*,
*::before,
*::after{
padding: 0;
margin: 0;
box-sizing: inherit; /* to inherit the value declared in the body selector */
}

html{
font-size: 62.5% /* (10/16) * 100%  and this is possible because by default the value of 100% will be computed to 16px by the browser and equal to 1(r)em, with this conversion we can reduce the calculations whenever you want to convert a value from px to (r)em since the are in multiples of 10 eg 1(r)em == 10px and 10(r)em == 100px*/
}

body{
box-sizing: border-box;
}

img{
width: 100%;
min-width: 27rem; /* to make the images responsive and look good on smaller screens */
}

so with the that basic reset you can always rely on using ems or rems for fonts an percentages for images and other block element when it feels appropriate. This little write up is not enough to teach you all you need to know about responsiveness in the web but I hope it shed light on your path. Meanwhile those were not my original ideas i took a course by 'Jonas Schmedtman', He actually thought me those. If you have a sketch of what the final pages should look like or you are still not very clear with what i have tried to explain so far please don't hesitate to add a comment so that we tidy it up together.

Monday A Victor
  • 441
  • 5
  • 16