What is the best way to condense text within a header and still maintain right-aligned buttons?

I'm having trouble using css to position some buttons on the right side of my header, while also ensuring that the text collapses if it becomes as wide as the buttons. I want to maintain justification and show ellipsis for the main text of the breadcrumb trail, but I'm struggling to make it work.

Here's a link to the Fiddle for reference: https://jsfiddle.net/hLcm8jsf/

I've tried using justify-content and text-overflow, but they don't seem to achieve the desired effect. The buttons are just jumping down to a new row. I would appreciate any help as I'm still learning css.

body {
    font-size: 16px;
    background-color: #222;
    color: white;
}
h2 {
    font-size: 2em;
}
a {
    color: rgb(85, 109, 172);
}
a:hover {
    color: rgb(85, 109, 172);
}
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  display: none !important;
}
.row {
    margin: 0px;
    padding: 3px;
    width: 100%;
}
.rowjustify {
    justify-content: space-between;
}
.header {
    background: #002550;
    display: flex;
    height: 40px;
    overflow: hidden;
    white-space: nowrap;
}
.textbreadcrumb {
    margin-top: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: auto;
}  
<div class="row header rowjustify">
  <div class="textbreadcrumb">
    <a href="" ng-show="showPhotos||showImage||showConfig" ng-click="setPage('Albums')">Albums</a>
    <span ng-show="true">>
      <a href="" ng-click="setPage('Photos')">{{album name here}}</a>
    </span>
    <span ng-show="showImage">&nbsp;>&nbsp;{{photo name here, which can be a long name}}</span>
  </div>
  <div ng-show="showImage">
    <button type="button" class="btn btn-primary btn-sm" ng-click="prevImage()" ng-disabled="photo_id==0">Prev</button>
    <button type="button" class="btn btn-primary btn-sm" ng-click="nextImage()" ng-disabled="photo_id >= gallery.albums[album_id].photos.length-1">Next</button>
    <button type="button" tooltip="Set as Album Cover Photo" class="btn btn-primary btn-sm" ng-show="showLogin" ng-click="setCover()">Set As Cover</button>
  </div>
</div>  

Answer №1

To ensure this function properly, you must complete two tasks:

  1. Include display: flex;, flex: 1;, and min-width: 0; in the .textbreadcrumb CSS class
  2. Add text-overflow: ellipsis;, white-space: nowrap;, and overflow: hidden; to the span containing the text that needs truncation

The first step is vital due to how text wrapping occurs within flexbox children.

For more information, refer to:

and
https://css-tricks.com/flexbox-truncated-text/

The second step is essential as it specifies where the overflow should happen within the span element holding the text.

View a demonstration with these additions:
https://jsfiddle.net/withn/6t1s3x2w/

<div class="row header rowjustify">
  <div class="textbreadcrumb">
    <a href="" ng-show="showPhotos||showImage||showConfig" ng-click="setPage('Albums')">Albums</a>
    <span ng-show="true">>
      <a href="" ng-click="setPage('Photos')">{{album name here}}</a>
    </span>
    <span ng-show="showImage" class="temp1">&nbsp;>&nbsp;{{photo name here, which can be a long name}}</span>
  </div>
  <svg viewBox="0 0 56 18">
    <text x="0" y="15">Fit Me</text>
  </svg>
  <div ng-show="showImage">
    <button type="button" class="btn btn-primary btn-sm" ng-click="prevImage()" ng-disabled="photo_id==0">Prev</button>
    <button type="button" class="btn btn-primary btn-sm" ng-click="nextImage()" ng-disabled="photo_id >= gallery.albums[album_id].photos.length-1">Next</button>
    <button type="button" tooltip="Set as Album Cover Photo" class="btn btn-primary btn-sm" ng-show="showLogin" ng-click="setCover()">Set As Cover</button>
  </div>
</div>

