The inline display is malfunctioning

header ul {
  display: inline; }
  header ul .nav-header li {
    list-style: none;
    margin-right: 1em;
    float: left; }
  header ul a {
    text-decoration: none; }

*{ border: 0; margin: 0; padding: 0; }

I am currently working with this CSS code but running into an issue. It seems that using the reset wildcard is causing the display property of inline to not work as expected. Does anyone know how to fix this?

The problem arises when removing the wild card - the "Welcome" header ends up on the line below the navbar instead of next to it. By using display: inline;, the intention was to have them on the same line, but it's not functioning as intended.

http://jsfiddle.net/P8QmL/

Answer №1

Make sure to apply the display:inline property to the header element, not the header ul.

Additionally, remove the unnecessary divs inside your ul.

Here is your updated HTML code:

<header>
      <ul class='nav-header'>
          <li>
            Kali @ 1000 Commercial
          </li>

            <li>
              <a href="/">Home</a>
            </li>
            <li>
              <a href="/products">Products</a>
            </li>
            <li>
              <a href="/about">About</a>
            </li>
      </ul>
    </header>
    <section class='body-wrapper'>
      <h1>Welcome</h1>
    </section>
    <footer>
        <ul class='nav-footer'>
          <li>
            <a href="/contact">Contact Us</a>
          </li>
        </ul>
    </footer>

And here is your revised CSS code:

header {
  display: inline; }

  header .nav-header li {
    list-style: none;
    margin-right: 1em;
    float: left; }

  header ul a {
    text-decoration: none; }

Answer №2

Ah, now I see what's going on.

Here's the issue at hand:

When an element (like <header>) contains floating elements, it can "lose" its size. This means that even though your <header> element actually holds non-zero content, it ends up with a width and height of 0. As a result, other elements following the header might appear to drift to the right because they are not acknowledging the header's sizelessness.

There are a couple of ways to address this problem, but one effective solution is to apply the css clear property to the subsequent elements like so:

section {
    clear: both;
}

I have taken the liberty of enhancing your HTML & CSS for you:

http://jsfiddle.net/P8QmL/4/

However, please note that even with these changes, your <header> element still remains devoid of any visible dimensions. So, if you intend to style your header, such as giving it a background color, you'll notice that nothing seems to change due to its sizeless nature. To address this, you can opt for a different approach. One simple method to assign a size to an element containing floated children is by using overflow: auto. While it may seem somewhat unconventional, it does get the job done.

header {
    background-color: red;
    overflow: auto;
}

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

What is the equivalent of a very deep selector in TailwindCSS?

When working with the v-deep selector to customize the appearance of tiptap, a rich text editor, accessing the .ProseMirror class in SCSS would look like this: editor-content { // ... styles &::v-deep(.ProseMirror) { // ... styles } } ...

Error 404 occurs when images are not able to load when stored in a different directory

When I encounter a custom 404 Error on my website at http://ericmuir.tk and it happens in a directory other than the home one, none of the images on the page load. I faced a similar issue with loading CSS scripts, but resolved it by using style tags which ...

AngularJS seems to have trouble with routing functionality

I've recently started learning AngularJS and have been following CodeSchool's video series. However, I've encountered an error when trying to route through a click on an image. Can someone please assist me with this? Below are my HTML and J ...

What is the best way to create an oval-shaped background for a div element?

Can someone help me achieve an oval shape for my index page div? I tried using border-radius but the edges are too round for my liking. I am looking for a more specific result See the CSS code below for reference <div class="home-page"></div> ...

Toggle visibility with JQuery's onClick event

I am looking for a way to toggle the visibility of text that has display: none; in CSS when a button is clicked, as well as clear the input field on the onClick event. Currently, the text remains visible even after it has been displayed. Any assistance wou ...

What could be causing site container not to respond to height:auto?

I have encountered an issue while developing a website using absolute height values. I am puzzled as to why the height:auto property is not working for me. Can anyone provide some insight on this? HTML Structure <div id="site-content"> <div id=" ...

Scroll horizontally on a webpage using drag with JavaScript

I have been working on a unique horizontal website design that allows users to scroll horizontally by dragging the screen. I managed to successfully implement the horizontal scrolling feature, but I am facing difficulties in adding the horizontal drag-to-s ...

What is the functionality behind this unique SCSS mixin that combines flexbox and grid layouts?

Discover a SCSS mixin for creating flexbox/grid layouts HERE. Take a look at the complete mixin code below: @mixin grid-col( $col: null, $grid-columns: 12, $col-offset: null, $gutter: null, $condensed: false, ...

Accessing information from a database and showcasing it within a tooltip

I have successfully implemented a tooltip feature using JavaScript and integrated it into an HTML page. Check out the code snippet below: $(document).ready(function () { //Tooltips $(".tip_trigger").hover(function (e) { tip = $(this).find('.tip&a ...

Why isn't the background image showing up on iOS devices when using the slider?

The website's background image displays on all devices such as laptops and Android phones, but not on iOS mobile devices. I even resized the image to 768px * 365px, but it still doesn't work. .bg-img { position: absolute; left: 0; ...

Setting the default styling for unordered lists in Material-UI React is a breeze with these simple steps

Currently, I am attempting to recreate a basic blog using markdown with Next.js and Material-UI. However, it appears that something is stripping away the default styles from unordered lists. The list items (HTML elements) have been set with list-style: no ...

The responsiveness of cards within the carousel-inner needs improvement

Despite successfully creating a carousel with 12 cards and 6 cards on each side, I am facing challenges with the responsiveness on mobile screens. I have tried numerous methods to make it responsive but have not achieved the desired results. The behavior o ...

What strategies can be implemented to avoid using .stop() in specific scenarios?

Currently, I am working on a jQuery animation where clicking on a tile should display its information by hiding all other tiles and showing its details. While I have implemented .stop() to prevent queuing issues, I encountered a problem with the transition ...

Triggering modal activation upon clicking on the SVG map

Seeking advice on the best way to implement a new feature. I have an SVG map with tiny blue icons that users can click on. You can refer to the image below for clarity: https://i.sstatic.net/XHry9.png Whenever a user clicks on any of these blue icons, I ...

Begin the div at a width of 0 pixels and expand it towards the right

My current project involves opening a row of blocks with an animation. The desired outcome is to transition from 2 blocks to 3 blocks by clicking a button. Specifically, the block that needs to be added should appear in the middle and fade in from left to ...

Simple Steps for Dynamically Adjusting Table Cells without Disturbing Existing Data

Is there a way to make a table automatically arrange cells in rows of two, adjusting as necessary when adding or removing cells (with one cell in the last row if there is an odd number of total cells)? For example: <table> <tr> <td>o ...

"Exploring the dynamic manipulation of CSS display property through the use of an active class

When attempting to implement a small pop-up window for user confirmation before navigating away from the page, I encountered an issue. Upon clicking the RUN button with the id "openBtn," the pop-up window briefly appears and then disappears. I'm unsur ...

The divs are intersecting each other

For some reason, when I try to add another section under the jumbotron it overlaps with the jumbotron. I have included my code below: http://www.bootply.com/IUd0GWEuAn ...

Extra space within table in Firefox

Experiencing an issue with excess whitespace in a table on Firefox. Visit the live example at The problem can also be seen on this jsFiddle: http://jsfiddle.net/DVbCC/ In Chrome and Safari, rows are neatly arranged with minimal spacing, but Firefox show ...

The container refuses to show the padding

I'm facing an issue with my .container where the padding is not displaying correctly. I've tried various methods but the padding just won't work as expected. CSS: nav{ border-style: solid; border-color: green; float: left; ...