a basic three-tier flexible design with alignment to the lower right side

I am looking to create a dynamic header that adjusts based on the height of the svg logo and available width for the navigation:

layout1: https://i.sstatic.net/Oa8gB.png

If there is not enough space for all navigation buttons (a) to fit in one row next to the svg, then the nav block should move below the svg and take up the full width:

layout2: https://i.sstatic.net/2avAA.png

It's crucial that the nav block aligns to the bottom right corner of the parent header element.

I have researched, Googled, tried different methods but haven't found a satisfactory solution. Any suggestions using flexbox? Please, no JavaScript as I prefer to keep it pure.

Edit: This is my attempt so far: http://codepen.io/Kleajmp/pen/dYEeKW

html:

<header> 
      <div id="logo" class="col-3"><img src="http://www.dsunits.be/v4/img/DS_units.svg"></div>
  <nav>
    <a href="#">DS units</a>
    <a href="#">button2</a>
    <a href="#">button3</a>
    <a href="#">button4</a>
    <a href="#">button5</a>
    <a href="#">button6</a>
    <a href="#">button7</a>
    <a href="#">button8</a>
  </nav>
</header>

css:

header{ display:flex; align-items:flex-end; justify-content:space-between; }
div#logo{ display:inline-flex; align-items:flex-start; width:25%; }
div#logo img{ max-height:150px; }
nav{ display:inline-flex; cursor:pointer;  }
nav a{ display:inline-flex; flex-wrap:nowrap; }
nav a:hover{ color:white; background-color:#0099cc; border-top-right-radius:0.5rem; }

Answer №1

Alright, I'm a bit unsure about how this is all meant to come together, but I believe this code snippet is pretty close to what you're looking for.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background-color: rgba(0, 0, 0, 0.2)
}
header {
  background-color: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
}
#logo {
  flex-grow: 1;
  white-space: nowrap;
}
div#logo img {
  height: 150px;
}
nav {
  white-space: nowrap;
  flex-grow: 1;
  background: plum;
  display: flex;
  justify-content: space-between;
}
nav a {
  display: inline-block;
  color: black;
  text-transform: uppercase;
  text-decoration: none;
  padding: 8px;
  background-color: rgba(255, 255, 255, 0.9);
  line-height: 1rem;
}
nav a:hover {
  color: white;
  background-color: #0099cc;
  border-top-right-radius: 0.5rem;
}
<header>
  <div id="logo">
    <img src="http://www.dsunits.be/v4/img/DS_units.svg">
  </div>
  <nav>
    <a href="#">DS units</a>
    <a href="#">button2</a>
    <a href="#">button3</a>
    <a href="#">button4</a>
    <a href="#">button5</a>
    <a href="#">button6</a>
    <a href="#">button7</a>
    <a href="#">button8</a>
  </nav>
</header>

Check out the Codepen Demo here!

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

Combine two FontAwesome icons in a stacked manner

Is there a way to group 2 icons together and display them one above the other? I attempted to use the fa-stack class, but the images are overlapping. How can I achieve this layout? <span class="fa-stack fa-lg"> <i class="fa fa-envelope fa-stack ...

Looking to retrieve just your Twitter follower count using JavaScript and the Twitter API V1.1?

I am trying to retrieve my Twitter follower count using JavaScript/jQuery in the script.js file and then passing that value to the index.html file for display on a local HTML web page. I will not be hosting these files online. I have spent weeks searching ...

The Codepen demo for SemanticUI is not functioning properly

Click here to view the example on CodePen $('.ui.sidebar').sidebar({ context: $('.bottom.segment') }) .sidebar('attach events', '.menu .item'); I am currently trying to replicate this specific functiona ...

Unable to hear sound - JavaScript glitch

Spent countless hours trying to figure this out - Can't get the audio file to play when clicking an HTML element. var sound = document.querySelector(".soundfile"); function playAudio() { sound.play(); } document.querySelector(".btn-hold").addE ...

The index named "name" has not been defined

I keep encountering this message when trying to load the form: Notice: Undefined index: name in C:\xampp\htdocs\main.php on line 267 Notice: Undefined index: email in C:\xampp\htdocs\main.php on line 275 Notice: U ...