body {
    font-size: 16px;
    background-color: #222;
    color: white;
}
h2 {
    font-size: 2em;
}
a {
    color: rgb(85, 109, 172);
}
a:hover {
    color: rgb(85, 109, 172);
}
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
  display: none !important;
}
.row {
    margin: 0px;
    padding: 3px;
    width: 100%;
}
.rowjustify {
    justify-content: space-between;
}
.header {
    background: #002550;
    display: flex;
    height: 40px;
    overflow: hidden;
    white-space: nowrap;
}
.textbreadcrumb {
    min-width: 0;
    display: flex;
    flex: 1;
    margin-top: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: auto;
}  
.temp1 {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

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

Why does my anchor appear with a different style compared to my submit button?

I encountered an issue where I have created a submit button and anchor link with the same class name and style, but they are displaying differently. The anchor link appears to be larger than the submit button. You can see the difference in size here: http ...

Fetch colors from an API to dynamically update the colors in tailwind.config.ts using Next.js

When I decided to incorporate SEO into my React project, I opted for Next.js. However, I encountered an issue when trying to load colors from the backend to be used in tailwind.config.ts. Does anyone know how to accomplish this with Next.js? ...

Having issues with a PHP script that is supposed to generate a webpage

I have been studying web development through the "PHP and MongoDB Web Development" book, where they provide a code snippet for creating a blog post creator. <?php $action = (!empty($_POST['btn_submit']) && ($_POST['btn_submit&apo ...

Mastering the art of utilizing particles.js

Particles.js doesn't seem to be functioning properly for me—I'm struggling to pinpoint the issue. Any guidance or suggestions would be greatly welcomed, as I'm unsure whether it's related to an external dependency... HTML: <div ...

How can I set up a cycling image background for the main div and a floating menu?

I was wondering how I could keep a cycling image background stationary behind the main content while scrolling through the page. You can check out the project itself by following this link. Feel free to use any of the code, including the fixed header menu, ...

Extend full width of the page with DIV element

I am looking for a way to make a div expand to the full width of the HTML document based on its content. Consider this scenario: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Traditional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&g ...

Switching Over to Burger Menu

I created a burger menu using HTML, CSS, and jQuery that switches from a full-width menu to a burger menu. However, I'm facing an issue with toggling the dropdown when the menu collapses. Here's my code: <!DOCTYPE html> <html> < ...

What is the optimal backup plan for selecting rem as the font-size unit in a dynamic layout?

Recently, I started pondering the best fallback option to use when employing rem as the font-size unit. While pixels seem like a suitable choice, it becomes cumbersome to adjust every px-based font-size if you decide to modify the global font-size within a ...

The plugin's element is not compatible with jQuery methods

This particular plugin is designed to enhance the appearance of checkbox inputs. It creates a more visually appealing version of standard checkboxes. However, I have encountered an issue with one of the variables in the code. Let's discuss the theLab ...

What is the significance of the space between form.validate and .ng-invalid-email.ng-dirty?

I'm currently working on an AngularJS application and I'm confused about the spacing between "form.validate" and ".ng-invalid-email.ng-dirty" in the stylesheet code below: <style> form.validate .ng-invalid-required.ng-dirty {background ...

The Wonders of Flex Box and Media Queries

Can a website still be made responsive without relying on media queries when flexbox is already implemented? Are there specific scenarios where the utilization of media queries offers enhanced control? ...

Opting for <button> over <a>

I am currently working with ReactJS in conjunction with a Bootstrap Nav Bar. Bootstrap utilizes an <a> tag for the navigation buttons. I am aiming to have the buttons scroll down to a different component on the page without resorting to using an href ...

Comparing `height: calc(100vh);` to `height: 100vh;` in CSS can reveal a few

Currently tackling a project where the previous developer utilized: .main-sidebar { height: calc(100vh); } Unfortunately, I can no longer reach out to them, and I am curious about the variance (if any) between the two approaches. (Am I in the approp ...

Trouble with CSS positioning

Styling with CSS: .one { width: 13%; } .two { width: 30%; } .three { width: 30%; } Formatting in HTML: <table> <tr> <th class= "one">Quantity</th> <th class= "two">Info</th> ...

Styling Images Inside a DIV Container Using CSS Float

Considering that I have 2 divs with images and text, I encountered some formatting issues when attempting to float the image to the left using float:left;. The strange formatting is ruining the layout. Below, I've included my code snippet along with a ...

The best way to identify $container-max-widths in Bootstrap

I've been working on customizing Bootstrap 4 and making changes to the breakpoints. My current setup is as follows: $container-max-widths: ( xs: 540px, sm: 700px, md: 960px, lg: 1140px, xl: 1300px, g: 1560px, xg: 1920px ) ...

Struggling to incorporate a basic drop-down into my design despite implementing transitions

Looking to optimize space on a webpage, I am interested in creating a hover effect for topics that reveals sub-topics with a smooth ease-out animation. Here is an example of the effect I am aiming for: https://jsfiddle.net/170z6pj1/ I have been strugglin ...

Is there a way to prevent tags from wrapping and showcase them all in a single line when utilizing the jQuery select2 plugin?

I have a requirement to prevent tags from wrapping and instead display them in a single line using the jQuery TagIt plugin. Check out my preview: https://i.stack.imgur.com/lYhsi.png My goal is to have all the tags displayed on a single line without wra ...

Webpack struggles with handling css using the css-loader when trying to implement (react)-css-modules

Trying to set up webpack with react and (react)-css-modules, but encountering an issue where webpack is unable to parse the css. This is the standard configuration being used. const webpack = require("webpack"), merge = require("webpack-merge"), path ...

Having trouble positioning items correctly in Bootstrap 4.5?

My attempt to align two elements in HTML using Bootstrap is not yielding the desired outcome. Here is the code I am currently using: <div class="row align-items-center"> <div class="col-auto"> <h6>Alignment Testing</h6> ...