Preventing div from utilizing full width when browser is resized

Back in the day, I had no problem getting my header, content, and footer to resize proportionally across different devices just by setting the width to 100%. But for some reason, it's not working this time. I can't figure out why. I still need to work on the footer, though.

*. {
width: 100%;
}

body {
font-family: Andale Mono, monospace;
}

p {
font-size: 24px;
}

.header {
padding: 200px;
text-align: center;
background-color: #001f4d;
}

.header h1 {
font-size: 64px;
color: white;
}

.header p {
color: white;
}

/* Begin main-content */

.content {
background: #0d0d0d;
padding: 80px;
color: white;
}

#main-title {
text-align: center;
font-size: 36px;
}

#main-paragraph {
margin: 400px;
max-width: 1000px;
margin: auto;
}

.column {
  float: left;
  width: 33.33%;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}



/* Small devices (portrait tablets and large phones, 600px and up) */

@media screen and (max-width: 600px) {
.header {
width: 100%;
}

.content {
width: 100%;
}

#main-paragraph {
width: 100%;
}

.column {
    width: 100%;
  }
}
<!DOCTYPE html>
<html>
<head>
<title>Doug Cannon's Biography</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div class="header">
<h1>My Website</h1>
<p>Welcome to my website.</p>
</div>

<div class="content">


<h2 id="main-title">About Me</h2>
<p id="main-paragraph">Mollit officia quis officia nostrud culpa ad sunt quis nulla quis esse adipisicing ut. Ullamco mollit ad elit reprehenderit mollit in duis incididunt id sit laboris adipisicing nisi pariatur. Lorem ipsum ea ut qui in ea consectetur id adipisicing quis officia occaecat laboris id velit. Sunt ea irure ex nostrud elit enim dolor in ut anim cillum ad duis.</p>

<br><br><br>


<!-- Responsive column cards -->

<div class="row">

  <div class="column" style="background-color:#aaa;">
    <h2>Column 1</h2>
    <p>Some text..</p>
  </div>

  <div class="column" style="background-color:#bbb;">
    <h2>Column 2</h2>
    <p>Some text..</p>
  </div>

  <div class="column" style="background-color:#ccc;">
    <h2>Column 3</h2>
    <p>Some text..</p>
  </div>

</div>



</div> <!-- End main-content -->

<div class="footer">
<footer>
      Douglas Cannon <span class="highlight">&copy; 2019</span>
    </footer>
</div>

</body>
</html>

Answer №1

It appears I have caught on to the situation!

The header is set with 200px of padding while the content has 80px. Once the window width exceeds 600px, the content and header widths become auto, adjusting to their container's width (<body>) less the 200px/80px padding. Since the padding extends beyond the actual width, they seamlessly fill up the window width!

However, should the window size drop below 600px, the header and content widths are adjusted to 100% of the container, but maintain the 200px/80px padding on the outer edges. Consequently, the elements occupy considerably more space! By setting box-sizing to border-box, the padding shifts inside, allowing for consistent appearance irrespective of window width changes.

To achieve a wider display, consider reducing the padding rather than setting the width to 100%. Additionally, address the 8px margin on <body> which creates gaps around the entire page.

Fingers crossed that my interpretation is accurate :)

Answer №2

To decrease the space around the content when the screen size is less than 600px

*. {
width: 100%;
}

body {
font-family: Andale Mono, monospace;
    margin: 0;
}

p {
font-size: 24px;
}

.header {
padding: 80px;
text-align: center;
background: #001f4d;
}

.header h1 {
font-size: 64px;
color: white;
}

.header p {
color: white;
}

/* Begin main-content */

.content {
background: #0d0d0d;
padding: 80px;
color: white;
}

#main-title {
text-align: center;
font-size: 36px;
}

#main-paragraph {
max-width: 1000px;
margin: auto;
}

.column {
  float: left;
  width: 33.33%;
}

/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

/* Footer */
.footer {
background: #001f4d;
padding: 80px;
color: white;
}


/* Small devices (portrait tablets and large phones, 600px and up) */

@media screen and (max-width: 600px) {
.header {
padding: 40px;
}

.content {
padding: 40px;
}
  
  .footer {
    padding: 40px;
  }
}
<!DOCTYPE html>
<html>
<head>
<title>Doug Cannon's Biography</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div class="header">
<h1>My Website</h1>
<p>Welcome to my website.</p>
</div>

<div class="content">

<h2 id="main-title">About Me</h2>
<p id="main-paragraph">Mollit officia quis officia nostrud culpa ad sunt quis nulla quis esse adipisicing ut. Ullamco mollit ad elit reprehenderit mollit in duis incididunt id sit laboris adipisicing nisi pariatur. Lorem ipsum ea ut qui in ea consectetur id adipisicing quis officia occaecat laboris id velit. Sunt ea irure ex nostrud elit enim dolor in ut anim cillum ad duis.</p>

<br><br><br>


<!-- Responsive column cards -->

<div class="row">

  <div class="column" style="background-color:#aaa;">
    <h2>Column 1</h2>
    <p>Some text..</p>
  </div>

  <div class="column" style="background-color:#bbb;">
    <h2>Column 2</h2>
    <p>Some text..</p>
  </div>

  <div class="column" style="background-color:#ccc;">
    <h2>Column 3</h2>
    <p>Some text..</p>
  </div>

</div>



</div> <!-- End main-content -->

<div class="footer">
<footer>
      Douglas Cannon <span class="highlight">&copy; 2019</span>
    </footer>
</div>

</body>
</html>

Answer №3

Upon visiting this site, I encountered two issues that were preventing the browser from properly rendering the page with the HTML not sizing to 100% of the browser viewport.

