Vertical alignment of text in Bootstrap 4 can be achieved by using

Once more, I find myself in need of your assistance.

I am facing an issue with my project. Specifically, on my menu, I want the selected option to have a bottom border and the text aligned vertically. However, using vertical-align : middle with a display table is causing complications with my menu.

Here is the code snippet :

.infos-btn {
  text-transform: uppercase;
  color: #482A81;
  box-shadow: 0px 3px 10px #888;
}

.infos-btn>div:hover {
  cursor: pointer;
}

.selected-btn {
  border-bottom: 3px solid #482A81;
  color: #482A81;
  font-weight: bold;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="row text-center px-3 infos-btn">
  <div class="col-md col-sm py-3 selected-btn">Menu</div>
  <div class="col-md col-sm py-3">Menu</div>
  <div class="col-md col-sm py-3">Menu</div>
  <div class="col-md col-sm py-3">Menu longer than others</div>
  <div class="col-md col-sm py-3">Menu</div>
</div>

In order to achieve responsiveness, adding a margin : 0 auto; might work but it will impact the positioning of the border at the bottom of the menu.

Your help is greatly appreciated!

Answer №1

To ensure it consistently begins in the middle of the screen, consider using width : 50%.

Answer №2

Make the following changes in the HTML code: Add the "align-items-center" class to the parent div

<div class="row text-center px-3 align-items-center infos-btn">
            <div class="col-md col-sm py-3 selected-btn">Menu</div>
            <div class="col-md col-sm py-3">Menu</div>
            <div class="col-md col-sm py-3">Menu</div>
            <div class="col-md col-sm py-3">Menu longer than others</div>
            <div class="col-md col-sm py-3">Menu</div>
</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

Enhancing JSON Objects in AngularJS with Custom Properties and Calculations

Hello, I'm still getting the hang of angularjs and could use some guidance. I have a Rest service that provides data on saleItems when a get request is made, as shown below: saleItems = [ { "id": 236, "variant": "Oval Holder", "mrp": "6 ...

Tips for changing the visibility of a div within table rows upon clicking

Struggling to solve this jQuery issue with a table that displays numbers on each row. I want to be able to click on one of the numbers, which is a href link, and toggle only the corresponding div called "test" instead of toggling all rows at once. How can ...

jQuery Accordion not showing up on screen

On my FAQ page, I have integrated a jQuery Accordion with a repeater control nested inside to display various questions and answers. The FAQ page utilizes a master page named LaunchPage.Master. Here is the code for LaunchPage.Master: <html> <he ...

Customized content is delivered to every client in real-time through Meteor

I am currently working on creating a multiplayer snake game using three.js and meteor. So far, it allows one player to control one out of the three snakes available. However, there is an issue where players cannot see each other's movements on their s ...

Tips for creating a unique parent tag and child tag with onclick functionality on a b-form-checkbox without repeating code

As I work on a li tag with various child elements, including a b-form-checkbox, I encountered an issue. I want the checkbox to function properly when clicked anywhere inside the li tag, including on the checkbox itself. However, when I click directly on th ...

What could be causing the jQuery Mobile DOM element to return 'undefined' when using .val()?

Currently, I am experimenting with Jquery Mobile and facing an issue where my Form elements are returning 'undefined'. I suspect that the problem lies in the fact that my form may not be created when the onclick() function is triggered by the Mem ...

The issue of margin error and vertical alignment on pseudo-elements

Here's the HTML code I am working with: <article> <picture> <img src="a.png"> </picture> </article This particular HTML code is used throughout my page, where the image has a varying width. The goal is to c ...

Tips for integrating my HTML5/javascript game into my existing website

Embarking on my first game development journey, I'm feeling a bit lost in the sea of coding. Creating a browser game is unfamiliar territory for me, and I'm struggling to grasp the usual process. My game relies on the Phaser framework of HTML an ...

Issue with Font-Awesome icons failing to display properly when using the BootstrapCDN

Trying to integrate Font-Awesome icon fonts using the BootstrapCDN link with what seems like the latest version: <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> The link has been added to the <hea ...

Missing 'id' property in ngFor loop for object type

I'm currently learning Angular and I've been following a code tutorial. However, despite matching the instructor's code, it doesn't seem to be working for me. When I try to compile the following code, I receive an error message stating ...

Creating PNG images in a scripting language for web applications

Imagine giving your website user the ability to specify a radius size, let's say 5px, and in return receiving a PNG file with a circle of that radius. This question can be divided into two sections: In what language and using which technologies can ...

What is the best way to insert an image within a .NET HTML email?

Currently, I am working with an HTML Mail template that has a designated spot for an image. The image I need to include in the email is coming from a database and I am saving it into a photo directory. My task involves embedding this image in the HTML Mess ...

How does an iOS device typically manage the :hover pseudo-class?

My div is designed to expand when clicked using jQuery $('.mydiv').click, and collapse with a second click. In addition, the same div showcases more information on hover due to CSS rules utilizing :hover. This feature works perfectly on a comput ...

How can elements be displayed differently depending on the return value of a function?

Basically, I am looking to display different content based on the status of a job: Show 'Something1' when the job is not processing Show 'Something2' when the job is running and has a status of '0' Show 'Something3&apos ...

Transmit HTML message using the "textarea" tag through email

Whenever I try to send the content of my "textarea" via email, it always ends up being sent as a blank message. How can I fix this issue? Below is my PHP code: <?php $input = json_decode(file_get_contents("php://input"), true); $ToEmail = "<a href ...

Avoiding page refresh while submitting a form can be tricky, as both e.preventDefault() and using a hidden iFrame seem

I've been stuck on this issue for a while now, scouring Stack Overflow and Google for solutions, but nothing seems to be working. My main goal is to avoid page reloads after uploading a file because it resets the dynamic HTML I need to display afterwa ...

Enlargen div or unordered list according to content exceeding limits

What is the best way to ensure a div expands when it contains a lot of content? Code Example (HTML): <div class="content"> Content goes here <br /> Content goes here <br /> Content goes here <br /> Content goes her ...

What might be causing the invisibility of a particular div element?

Here is the layout in the div element: <div class=" wrap clear"> <div class="block pink float"></div> <div class="block blue float"></div> <div class="block orange float"& ...

Encountering a classnotfound exception with JSP JDBC SERVLET, but all code appears to be

index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> < ...

Center align a font-awesome icon vertically next to a paragraph of text

Is there a way to align a font-awesome icon on the left side of a text paragraph while keeping the text on the right side, even if it's longer and wraps underneath the icon? I've tried various code snippets but haven't found a solution yet. ...