The Power of HTML Floating Elements

<nav>
    <div class="row">
       <img src="resources/img/logo-white.png" alt="logo" class="logo">
           <ul class="main-nav">
               <li><a href="#">Food delivery</a></li>
               <li><a href="#">How it works</a></li>
               <li><a href="#">Our cities</a></li>
               <li><a href="#">Sign up</a></li>
           </ul>
   </div>
</nav>

I am currently following an online tutorial on Udemy which includes the code above for a navigation bar. The CSS for the navbar is shown below:

.row {
    max-width: 1140px;
    margin: 0 auto;
}

.logo {
    height: 100px;
    width: auto;
    margin-top: 20px;
}

.main-nav {
    float: right;
    list-style: none;
    margin-top: 60px;
}

I am puzzled by the positioning of the image within the div with the class="row". Even though I did not specify float: left for the img, it is displayed in the top left corner. Contrarily, I had to set float: right for the ul with the class="main-nav".

https://i.sstatic.net/dAzVG.png

Answer №1

It's interesting to note that the img element is considered inline, while the ul element is classified as block level. This distinction means that the ul element will automatically occupy 100% of the width and appear on a new line, while the img element will only take up the width specified by its dimensions. Additionally, since the default text direction is left-to-right (ltr), all inline elements will be aligned to the left side of the page.

Answer №2

The default direction for every HTML element is set to "LTR," which means that the logo will appear on the left side even without specifying a "float: left" line.

For more information, check out this link. Happy coding!

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

Approach to converting between metric and imperial measurements for weight and height

When prompting users to enter their weight, it's important to consider both metric and imperial units. One convenient approach might be to provide a dropdown menu for users to choose their preferred unit of measurement before filling in the correspond ...

What is the best way to stylize a date using Bootstrap-datepicker?

While this topic is well-known, I have a slightly more complex question regarding it. I have gone through the documentation here. My goal is to display the date in French format (dd/mm/yyyy) and save the value in US format (yyyy-mm-dd). Additionally, I nee ...

What techniques can be used to create logos that adapt and transform seamlessly as the screen size varies?

The way Responsive Logos adjust their image width when you resize the browser is truly impressive. It seems like they are using SVG images, but I'm not entirely sure how they are able to make the image change dynamically. Could it be through the CSS c ...

Place a Button or Link Right Below the Title on the Custom Post Type Editing Page

I am currently working on customizing the backend of a WordPress site for a client by adding multiple custom post types. These custom posts are only meant to be displayed on the front-end through a specific loop on one page, preventing users from accessing ...

What is the best way to make a hyperlink in HTML open in the same page or window, without relying on the <iframe> tag or JavaScript?

I have two html files and one css file. My question is how to open the link monday.html on the same page or window in my content section. For example, when someone clicks on the Monday navigation button, I want the result to show up in the content section ...

Are there any pre-existing pop-up methods available for AngularJS?

Is there a way to create a simple pop-up window with static text and just one "Ok" button? In Java/Swing, it's possible to achieve this with just one line of code using pre-defined classes. However, when it comes to Angular pop-ups, it seems like the ...

How can I maintain circle radius while resizing SVG to 100% width?

Our line graphs are drawn using SVG technology: https://i.stack.imgur.com/PLpPT.png When generating SVG, the width is set to 100%, but the exact value remains unknown. To ensure that the SVG fills the entire width without distortion, we use preserveAspec ...

Tips for creating an editable div that can also incorporate a textarea and the option to upload or delete photos

On my website, users can upload images, names, and descriptions which are saved in a MySQL database. The information is then fetched to display on the website. The code below allows users to enter this information and see it displayed when they click the s ...

Tips for dynamically assigning unique IDs to HTML form elements created within a JavaScript loop

let count = 0; while (count < 4) { $('#container').append("<div><input type='textbox' class ='left' id='left-${count}'/><input type='textbox' class ='right' id=' ...

Troubleshooting CSS rendering issues on Chrome browser

Currently in the process of developing a new website based on an old template. The site appears as intended in IE, Safari, and Firefox, but for some reason Chrome is not rendering any of the css. Just to clarify, none of the links are functioning at this ...

What is the best way to incorporate multiple versions of jQuery on one webpage?

Is it possible to use multiple versions of jQuery on a single page? I need two different versions for various functions, but they seem to be conflicting with each other. If I implement jQuery noconflict, will the product scripts still work? <script typ ...

Step-by-step guide on redirecting a page from a Django form

I'm in the process of developing a dictionary application that allows users to input a word through a form. The issue I'm facing is that when a user enters a word and hits submit, the form disappears leaving only the submit button and the search ...

When the div tag exceeds its boundaries, apply a new class

I am working on a div with set dimensions, and I am populating it with content using ng-repeat. My goal is to apply a CSS class to this div when it exceeds its limits. I attempted to use the length property but without success. var app = angular.module( ...

Tips for optimizing the loading of an HTML5 video on page load

I have a page with 4 videos that I am embedding using the "video" tag with the "preload" attribute. Everything is functioning as intended, but I am wondering if there is a method to preload the videos in the background, ensuring they are fully loaded eve ...

How can I prevent Bootstrap from conflicting with my custom styles?

My HTML menu was functioning perfectly with specific CSS styles, until I decided to add a Bootstrap reference in the header: New Link Added <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> Afte ...

Creating a personalized mouse cursor using HTML

I am trying to set an image as my cursor inside a div container but I want it to disappear and revert back to a normal pointer cursor when the mouse hovers over any link within that div. Here is my code snippet: var $box = $(".box"); var $myCursor = $ ...

How can I adjust the font size in a TextField when it is in focus?

As a novice in ReactJS, I am currently utilizing materia-ui to design a page. I am looking to make a custom change on a TextField where the font size adjusts when text is entered. However, adjusting the font size creates too much space between the label a ...

Adhesive Navigation Bar

Check out this link: JSFIDDLE $('.main-menu').addClass('fixed'); Why does the fixed element flicker when the fixed class is applied? ...

empty area located on the right side of my HTML/CSS website

I'm struggling to figure out why a small white space appears next to my webpage. Inspecting the element shows that the body ends before the space begins, indicating the border is where it should be. As a beginner in HTML and CSS, I hope this issue wil ...

Adding CSS files to a JSP page in Spring MVC

This is how my project's structure looks like: webapp: resources: css: test.css WEB-INF: pages: mvc-dispatcher-servlet.xml web.xml I am working on including a .css file in my jsp. mv ...