Tips for altering the class of an HTML button dynamically when it's clicked during runtime

I currently have a set of buttons in my HTML page: <button id="button1" onclick="myFunction()" class="buttonClassA"></button> <button id="button2" onclick="myFunction()" class="buttonClassA"></button> <button id="button3" onclic ...

SQL queries can be used in Node.js to fetch data from various tables and display it on an HTML page

I have a problem with my expressjs app where I am trying to count records from multiple tables in a database and display the results on separate divs in HTML. Currently, the code is functional without any errors, but I am encountering an issue where the sa ...

Retain the previously selected option in a PHP combobox even when changing pages

Can someone please assist me with my PHP code? I am having trouble keeping my combobox unchanged after a page reload. It works fine until I change pages in my pagination. Can anyone help? THIS IS MY PHP. PHP ...

Icon not appearing within the input group

Is there a way to design an input group that includes both a text field and an icon placed at the beginning of the text field? The code below demonstrates my attempted implementation, however, it appears that only the text field is visible without the acco ...

The margins within the div of the new tab are not applying as expected

Greetings! Currently, I am in the process of generating a dynamic form within a new tab using JavaScript. For some reason, the margin effects on the div element are not being applied correctly. Despite my attempts to set the margins using both classes and ...

Learn how to extract an ID created with AngularJS using JavaScript

I have a piece of code that generates multiple divs using ng-repeat and assigns each one an id based on a specific value. <div ng-repeat="item in $scope.items"> <div id="ajs-{{item.title}}">{{text}}</div> <script> v ...

Creating a smooth sliding textarea in HTML

I am working on creating an HTML table with numerous text input areas (textarea) that expand downwards when clicked. Currently, the textarea element expands properly but disrupts the layout of the table. My goal is to achieve a design like this Instead o ...

What is the best way to adjust the widths of a two-row header table using the table-layout: fixed property?

Here is the table header setup I am aiming for: <table class="tabel_op_panou" style="margin: 0px 2px 0px 2px; width: 99%; table-layout:fixed;"> <tr> <th rowspan="2" style="width: 35%;">A</th> <th colspan="2" style="width ...

Discovering the method for retrieving JavaScript output in Selenium

Whenever I need to run JavaScript code, the following script has been proven to work effectively: from selenium import webdriver driver=webdriver.Firefox() driver.get("https:example.com") driver.execute_script('isLogin()') However, when I atte ...

Tips for deciding on the appropriate CSS for an Angular 6 navbar component

I am currently working on an angular 6 application where users are assigned different roles that require distinct styling. Role 1 uses Stylesheet 1, while Role 2 uses Stylesheet 2. The Navbar component is a crucial part of the overall layout structure of ...

The image appears uniquely sized and positioned on every screen it is viewed on

After reviewing the previously answered topics on the site, I couldn't seem to make the necessary adjustments. Despite setting the size and location in the css file, the large image remains centered and fitting for the screen. The "imaged1" class seem ...

What is the best way to hide the button when a user is viewing their own profile in an Angular application?

Each user has their own profile on the platform. A unique feature allows users to send messages by clicking a button when viewing other profiles. However, an issue arises where this messaging button also appears on a user's own profile. Is there a way ...

I'm curious about this encoding method. Is there a way to convert it in UIWebView?

Can anyone help me figure out how to display these characters correctly in my UIWebView? The screenshot below shows that some European language characters are not being rendered properly. When I checked the original webpage, everything looked fine, so I th ...

How to Prevent Scrolling When Modal is in Use on Full Page JS

I am trying to achieve the functionality where when the modal is open, I want to prevent full-page scrolling in JavaScript. The issue arises when I open the modal and try to scroll, it ends up moving the content that's behind the modal, which is actua ...

How can I loop through SVG elements and attach an event listener to each one in JavaScript?

I am struggling with loading a simple SVG file and iterating through the shape nodes to add an onclick event. Unfortunately, after the SVG file is loaded, it cannot find the shape nodes. What could be the issue here? Here is the SVG code snippet: < ...