The art of perfecting the spacing and placement of a navigation bar

Is there a way to align Brand slightly to the right, while also positioning About Portfolio and Contact on the right side with some space between them without relying on margin and padding? A sample of what I'm referring to can be seen here:

<div class="navbar">
      <ul>
        <li id="brand"><a href="#">Brand</a></li>
        <li id="about"><a href="#">About</a></li>
        <li id="portfolio"><a href="#">Portfolio</a></li>
        <li id="contact"><a href="#">Contact</a></li>
      </ul>
    </div>



*{
  margin:0;
  padding:0;
}
.navbar{  
  top:0;
  position:fixed;
  width:100%;
  background-color:rgb(114, 40, 114);
}
ul{
  list-style:none;
  display:flex;
  flex-flow: row nowrap;
  background-color:rgb(114, 40, 114);
  height:80px;
  justify-content:space-between;
  align-items:center;
}

ul #brand{  
  text-align:center;


}

ul #about{

}
ul #portfolio{

}

ul #contact{

}

ul li a:hover,
ul li a:focus{
  text-decoration:none;
  color:white;
}

Answer №1

Try using the following CSS properties:

width: calc(100% - 50px); margin: 0 auto;

*{
  margin:0;
  padding:0;
}
.navbar{  
  top:0;
  position:fixed;
  width:100%;
  background-color:rgb(114, 40, 114);
}
ul{
  list-style:none;
  display:flex;
  flex-flow: row nowrap;
  background-color:rgb(114, 40, 114);
  height:80px;
  justify-content:space-between;
  align-items:center;
  width: calc(100% - 50px);             /*  added property  */
  margin: 0 auto;                       /*  added property  */
}

ul #brand{  
  text-align:center;
}

ul #about{

}
ul #portfolio{

}
ul #contact{

}

ul li a:hover,
ul li a:focus{
  text-decoration:none;
  color:white;
}
<div class="navbar">
      <ul>
        <li id="brand"><a href="#">Brand</a></li>
        <li id="about"><a href="#">About</a></li>
        <li id="portfolio"><a href="#">Portfolio</a></li>
        <li id="contact"><a href="#">Contact</a></li>
      </ul>
    </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

Creating HTML classes based on PHP conditional statements

Exploring the possibility of defining HTML classes within PHP if else statements. Consider this example: <?php if (condition 1) { ?> <span class = 'class1'>Line 1</span> <?php } else if (condition 2) { ?> <span class = ...

The feature to hide columns in Vue-tables-2 seems to be malfunctioning

The issue I'm facing is with the hiddenColumns option not working as expected. Even when I set it to hiddenColumns:['name'], the name column remains visible. I've updated to the latest version, but the problem persists. UPDATE I am tr ...

Font discrepancies in HTML field types "text" and "textarea" are causing inconsistent font display

Why do the text in my "text" and "textarea" fields show different fonts on my pages' HTML? I attempted to specify the font type in both the background CSS file and within the HTML, but it did not resolve the issue. Just to be transparent...I'm ...

Necessary CSS selector input equivalent in Reactive Forms

Is there a similar CSS method like input:required {CSS} to style all the reactive form fields in Angular that are set as required using Validators.required in their formControl? Or is there another approach to achieve this with CSS? ...

What's the most effective method for incorporating lengthy HTML snippets into a single-page application?

As I develop a simple single page application, the focus remains on a few user views to manage local storage data without using any templating framework. Although it's primarily JavaScript/jQuery right now, the thought of incorporating Backbone or ano ...

Is there a way to launch only a single popup window?

Recently, I came across this piece of Javascript code which is causing me some trouble: function call() { popup = window.open('http://www.google.co.in'); setTimeout(wait, 5000); } function caller() { setInterval(call, 1000); } func ...

Registering a change event for a table's value

I am a beginner in Angular and struggling with writing an event that can successfully pass the changed value from a table cell to my component. Below is the HTML code for the table cell, where the user should be able to change the value and have it passed ...

Trimming Text with JQuery

My goal was to truncate a string and add an ellipsis at the end using jQuery, but my code doesn't seem to be working as intended. Below is the jQuery code I wrote: $(".link-content > h4").each(function(){ var len = $(this).text().length; ...

Extract hidden form variables using a function in PHP

Here is the JavaScript function that I have written: function GetCellValues() { var rows = document.getElementsByTagName('tr'); var str = ''; for (var c = 1 ; c < rows.length ; c++) { str += '\n&apo ...

Issues encountered with Element clicking in Span Div CSS dropdown frame using Selenium Web Driver

I am facing a challenge with a sophisticated epiphany web application that is only compatible with IE. The user interface involves multiple frames, one of which contains a Button that, upon being clicked, reveals a set of menu options. Here is the HTML cod ...

Converting Beautifulsoup4's findAll() method output of HTML into a list of strings using Python

I'm just starting to explore Python, as I have a project idea in mind that I believe could be achieved by web crawling with Python. Currently following a tutorial series, I know that some consider findAll() to be outdated (I'm not sure why, but ...

Is it feasible to set the width as automatic in this scenario?

Example 1 demonstrates my goal, but it's challenging to set a fixed width for .sub due to the addition of new items. The width needs to adjust accordingly. However, when no width is specified, Example 2 displays the result. Are there any methods to ...

Bizarre Actions of a JavaScript Object

Currently, I am in the process of developing a Multiplayer game using Phaser and Eureca io. My main focus right now is on perfecting the authentication of players and their controls. To achieve this, I have implemented a method on the server that retrieves ...

The use of absolute positioning in conjunction with overflow:hidden

<div id="container" style="overflow:hidden; position:relative;"> <div id="content" style="position:absolute;"> </div> </div> Is it possible to display the content element which is larger than its parent container, while still k ...

When I refresh the page, the table expands in both Google Chrome and Opera browsers

After creating an HTML table, I noticed that when I refresh my page, it appears stretched out in Google Chrome and the Opera web browser. However, when tested in Internet Explorer and Firefox, the table displays normally. The oddly sized table after a pa ...

Tips on concealing all classes except one through touch swiping

If you have a website with a single large article divided into multiple sections categorized as Title, Book1, Book2, & Book3, and you want to implement a swipe functionality where only one section is displayed at a time, you may encounter some issues. ...

Space allocation among the columns' borders

My layout consists of 3 columns in a row, each with the class col-xs-4, covering the entire row. I am trying to add a border to each column without them overlapping. Currently, I have applied the border but there is no spacing between the columns. I want ...

Preventing CakePHP from inserting comment tags in the output

Currently, I am working on creating an endpoint that will return JSON data. {"a":1,"b":1} Surprisingly, when my code runs, Cake inserts an HTML tag into the output result. {"a":1,"b":1} <!-- 0.0964s --> This unexpected formatting is causing issue ...

Why isn't the Full Calendar loading automatically within a Bootstrap Tab?

I have been working on a travel website and incorporated a bootstrap tab feature. In the first tab, I have some content, while in the second tab, I've added a full calendar with JavaScript. Everything seems to be functioning correctly when the full ca ...

Persist the current scroll position of a div in local storage using React

Despite the numerous questions I've come across on this topic, none of them align with my approach. Most solutions involve window scrolling, but I have a div containing overflow items that I want to retain the user's scroll position for. My attem ...