Focus the text on a specific letter

I am attempting to align a phrase in the center of my navigation bar, which has been built using Bootstrap. Currently, the navbar appears as follows:
Centered Navbar title
My goal is to center the "|" symbol with the text adjacent to it on both sides, rather than simply centering the entire sentence. Essentially, I want the "|" to be precisely centered with text on either side, instead of having the middle letter in the center. I hope this explanation makes sense - I want the "|" to be at the midpoint.
I have attempted to center the "|" and utilize floating for the left text to move right and the right text to move left, but this resulted in the text shifting completely to the right rather than stopping before the "|".
Please use the snippet provided to view the code, ensuring you select "Full Page" for proper functionality...

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>

<head>
  <link href="https://www.fontify.me/wf/da96db5dc1f0db255a8e71edaa0ace2d" rel="stylesheet" type="text/css">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>
    <?php echo $album_nm; ?>
  </title>

  <!-- Bootstrap Core CSS -->
  <link href="https://blackrockdigital.github.io/startbootstrap-scrolling-nav/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom CSS -->
  <link href="https://blackrockdigital.github.io/startbootstrap-scrolling-nav/css/scrolling-nav.css" rel="stylesheet">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
  <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
  <!-- -------------------------------------------------------------NAV BAR------------------------------------------------------ -->
  <nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="background-color: #1a1a1a;">
    <div class="container" style="text-align: center;">
      <div class="container" class="navbar-header page-scroll">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
        <div style="font-family: font71888;" class="navbar-brand page-scroll" href="#page-top">
          <div style="display:inline-block; text-align: right;">
            CHLOE
          </div>
          <div style="display:inline-block; float: none; margin: 0 auto;">
            |
          </div>
          <div style="display:inline-block; text-align: left;">
            <?php echo $album_nm; ?>
          </div>
        </div>
        <!-- <a style="font-family: font71888;" class="navbar-brand page-scroll navbar-middle" href="#page-top"><br>CHLOE | <?php echo $album_nm; ?></a> -->
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse navbar-ex1-collapse">
        <ul class="nav navbar-nav" style="align: center; float: center; text-align: center;">
          <!-- Hidden li included to remove active class from about link when scrolled up past about section -->
          <li class="hidden">
            <a class="page-scroll" href="#page-top"></a>
          </li>
          <li>
            <a class="page-scroll" href="#buy">Buy</a>
          </li>
          <li>
            <a class="page-scroll" href="#story">My Story</a>
          </li>
          <li>
            <a class="page-scroll" href="#about">About Me</a>
          </li>
          <li>
            <a class="page-scroll" href="#warchild">War Child</a>
          </li>
          <li>
            <a class="page-scroll" href="#listen">Listen</a>
          </li>
          <li>
            <a class="page-scroll" href="#thanks">Thanks</a>
          </li>
          <li>
            <a class="page-scroll" href="#contact">Contact</a>
          </li>
        </ul>
      </div>
      <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
  </nav>
</body>

</html>

Edit:

Special thanks to Andrei Gheorghiu for providing a solution that worked smoothly and looked great! I have selected his answer as correct, as it currently has the most upvotes...

Answer №1

My approach would be:

.navbar-brand {
  display: flex;
}
.navbar-brand > div{
  flex: 1 1 0;
  padding: 0 4px;
}
.navbar-brand > div:first-child,
.navbar-brand > div:last-child{
  flex-basis: 50%;
}
.navbar-brand > div:first-child {
  text-align: right;
}
<div class="navbar-brand page-scroll" href="#page-top">
  <div>CHLOE</div>
  <div>|</div>
  <div>This is a long album name</div>
</div>

P.S.: Remember to autoprefix your CSS before deploying.
Also, refrain from using inline style! It's important for organizing your declarations within @media queries.

Answer №2

Here.

Note: To exclude the mobile menu button from text centering calculations, simply remove the overflow: hidden property from the wrapping div.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>

<head>
  <link href="https://www.fontify.me/wf/da96db5dc1f0db255a8e71edaa0ace2d" rel="stylesheet" type="text/css">
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>
    <?php echo $album_nm; ?>
  </title>

  <!-- Bootstrap Core CSS -->
  <link href="https://blackrockdigital.github.io/startbootstrap-scrolling-nav/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom CSS -->
  <link href="https://blackrockdigital.github.io/startbootstrap-scrolling-nav/css/scrolling-nav.css" rel="stylesheet">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
  <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body id="page-top" data-spy="scroll" data-target=".navbar-fixed-top">
  <!-- -------------------------------------------------------------NAV BAR------------------------------------------------------ -->
  <nav class="navbar navbar-default navbar-fixed-top" role="navigation" style="background-color: #1a1a1a;">
    <div class="container" style="text-align: center;">
      <div class="container" class="navbar-header page-scroll">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
        <div style="font-family: font71888; float: none;" class="navbar-brand page-scroll" href="#page-top">
          <div style="display:block; text-align: right; width: 50%">
            CHLOE |
          </div>
          <div style="display:block; text-align: left; width: 50%" >
            <?php echo $album_nm; ?>
          </div>
        </div>
        <!-- <a style="font-family: font71888;" class="navbar-brand page-scroll navbar-middle" href="#page-top"><br>CHLOE | <?php echo $album_nm; ?></a> -->
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse navbar-ex1-collapse">
        <ul class="nav navbar-nav" style="align: center; float: center; text-align: center;">
          <!-- Hidden li included to remove active class from about link when scrolled up past about section -->
          <li class="hidden">
            <a class="page-scroll" href="#page-top"></a>
          </li>
          <li>
            <a class="page-scroll" href="#buy">Buy</a>
          </li>
          <li>
            <a class="page-scroll" href="#story">My Story</a>
          </li>
          <li>
            <a class="page-scroll" href="#about">About Me</a>
          </li>
          <li>
            <a class="page-scroll" href="#warchild">War Child</a>
          </li>
          <li>
            <a class="page-scroll" href="#listen">Listen</a>
          </li>
          <li>
            <a class="page-scroll" href="#thanks">Thanks</a>
          </li>
          <li>
            <a class="page-scroll" href="#contact">Contact</a>
          </li>
        </ul>
      </div>
      <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
  </nav>
