Eliminate any unnecessary spaces in the text of a link following the breaking of a word

While working on a navigation menu, I noticed that in large screens the navigation looks fine but in laptop view, the words are breaking up and it's acceptable. However, I want to remove the extra spacing after the text.

In the large screen:

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

In the laptop view, there is another image where I want to remove the space before the border.

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

For example, there is a gap between "App Service Performance" and "App Explorer" which I want to eliminate.

Below is the code I am currently using:

<Box
    display="flex"
    justifySelf="start"
    flex="1 1 0"
    alignItems="center"
    sx={{
        flexDirection: "row",
        width: "100%",
        alignItems: "center",
    }}
>
    {pages &&
        pages.map((page: Page, index: number) => (
            <Fragment key={page.id}>
                {index !== 0 && (
                    <Divider
                        sx={{ marginX: 1, paddingY: "15px" }}
                        orientation="vertical"
                        variant="middle"
                        flexItem
                    />
                )}
                <Typography
                    component={Link}
                    to={`/${siteId}/${page.id}`}
                    key={page.id}
                    sx={{
                        color:
                            page.id === activePage?.id
                                ? theme.palette.common.white
                                : theme.palette.grey["200"],

                        textDecoration: "none",
                    }}
                >
                    {page.name}
                </Typography>
            </Fragment>
        ))}
</Box>

Answer №1

To ensure each link stays on one line, you can apply the CSS property whitSpace: "nowrap" to each link element within your code:

<Box
  display="flex"
  justifySelf="start"
  flex="1 1 0"
  alignItems="center"
  sx={{
    flexDirection: "row",
    width: "100%",
    alignItems: "center"
  }}
>
  {pages &&
    pages.map((page, index) => (
      <Fragment key={page.id}>
        {index !== 0 && (
          <Divider
            sx={{ marginX: 1, paddingY: "15px" }}
            orientation="vertical"
            variant="middle"
            flexItem
          />
        )}
        <Typography
          component={Link}
          href={`/`}
          key={page.id}
          sx={{
            color: "#fff",
            textDecoration: "none",
            whiteSpace: "nowrap"
          }}
        >
          {page.name}
        </Typography>
      </Fragment>
    ))}
</Box>

In addition, remember to include the CSS property overflow-x: scroll in the parent header class for smaller screens to enable horizontal scrolling.

With these changes, the links should now remain on a single line. Thank you!

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

When resetting the function, make sure to move the class to the closest sibling element

I am currently utilizing a slider that employs the .prev and .next jQuery functions to toggle the active class, indicating which slide is being displayed. Here is the code responsible for this functionality. It identifies the current sibling with the acti ...

Hugo inquired about the process of including a class specifically for the final post

I've set up my baseof.html file to add the class first-post to the body tag in order to style the first post differently from the rest, especially when paginated: <body class=" {{ with where site.RegularPages "Type" "posts" }} {{ $first_post = ind ...

Difficulty with Material-UI Styled API: styling classes are not being properly applied to nested child elements

Struggling to set up a page in Material-UI v5. While I have experience with v4 and am starting to understand v5 better, the CSS styles are not being applied. Both my testcss and loadingBox classes seem to have no impact at all. What could be causing them ...

automatically collapse a submenu once a different menu option is selected

After doing some research and trying out various solutions, I still couldn't get it to work. I made adjustments to my dropdown menu and click function so that each submenu opens and closes when its parent is clicked. However, I'm now looking to f ...

"Excessive overflow results in the displacement of the following block

When viewing on smaller screens, the blocks move down due to oversized images causing overflow. Is there a way to simulate collision in this scenario? <div class="image"> <img src="img/1.jpg" /> </div> <div class="image"> & ...

Unable to display horizontal scrollbar for an oversized image

I am struggling to implement a horizontal scrollbar for a long picture in my React project. Despite trying various methods like MUI Card, Box component="img", and <img src=, I haven't been able to achieve the desired result. Google search results h ...

The TextBox will alter its color following an incorrect submission

I am struggling to create a bootstrap form that will change the color of the borders to red after incorrect submission. The issue I am facing is that the textbox always remains in red. Does anyone have any suggestions for setting the textbox borders to red ...

Having trouble implementing button functionality in a web app using JS, jQuery, HTML, and CSS along with an API integration

I am currently developing a web search engine that utilizes the Giphy API... However, I've encountered difficulties with the button function. I have created buttons to modify the page format and adjust the number of search results displayed.... The We ...

This code is only functional on JSFiddle platform

I encountered an issue with my code recently. It seems to only work properly when tested on jsfiddle, and I can't figure out why it's not functioning correctly on codepen or when run from local files. Why is this code specific to jsfiddle? When ...

Identifying the pressing of the enter key in an input field

Currently, I am developing an innovative IFrame browser that features an omnibox (identified as "address") and a "GO" button (identified as "submit"). One of the key challenges I'm facing is detecting when the user inputs information and hits the Ente ...

Issues with jQuery animate.css functionality specifically occurring on Firefox browser

As a beginner in jQuery, I have been exploring different animations and recently came across an issue with Firefox compatibility. I discovered the animate.css library, and decided to incorporate its animations into text captions on a slider using the Soli ...

Creating an animated transition for an element's height with CSS

I need to animate the height of a div that doesn't have a specified height. Using max-height isn't an option due to multiple potential height amounts. I attempted adding transition: height 0.2s ease to the div, but it didn't work as expecte ...

The height auto transition in CSS3 begins by shrinking to a height of 0 before expanding to

My CSS code looks like this: .foo { height:100px; overflow:hidden; -webkit-transition: height 200ms; -moz-transition: height 200ms; -o-transition: height 200ms; transition: height 200ms; } .foo.open { height:auto; } When the ...

What steps can I take to bring this idea to life in my gallery?

Currently, I am facing a roadblock while transitioning my design concept into actual code. My main concern lies with creating this art piece. Although the gallery is up and running with all the images in place, I'm encountering difficulties with the s ...

Ways to stop button from wrapping inside a div

While working on a search page, I encountered an issue where the submit button overlaps with the text input when zooming in due to lack of space. Is there a solution to prevent this overlapping and keep the layout intact? HTML <input type="text> &l ...

Tablet displaying incomplete background image

I am facing an issue with my background image only showing inside the content blocks, as you can see in the screenshot. I have a small fadeIn animation for the content, but nothing else special. Here is the CSS code I am using: .template_home { backgro ...

HTML & CSS: Modify background rectangle behind text to limit its size within the webpage dimensions

I'm experiencing a unique issue with the current code present in my HTML index file. <div class="titleMessage"> <div class="heading"> <p class="main">NAME HERE</p> <p class="sub">Software Engineer& ...

Challenges regarding placement and z-index are causing issues

Currently, I am attempting to make the menu overlap the content on my webpage. However, I am facing an issue where it moves the content box instead of overlapping it. I have already experimented with the position: relative concept, but unfortunately, the ...

Adjusting Bootstrap CSS Styles

After recently installing bootstrap 3.0 on my website and experimenting with it, I have a few questions. I am looking to customize certain aspects of the jumbotron (and other classes) in my personal .css file named "mycss.css". Here is the code I have add ...

What's the solution for aligning these progress bars side by side if floating them doesn't produce the desired result?

I am looking to place two progress bars next to each other, but I have tried using float: left and inline-block without success. I am open to a solution using flex, but I believe there must be a simple fix for this issue. Here is a link to the fiddle for ...