Placing a collection of <a> anchor tags inside a div and making them float

I've been experimenting with building a website from scratch, opting for a simple and blocky design. I placed the navigation at the top of the page in an unordered list format containing <a> elements within list tags, all enclosed within a <nav> tag like this;

* {
  margin: 0;
}
html,
body {
  height: 100%;
  margin: 0;
}
.bdy {
  display: block;
  margin: 0;
  background-color: #d2d2d2;
  height: 85%;
  float: left;
  width: 100%;
}
nav.navbar {
  margin: 0;
  padding: 0;
  height: 15%;
  width: 100%;
}
nav ul {
  float: left;
  list-style-type: none;
  height: 100%;
  text-align: center;
  background-color: #326ada;
  width: 97.9%;
}
nav.navbar li {
  display: inline-block;
  float: left;
  bottom: 0;
  margin-left: 1%;
  margin-top: 10%;
}
nav li a {
  text-decoration: none;
  color: white;
}
<nav class="navbar">
  <ul>
    <li><a href="#" class="first">Home</a></li>
    <li><a href="#">Assignments</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>
<div class="bdy">
  <p>content</p>
</div>

I'm aiming to position the unordered list elements always at the bottom of the Navigation area (Blue), approximately 10px from the bottom. Using margins with percentages hasn't yielded the desired outcome. Is there a way to float the list downward without disrupting the existing order?

Answer №1

To improve the layout and alignment of the text within each a tag, you can refrain from using the % margin. Instead, consider aligning the text to the bottom of the lists with this code snippet:

* {
  margin: 0;
}
html,
body {
  height: 100%;
  margin: 0;
}
.bdy {
  display: block;
  margin: 0;
  background-color: #d2d2d2;
  height: 85%;
  float: left;
  width: 100%;
}
nav.navbar {
  margin: 0;
  padding: 0;
  height: 15%;
  background-color: red;
  width: 100%;
}
nav ul {
  float: left;
  list-style-type: none;
  height: 100%;
  text-align: center;
  background-color: #326ada;
  width: 97.9%;
}
nav.navbar li {
  float: left;
  height:100%;
  bottom: 0;
  margin-left: 20px;
  box-sizing:border-box;
  padding-bottom:10px;
  white-space:nowrap;
}
nav li:before {
  content:"";
  height:100%;
  display:inline-block;
  vertical-align:bottom;
}
nav li a {
  text-decoration: none;
  color: white;
}
<nav class="navbar">
  <ul>
    <li><a href="#" class="first">Home</a></li>
    <li><a href="#">Assignments</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>
<div class="bdy">
  <p>content</p>
</div>

Answer №2

It appears that your CSS code contains a lot of unnecessary elements. Take a look at my snippet below, which may align more closely with what you are aiming to achieve.

* {
  margin: 0;
}

html,
body {
  height: 100%;
  margin: 0;
}

.bdy {
  min-height: 85%;
  background-color: #d2d2d2;
}

nav.navbar {
  position: relative;
  height: 15%;
  background-color: red;
}

nav ul {
  position: absolute;
  width: 100%;
  bottom: 0;
  list-style-type: none;
  text-align: center;
  background-color: #326ada;
  padding: 5px 0 2px 0;
}

nav.navbar li {
  display: inline-block;
  margin-left: 1%;
}

nav li a {
  text-decoration: none;
  color: white;
}
<nav class="navbar">
  <ul>
    <li><a href="#" class="first">Home</a></li>
    <li><a href="#">Assignments</a></li>
    <li><a href="#">Blog</a></li>
  </ul>
</nav>
<div class="bdy">
  <p>content</p>
</div>

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

Looking for straightforward tips on parsing CSS code

Seeking advice on how to extract rules and property/values from a .css file or <style></style>. I am not in need of an elaborate parser, as the validity of selector text, property name, or value is not important. My main focus is ensuring that ...

What is the difference between using min-height in vh versus % for the body tag

I'm trying to understand a code where the min-height of the body element is set to 100vh after previously defining the height of the html element as 100%. Why is there a need for this specific sequence? body { position: relative; overflow: hidd ...

Display content from an external HTML page within a div using Ionic