The first issue stemmed from my use of img tags with inline styling in the HTML code like so;

<img id="recipe_picture" class="method-img" src="{{ step.picture1() }}"/>

Secondly, after attempting to fix the problem by setting the main container's padding to 0 (which actually made things worse), the resizing issue persisted.

        .container{
            padding: 0;
        }

By removing these components, I was able to resolve the issue. Hopefully, this solution will be helpful to others experiencing similar problems.

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 window fails to retain the scroll position when overflow is enabled

Whenever I click on a specific div, I use jQuery to dynamically apply overflow: hidden to the html and body. $(".mydiv").on("click", function() { $("html, body").css("overflow", "hidden"); }); However, this action causes the window to scroll to the to ...

Using javascript to transform the entire list item into a clickable link

Currently, I am using PHP in WordPress CMS to populate slides on a slider. Each slide contains a link at the bottom, and my goal is to target each slide (li) so that when clicked anywhere inside it, the user is directed to the URL specified within that par ...

Delete all HTML functionalities

Is there a way to strip HTML functions when using a text area so that the content shows as plain text in a new post (div)? For example, if I type "Hello", I want it to appear as "< b > Hello < b / >", showing the whole code. Here is the code ...

Creating a Bootstrap carousel with a caption placed on the right side - here's how!

How can I get the caption to appear on the right side instead of the left side? Here is the CSS code I am using: #jumboCarousel { margin-top: 70px; min-height: 300px; max-height: 600px; min-width: 100%; } #jumboCarousel img { min-heig ...

is it possible to position datepicker's dropdown panel at the top in Vue.js?

Currently, I am developing a web page utilizing IView components by Vue.js. However, I am facing an issue where the dropdown menu of the datepicker component is not functioning properly when nested inside a card component. It appears that the dropdown pane ...

What is the best way to display the complete text or wrap a menu item in an Angular Material menu?

Is it possible to display the full text of a menu item instead of automatically converting it to ellipses or breaking the word? I've tried various CSS methods without success. Any suggestions? https://i.stack.imgur.com/3l7gE.png #html code <mat-m ...

What is the best way to define relative paths for content like CSS files?

Whenever I link to a file, I always find myself having to include the entire absolute path like this <link rel="stylesheet" type="text/css" href="F:/XmppOld/XAMPP2/htdocs/MAIN_SITE_LAYOUT/css/stylemainpage.css" /> I want to simplify it to ...

Modifying the appearance of the initial column in a panelGrid

Is there a way to left align the first column and right align the second column of a <h:panelGrid>? I've attempted to assign a class to elements in the first column for left alignment, but as they are outputText elements nested in a span inside ...

Encountering an issue where an error message indicates that a variable previously declared is now undefined

Currently, I am working on developing a small test application to enhance my coding skills. However, I have encountered a roadblock while attempting to display dummy information from a mongodb database that I have set up. I have tried various solutions bu ...

What could be causing my video not to display a thumbnail on mobile devices until it is played?

When I view my website on mobile devices, there is no background image displayed before playing a video. Below is the HTML code I am using: <div class="row " > <div class="col-12 text-center"> <video control ...

displaying dropdown menu from bootstrap 4 on top of a div located below

Struggling to make the bootstrap 4 responsive top nav appear over my container div, but can't find a solution. This is how the Top nav should function: W3Schools editor Here is my code on jsfiddle: jsfiddle function myFunction() { var x = ...

What could be causing the unexpected behavior of nth-child?

I'm trying to position an image with the class photo, but unfortunately, the nth-child selector is not having any effect on that particular element. I have searched for various solutions, but none seem to be working! .container { height: 100vh; ...

Concealing Columns in the Beta version of Bootstrap 4

Currently utilizing Bootstrap 4.0 Beta for website design, encountering a roadblock with a responsive-utility feature. In previous Bootstrap 3 versions, it was achieved using classes like: hidden-xs, hidden-md, among others. The addition of -up and -down ...

Requesting data from local APIs using ZingGrid CRUD operations

Is there anyone who can assist me with ZingGrid? I am looking for a sample project to understand how to make API calls using ZingGrid. ...

Personalizing/Concealing Navigation Controls

Looking for a way to customize the Navigation in the Pagination Plugin; changing 'First, Prev, Page 1, Page 2, Next, Last' to 'Prev, Next, Page 1 of 2' The documentation suggests using show_first_last set to false to hide 'First/L ...

Compiling SCSS to CSS in Vue.js is a breeze

I am working on a vue js project that includes scss files. My goal is to compile these scss files into css and store them in the public folder. How can I achieve this? Should I make changes to the vue.config.js file? const path = require('path'); ...

Activate the Navbar by clicking on the bar and change the color of the icon

Is it possible to change the background color and icon color when clicking on the bar (active bar)? If not, is there an option to switch the icon with a different color? I've tried modifying my code but haven't seen any changes. Instead of using ...

When I try to scroll, the sticky card fails to stay in place as intended with CSS

I'm having trouble creating a sticky card that remains in place when I scroll. https://i.sstatic.net/wPZ6S.png <Box display={'flex'} width={'100%'} height={'150rem'} > <Box width={'100%'}> {f ...

Issue with Smooth Div Scroll on Chrome

I'm currently utilizing a plugin called Smooth Div Scroll, which can be found at Despite the automatic scrolling functionality working perfectly on Firefox, IE, and Safari, I'm encountering an issue with it not initiating when the page loads in ...

Ways to ensure that a div, header, container, and other elements completely cover the viewport

Currently, I am attempting to create a header that spans the entire viewport regardless of screen size. This header will be split horizontally into 3 equal sections, each occupying one third of the header space. I experimented with setting the header hei ...