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 that only the <li> elements within the header-list are horizontally aligned.

To achieve this, I made some adjustments to the code as follows:
 body {
          font-family: "Avenir Next";
        }

        .header-list li {
          list-style: none;
           float: left;
          padding: 33px 20px;
        }

        .header {
          background-color: #26d0c9;
          color: #fff;
          height: 90px;
        }

        .header-logo {
          float: left;
          font-size: 36px;
          padding: 20px 40px;
        }

        .header-list {
          float: left;
        }

        .main {
          background-color: #bdf7f1;
          height: 600px;
        }

        .footer {
          background-color: #ceccf3;
          height: 270px;
        }

Although the changes I made produced the desired outcome on the layout, when I tried to submit my answer, a popup appeared with the message:

The CSS for the float property of <li> elements should be deleted.

Confused by this, I revisited the instructions and realized that I needed to:

float: left;


padding: 33px 20px;

Hence, I modified the code once again, moving some CSS properties around to comply with this requirement. I found it puzzling why it was necessary to make these changes:

          body {
          font-family: "Avenir Next";
        }

        .header-list li {
          list-style: none;
        /* CSS properties from here are moved to line 32. But why? 
      We still get the required result without doing so.             
      */
        }

        .header {
          background-color: #26d0c9;
          color: #fff;
          height: 90px;
        }

        .header-logo {
          float: left;
          font-size: 36px;
          padding: 20px 40px;
        }

        .header-list {
          float: left;
        }

        .header-list li {
          float: left;
          padding: 33px 20px;
        }

        .main {
          background-color: #bdf7f1;
          height: 600px;
        }

        .footer {
          background-color: #ceccf3;
          height: 270px;
        }

Feeling a bit lost, I turned to the online community for insights. As a beginner, clearing these small concepts can be quite challenging. Any help or hints would be greatly appreciated. Stackoverflow, here I come!

Answer №1

To achieve a horizontal list layout, consider using display: inline; instead of floats. In this case, you can remove the float property from the CSS for <li> elements as mentioned previously. This method offers an alternative approach to displaying your list horizontally without the need for floats. Hopefully, this suggestion proves helpful!

If you're looking to further your knowledge, I suggest exploring The Net Ninja's YouTube channel. He is a fantastic teacher who covers a wide range of topics in a thorough and easy-to-understand manner. Whether you're interested in HTML, CSS, or other subjects, his playlists are a valuable resource. https://www.youtube.com/watch?v=I9XRrlOOazo&list=PL4cUxeGkcC9gQeDH6xYhmO-db2mhoTSrT

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

disable input box stationary

Is there a way to make a checkbox stay disabled even after refreshing the page? Currently, when I click the checkbox it disables, but upon refreshing the page, it goes back to being enabled. $( "input[type='checkbox']").click(function(event){ ...

Is there a way to adjust the height relative to the viewport in Bootstrap 5 for values other than 100?

Attempting to create a new type of div using a custom stylesheet with minimal non-bootstrap css. I am trying to convert each style rule from my django static files CSS into a bootstrap class, but I am stuck on viewport-based sizing. Prior to discovering t ...

How to centrally position an image within a div using Bootstrap

I am a fan of using bootstrap and I recently encountered an issue with applying max-width to an image. It seems that when I do this, the image does not center properly despite using text-center. The solution I found was simply removing the max-width to ...

How can I adjust my settings so that my image resizes from the center rather than the top left corner?

I'm having an issue with my code for resizing images on rollover - the image is currently resizing from the top left corner instead of from the center. How can I adjust it to resize from the center of the image? <script> $('i ...

Every single image within a specific domain

Exploring a way to create a gallery showcasing all the images within my domain's internet root folder. These images are scattered across various folders. What is the most efficient method to navigate through these folders and display the images? ...

Issue encountered when concealing page elements followed by revealing them again

My goal is to conceal an id within a page and then reveal it once all the JavaScript has finished loading on the page. The JavaScript I am using to display the content again is: $(document).ready(function() { $("#HomePage")[0].style.visibility = "visib ...

Error: unexpected syntax error at the end of the for loop in PHP MySQL

I encountered a puzzling issue with the "endif" statement after properly implementing code I found on YouTube with MySQL. <?php <?php for($x = 1; $x <= $pages; $x++); ?> <a href="?pages=<?php echo $x; ?>&per-page=< ...

Implementing a function trigger upon selection in JavaScript

I'm currently studying JavaScript and working on a basic project that involves generating random strings of different lengths. If you're interested, feel free to check out my codepen code [here][1]. My question revolves around the functionality ...

Adjust the number of columns displayed when rendering with Datatables

I've utilized DataTables to create a dynamic datatable. $('table').DataTable( { dom: 'Bfrtip', buttons: [ 'copy', 'excel', 'print', ], responsive: true } The table I created c ...

The justify-position attribute does not have any impact on the positions that are set

Here is the JSX code that resembles HTML but uses ClassName instead of class: <div className="snavbarcontainer"> <div className="toplefticon"> <a class="test" href=" ...

The element within the flexbox does not extend across the entire width, despite being designated as 100% full width

I'm currently attempting to center certain elements to ensure they are visually aligned. The upper div seems to have some odd space on the right, causing all the content within that div to be shifted and not accurately centered. On the other hand, th ...

What is the best way to apply styles to a React component that is passed as a prop?

I'm currently working on a component that is passed as a label prop. In order for me to utilize justify-content: space between within my div, I must ensure it has a width of 100%. You can see how this appears in the developer tools by clicking here. r ...

What is the best way to display a child div without impacting the position of other elements within the same parent container?

As I work with a div html tag within a login form, encountering an error inside this form has presented a challenging issue. The error div sits at the top of its parent div, and ideally, upon activation, should remain within the form div without disrupting ...

Tips for obtaining the dynamically loaded HTML content of a webpage

I am currently attempting to extract content from a website. Despite successfully obtaining the HTML of the main page using nodejs, I have encountered a challenge due to dynamic generation of the page. It seems that resources are being requested from exter ...

Utilizing absolute and relative positioning for setting up a flexible sidebar layout

I'm finding myself a bit puzzled when it comes to using Absolute and Relative positioning. In essence, I have a sidebar with about 4 divs in it. My goal is for div 3 to stay in the same position on every page, even if div 1 or div 2 are missing and c ...

Trigger a function when clicking outside the element, similar to how a Bootstrap modal is closed

I have successfully created a popup box using angular in my project. It appears when I click on an icon and disappears when I click on the close button. However, I would like it to also close if someone clicks outside of the popup. Can anyone help me with ...

Initiating the ngOnInit lifecycle hook in child components within Angular

I am facing an issue with controlling the behavior of child components in my Angular application. The problem arises when switching between different labels, causing the ngOnInit lifecycle hook of the children components not to trigger. The main component ...

Enhance your calendar with sleek jQuery styling

Currently, I am utilizing the jQuery-ui.css (smoothness) solely for the calendar CSS. Can anyone provide me with a comprehensive list of all the calendar CSS functions available in it? I'm looking to avoid using any unnecessary CSS that might be causi ...

Conceal table columns on an HTML page using CSS styling

HTML: <table class="list qy"> <tr> <td>cell1</td> <td class="q">cell2</td> <td>cell3</td> <td class="y">cell4</td> </tr> </table> CSS: table.qy td.q, table.qy td.y { displ ...

Unexpected behavior with HTML Bootstrap's dl-horizontal layout

Despite having the div class "dl-horizontal" within the table, the dl-horizontal fields are displaying outside the table. Here is the code I used: <!DOCTYPE html> <html lang="en> <head> <title>Bootstrap Example</title> ...