</body>

</html>

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

Styles and CSS have been successfully loaded, however, the content is not appearing

After attempting to import a web HTML CSS template into my self-made MVC, I encountered an issue. While the template works properly on its own, it fails to connect to the CSS files and display proper styles when accessed through my controller. Instead, onl ...

The background image vanishes in Chrome when scrolling downwards

After setting an image with a resolution of 1980 x 1200 as the background for my web page, I encountered an issue. When scrolling down, around the height of 1200px, the image disappears and is replaced by a white background. This problem only occurs in Chr ...

:after pseudo class not functioning properly when included in stylesheet and imported into React

I am currently utilizing style-loader and css-loader for importing stylesheets in a react project: require('../css/gallery/style.css'); Everything in the stylesheet is working smoothly, except for one specific rule: .grid::after { content: ...

Ways to show or conceal content using only CSS

Looking for help with switching content using pure CSS. I'm not very skilled with CSS and would prefer to avoid using JavaScript if possible. Any assistance would be greatly appreciated. Below is a snippet of the code: If A is clicked, toggle-on-con ...

tips on customizing buttons within form groups

I have set up two separate form-groups: My goal is to click on each button within each group and toggle its style from grey to green, and vice versa. However, when I click on a button, all buttons within the group turn grey except for the one that was cli ...

Show only the portion of the image where the cursor is currently hovering

Information in advance: You can check out the current code or view the live demo (hover image functionality not included) at . The concept: I would like to have it so that when I hover my cursor (displayed as a black circle) over the image, only the s ...

stop the menu component from triggering a re-render

I am facing an issue where the menu opens and closes briefly when I refresh the page. I want to find a way to prevent this re-rendering process. Every time I refresh, my console.log shows: false 'open' navigation.jsx:23 item navigation.jsx: ...

The scroll functionality does not seem to be functioning as intended on mobile devices when

Hey there, I'm currently working on making my navbar sticky and applying it when the page is scrolled. The code I have works flawlessly on desktop, but unfortunately, it doesn't seem to work on the mobile version. Any suggestions? window.addE ...

Tips for evenly spacing items in a navigation bar

I'm having trouble centering the logo on the navbar as it always leans more towards the left. Is there a way to resolve this problem using Bootstrap classes? The navbar consists of a dropdown toggle button on the left, the logo in the center, and two ...

"Wordpress Pluto theme: A stellar choice for your

I'm trying to add a link in my main template.index file that will redirect to one of my pages when clicked on the JavaScript button at the top in Pluto theme. Currently, the text is there but clicking on it opens something I don't want. Here&apo ...

Angular UI Bootstrap Typeahead - Apply a class when the element is added to the document body

In my current project, I am utilizing angular bootstrap typeahead with multiple instances. Some of these instances are directly appended to the body using the "typeahead-append-to-body" option. Now, I have a specific instance where I need to customize the ...

Issue with Bootstrap's vertical alignment property not functioning as expected

This question arises from the Bootstrap documentation and highlights an issue with vertical alignment. While everything else seems to be working fine, the vertical alignment is not displaying correctly. Take a look at the comparison below: Expected Align ...

My webpage is displaying the background image, but it is appearing behind all the other elements on the page

I've run into an issue where my background is showing up, but it's appearing behind my divs instead of alongside the content as I want. I can't seem to get it to work properly. I believe this part of my CSS code is causing the problem: body ...

Error with displaying uib-datepicker within a table row

I need assistance with integrating a uib-datepicker into a table: <div class="table-responsive"> <table class="table table-striped" > <thead> <tr> <th class="col-md-2"><span>Date ...

Instructions for adding an onfocus event listener to an input field in order to dynamically change the formatting of associated labels

I'm looking to change the style of my input labels to a more fancy look by implementing the .fancyclass style when using the onfocus event on the input field. I am curious to know how this can be achieved through event listeners in Javascript? ...

Generating grid-style buttons dynamically using jQuery Mobile

I am in need of assistance to create a dynamic grid using jQuery Mobile. The grid should consist of buttons with either 'onclick' or 'href' functionality. The number of buttons should be generated dynamically at runtime. Specifically, I ...

Alter the page's color scheme completely

I am currently facing an issue with my button that creates a popup and darkens the background of my page. While this functionality works, it does not affect any bootstrap containers. I am using bootstrap 4 and react for this project. https://i.sstatic.net/ ...

Tips for preventing cursor tooltips from going off the screen

I've been working on creating a popup box that displays text positioned away from an element when the cursor hovers over it. Check out a simplified demo here. Currently, the popup box collapses when it gets close to the bounding box. I'd like it ...

Animation scaling on the iPhone seems to abruptly jump away once it finishes

Encountering an issue with animations that is causing unexpected behavior on physical iPhone devices but not in the simulators. The problem arises when the background zooms in and then the div suddenly jumps to the left after the animation completes, as sh ...

Creating a scrollable card layout specifically for small screens in HTML

I am looking to implement a horizontal scroll (for small screens only) within my card layout so that all cards are displayed in a single row. Here is an example: For small screens: https://i.sstatic.net/5eWyV.png So far, I have added horizontal scrolling ...