elements with a display of inline-block and a fixed body width

My inline-block elements are setting the width of the page, but the header and footer tags are not taking up the full width. Why is this happening and how can I make them span the entire page width?

Check out the example here

Here's the HTML code:

<body>
  <header>
  HEADER
  </header>

  <ol>
    <li><img src="img/slides/boy.jpg"/></li>
    <li><img src="img/slides/bridge.jpg"/></li>
    <li><img src="img/slides/guitar.jpg"/></li>
    <li><img src="img/slides/iphone.jpg"/></li>
  </ol>

  <footer>
  FOOTER
  </footer>
</body>

And the CSS code:

  * {
    border: 0;
    margin: 0;
    padding: 0;
  }
  body {
    background-color: gray;
  }
  header {
    background-color: yellow;
  }
  footer {
    background-color: yellow;
  }
  ol {
    display: inline-block;
    white-space: nowrap; 
    font-size: 0;
    background-color: blue;
  }
  li {
    display: inline-block;
    list-style-type: none;
    white-space: normal;
  }
  img {
    width: 300px;
    height: 300px;
    margin: 40px;
  }

Answer №1

I am unsure about the nature of your inquiry.

If you desire for the entire webpage to match the width of the largest element present, implement the following CSS code:

body { display: inline-block; }

Answer №2

Both the header and footer are perfectly aligned at 100%. However, the list items extend beyond the body boundaries, resulting in the canvas appearing larger and the 100% width appearing incomplete. Following OdraEncoded's recommendation, changing the body to inline-block allows it to occupy the entire canvas width. As a result, the header and footer now span the full width as intended.

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

Is it possible to eliminate the css class prefix when using Modular css in React?

When working with React & NextJS, I have observed that my modular SCSS files are automatically prefixing my classnames with the name of the file. Is there a way to turn off this feature as it is making the DOM structure difficult to interpret? For instanc ...

What steps can be taken to turn this html code and css into a mobile application?

I have begun working on my HTML and CSS but need some guidance to create a mobile app without needing to resize it when accessed through the web. Additionally, I would like to make it responsive in CSS. Can you provide me with the necessary code? @c ...

What is the best way to update the current route in Angular 2 programmatically?

In my Angular 2 application, I am facing an issue with the navigation flow between the home component and the nav panel component. When a user clicks on the logout button in the nav panel, the current URL is correctly shown as "/login" in the console log. ...

Is there a way to deactivate a button upon clicking and then substitute it with a new button that serves a different purpose in AngularJS?

Is there a way to deactivate a button once clicked and substitute it with another button that performs a different task using AngularJS? Here is the button in question: <button type="submit" class="btn btn-small btn-default" ng-disabled="isteam==0 || ...

CSS for a navigation menu with underlined links

I am attempting to create an underline effect when hovering over a link. However, I am facing an issue where the underline does not align perfectly with the line below it. Can someone please guide me on how to modify this CSS so that when the link is hov ...

Issue with navigational button layout

I am facing an issue while designing my navigation menu with 4 circular items spaced about 20 px apart on the top right of the screen. I have managed to style each nav item as a circle, but when I try to position them in the upper right corner, only the 4t ...

How to exclude elements nested inside another element using CSS or XPath techniques

Presented here is a snippet of XML code: <xml> <section> <element>good</element> <section class="ignored"> <element>bad</element> </section> </section> </xml> Identifying a ...

Customize the X and Y position of the CSS background with specific degrees

Looking for help customizing the background position in a PSD image to adjust the slope at the top, right-left side, and bottom. Here is my PSD: https://i.stack.imgur.com/Jr4h7.png Below is some of my CSS code: html{ background:#aea99f; } body{ backgroun ...

Attempting to align the text perfectly while also adding a subtle drop shadow effect

Trying to center text with a drop shadow without using the CSS property. I'm utilizing span and :before for cross-browser compatibility. Here is what it currently looks like: The HTML: <h3 title="Say hello to Stack Overflow"><span>Say ...

positioning a picture at the middle of a link

Struggling to horizontally center an image within an anchor tag? Despite trying various methods like setting it as a block element, applying auto margins, and nesting divs, the image stubbornly remains aligned to the left. Even after looking at other resou ...

Retrieving the value of a select option from an HTML form using the $_POST method

I have a select element in my HTML code with options listed inside: <select name="taskOption"> <option>First</option> <option>Second</option> <option>Third</option> </select> Can someone provide ...

How deep can nesting go within a CSS rule?

When working with stylesheets, the majority of CSS rules follow a structured format: selector { property_1 : value_1; . . . property_n : value_n; } Each selector typically has only one {} block attached to it (without any sub {} blocks ...

Tips for avoiding the page from reloading when executing a query. I attempted using preventDefault(); which successfully prevented the reload, but it also stopped PHP

function createCounter() { var count = 0; return function () {return count += 1;} } var add = createCounter(); function updateDatabaseOnClick(){ document.getElementById("result").innerHTML = add(); } I'm currently working on implementing a co ...

Uncertainty surrounding the application of class selector within CSS

Currently, I'm deep into my CSS learning journey on Progate.com. I've been cruising through the exercises, but I hit a roadblock when it comes to a specific class selector in the CSS code. The task at hand is simple: I need to tweak the CSS so th ...

What are some strategies for preventing the $window.alert function from being triggered within an AngularJS controller's scope?

How can I prevent the alert from appearing on my dashboard? Do you have any suggestions? Thank you! I attempted to override the alert empty function in my controller, but I am still encountering the window alert when I navigate to my page. $window.alert ...

The functionality of responsive images is not functioning as intended within the Bootstrap framework

I'm currently working on troubleshooting a code issue. I am trying to implement a responsive image using Bootstrap, but it seems to not be functioning correctly. How can I go about resolving this problem? <header class="masthead text-center text-w ...

Is it possible to create a translucent glass floating box over HTML elements, similar to the frosted glass effect seen in iOS7?

Creating an overlapping div with a frosted glass effect typically requires using an image background (like ). I am interested in having a floating div (position:fixed) that can apply a frosted glass effect over any content below it, whether it be an image ...

jQuery does not seem to be able to recognize the plus sign (+)

I am currently developing a calculator program and facing some challenges with the addition function. While the other functions ("/", "-", "*") are working fine, the plus ("+") operation seems to be malfunctioning. Here's the snippet of HTML and JavaS ...

What are the steps to creating a fading effect for an item that appears as it enters the field of view and disappears as it exits the field of view?

Implementing a fade-in effect for a button as the user scrolls down and the button comes into view, along with a fade-out effect as the user continues scrolling down and the button goes out of view. var fadeInButton = $('#fadeInButton'); ...

Adjust the content to expand and occupy the entire height using Material UI cut-off Drawer

I am using the provided Material UI code for a persistent clipped drawer, but I am encountering an issue with the content height. I have set the background of the content section to red in my demo sandbox to showcase the problem. My goal is for the content ...