Currently, I am facing an issue where I am utilizing [innerHtml] to populate content from an external HTML page within my Ionic app. However, instead of loading the desired HTML page, only the URL is being displayed on the screen. I do not wish to resort t ...

How to display HTML on top without altering the viewport in React?

I am trying to display a component <Top /> above another component <Bottom /> in React. The code structure is as follows: ... [top, setTop] = useState(false); [bottom, setBottom] = useState(true); ... return ( <div> top && (< ...

What is the reason for the overflow occurring in a container of identical size due to this particular element?

I've encountered an issue while trying to create a div with a scrollbar that only appears when the elements within it don't fit the default area. <div style="overflow-y: auto; height: 36px;"> <img src="." width="36" height="36" /> ...

Determine the size of a file in either megabytes or kiloby

I need to determine the size of a file in either megabytes if the value is greater than 1024 or kilobytes if less than 1024. $(document).ready(function() { $('input[type="file"]').change(function(event) { var _size = this.files[0].si ...

The $watch() function seems to be failing to properly refresh the $scope

Within my controller, I have a function $scope.remove() that triggers a request to the usercart, which then calls an API. The JSON response from the API includes an object with an array of cart items. Despite using an ng-repeat in the HTML to iterate thro ...

Form submission not capturing multiple HTML select options

I have encountered an issue with a form that contains 2 fields: a hidden field and a multiple select. Upon form submission, the hidden field successfully reaches the django views.py file, but the selected values from the multiple select do not get transmit ...

The spinner persists even after the fetch api call

The issue I'm facing with my song lyrics app is that the spinner does not disappear after fetching data from the API. It seems like JavaScript is unable to detect the presence of the spinner even though it exists when the remove function is called. I ...

Custom Pug design without any CSS files added

I am having trouble with my .pug template in my express project as it is not including its stylesheets. I have referred to the pug documentation but still can't figure out the issue. Any help would be appreciated! FILE TREE: views `-- index.pug `-- ...

Searching for hidden elements within a div using a filter option

An accordion is located inside a div and a search box has been added to the div with the intention of serving as a search filter. Some accordion elements are visible within the div while others are hidden. The problem arises when trying to make the filter ...

Stop the form submission until validation is complete

I'm currently working on a form and encountering some validation issues. HTML: <form id="regForm" class="form-group" method="POST" action="signup.php"> <div class="col-md-12"> <h2>Job Pocket</h2> </div> <di ...

Dropdown menu featuring a customizable input field

Is it possible to have a drop-down list with an input textbox field for creating new items in the same dropdown menu? ...

Storing HTML table data in a MySQL database will help you

Operating a website focused on financial planning where users can input various values and cell colors into an HTML table. It is crucial to uphold the integrity of these HTML tables. How can I store the complete HTML table (including values and colors) i ...

How to position a div in the center of another div using HTML

I'm struggling to center the bottom div within a container that includes 3 other divs. Despite trying multiple solutions found online, nothing seems to work. This task should be simple, but for some reason, I can't get it right. .container { po ...

Tips for deleting "Category: [category name]" in Wordpress

I have attempted various solutions found in previous threads, but none of them seem to work for me. Here is a screenshot I am looking to remove the text from the header in the category and only display [category name]. Can anyone assist me with this, ple ...

What are some ways to ensure that text can adapt to the size of a

I am looking to create dynamic text that adjusts based on the size of its parent container. As the parent container's size changes, I want the text to automatically adjust accordingly. Specifically, I want the text in a widget to resize when the widg ...

Choosing and adding a div to another using the select method

Can someone assist me with this task? My goal is to dynamically append a div when selecting an option from a dropdown, and hide the div when the same option is selected again. Additionally, I want the name of the selected option to be displayed on the left ...

What are the steps for transforming an HTML page into a fully-fledged Vue or React project?

I have been customizing a dashboard using AdminLTE 3, removing unnecessary parts and modifying the HTML and CSS files. However, I now need to convert this project into either a Vue or React project. Currently, all I require is an index.html file with a bla ...

Show HTML form elements on the page using jQuery or JavaScript

Is there a jQuery or JS library that can perform the following task: If the user inputs 'x' in A01, then make A01_1 visible. Otherwise, do nothing. <form id="survey"> <fieldset> <label for="A01">A01</label&g ...