Interested in an issue related to Bootstrap 4 using Flexbox?

1- Seeking advice on an issue with the Header Section not following centering classes (d-flex justify-content center) in Bootstrap 4. Unable to center the text as desired.

2- Font Awesome displays oddly, looking to create a circle around it similar to a logo but found SVG while inspecting.

@import url('https://fonts.googleapis.com/css?family=Lato|Montserrat|Roboto&display=swap');
body{
font-family: 'Lato', sans-serif;
}
input[type="text"]{
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857;
color: #c0c0c0;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}

header .container{
padding: 35px 20px 0;
max-width: 950px;
}


nav a{
text-transform: uppercase;
}


i{
background-color: white;
border-radius: 50%;
border: 1x solid grey;
padding:10px;
color: red;

}

.bg-dark{
background-color: #343a4000!important;
}

.navbar-brand{
text-transform: capitalize;
}

.navbar-dark .navbar-brand{
font-size: 1.5rem;
}

.navbar-dark .navbar-nav .nav-link {
color: rgb(255, 255, 255);
font-size: 1rem;
}

header{
background: url('https://images.unsplash.com/uploads/1412198485051133af17f/5049dacb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80') no-repeat center center/cover;
min-height: 724px;
color: #fff;
}


.showcase-text h1{
font-size: 3rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <!-- Bootstrap 4  -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

  <!-- Animate CSS  -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.css">
  <!-- FontAwesome  -->
  <script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
  <!-- Wow.js -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/wow/1.1.2/wow.js">
  <!-- Hover.css Lib -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/hover.css/2.3.1/css/hover-min.css">
  <link rel="stylesheet" href="css/app.css">
  <title>Cairo Eat | Best Restaurants in Egypt at your Hand</title>
</head>
<body>
<header>
  <nav class="navbar navbar-expand-md navbar-dark bg-dark">
    <a class="navbar-brand" href="#"><span><i class="fas fa-utensils food-icon   mr-1"></i> </span>  CairoEat</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
  
    <div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
      <ul class="navbar-nav  ">
        <li class="nav-item ">
          <a class="nav-link" href="#">Sign Up <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Log in</a>
        </li>
      
        <li class="nav-item">
        </li>
      </ul>
  
    </div>
  </nav>
  
  <div class="container text-center d-flex flex-column justify-content-center">

   <h1>Hungry? Find the food you're looking for.</h1>
    <p>Your city's best eats, ready to be ordered online.</p>
    <input type="text" placeholder=" City or Address">
    <!-- <input type="submit" value="Search" class="btn btn-danger p-2 pl-3 pr-3"> -->
    <button type="submit" class=" btn btn-danger p-2 pl-3 pr-3">Search</button>
 

  </div>


</header>


</body>
</html>

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

Answer №1

  • To address your initial inquiry, please see the following response:

Upon reviewing your code, I noticed a typo on line 49 where you define the div classes.

<div class="container tex-center d-flex flex-column justify-content-center">

The class tex-center is incorrect and should be corrected to text-center. Therefore, the correct line should appear as follows:

<div class="container text-center d-flex flex-column justify-content-center">
  • Regarding your second query, the following steps can be taken:

Start by adding a class to your span element like this:

<span class="icon"><i class="fas fa-utensils food-icon"></i> </span>

Then, create a corresponding style for it:

span.icon {
  color: #343a40;
  background-color: white;
  border: 1px solid white;
  border-radius: 50%;
  padding: 5px;
  margin: 0 5px;
}

Keep in mind that the name class="icon" is simply for illustration purposes. You may customize it as needed, ensuring to update the style class name accordingly.


UPDATE

To resolve the initial issue, there are multiple approaches you can take. Follow the guidelines below:

  • Add d-flex to the header tag

nav.navbar {
  top: 0;
  width: 100%;
}
<header class="d-flex flex-column justify-content-center position-relative">
  <nav class="navbar navbar-expand-md navbar-dark bg-dark position-absolute">
  ...
  </nav>
  ...
</header>

NOTE: Use ... as placeholders for your actual content within the respective div containers. Replace them with your specific items accordingly.

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

Dynamic elements create an interactive horizontal scrolling experience

I have square elements that will be displayed in a row on the screen extension. These elements are generated dynamically, starting with 2 and going up to 50. Depending on the screen size and number of elements, there may be overflow. In such cases, I want ...

Providing data in response to a completed form submission

As a beginner, I'm attempting to accomplish the following task: a user selects options from three dropdown menus within a form, and the chosen values are then sent to another file for processing. action="process.php" method="post" In the processing ...

Prevent ng-repeat from rendering the contents of my div

Currently, I am in the process of modifying a website for which I need AngularJS. I am trying to use the ng-repeat command to display some documentation on the site. However, whenever I add the ng-repeat within a div, it seems to "destroy" the layout and I ...

Steps for making a CSS hover box with two sections

Recently, I came across a helpful tip on Stack Overflow about creating a box when hovering over text using pure CSS. It was quite interesting to implement. I decided to experiment with the cursor position and placement as well. span{ background:#F8F8 ...

Google's local host connection is currently being refused

Recently, as I was practicing HTML code to work on some forms, I encountered an issue when trying to run the code in the browser by pressing F5. Instead of seeing my code displayed, I received an error message that read: This site can’t be reached local ...

How to Conceal Axis Label in an HTML5 Canvas Line Chart

Is there a way to hide the x-axis label from a line chart without hiding the y-axis label as well? I tried using scaleFontSize: 0,, but that ended up hiding both axis labels. I only want to hide the x-axis label. var lineOptions = { ///Boo ...

Exploring the world of web scraping using R's XML package with the powerful xpathS

I need help extracting the names of shopping malls from a specific website. The URL is provided here: After examining the html code, I noticed that the mall names are stored under the "h5" tag. I tried to extract the text using the following codes, but it ...

Error encountered in Bootstrap: Cannot access property 'fn' as it is undefined

I am currently working on developing an Electron application utilizing Bootstrap. However, I have encountered an error message that states: Uncaught TypeError: Cannot read property 'fn' of undefined at setTransitionEndSupport (bootstrap.js:122) ...

Incorporate user input into Alert Dialog Boxes

Would you be able to assist me in displaying the input value from the "email" field in my alert box? The code seems to be working fine, but I'm having trouble getting the alert box to show the email form value. I decided to use Bootstrap for som ...

Utilize the return function in a separate PHP file

I wanted to create a basic login form as a way to dive into learning php. After setting up the form, I wrote a function that sends a query to a MySQL database to fetch the username and password (stored in md5 encryption) for comparison with user input. T ...

jQuery allows you to disable all other checkboxes when a specific one is checked

Whenever the "No" option is selected from a group of radio buttons, a DIV containing 6 checkboxes (with different names/IDs) should be revealed. Likewise, if the "None" option is checked, the other checkboxes should be disabled (and enabled once "None" is ...

The visual symbol is not being shown on the selection box in Mozilla Firefox

I've encountered an issue with a checkbox I created to display a + and - for expand and collapse functionality. HTML Code: <input type=checkbox class="ins" ng-model=show ng-class='{open:show}'><b>Show</b> CSS code: .ins ...

How can I ensure that I am only retrieving the first object within a "for loop" in vuejs and returning its value without getting the rest?

Why am I only able to retrieve the value of the first object in my "for loop" and not all three values as intended? var app = new Vue({ el: '#app', data: { myObj: [ {name: 'Hello', age: 10}, {name: ...

Can a video or image be displayed in HTML using an absolute path from a disk named E: while the localhost files are located in C:?

I'm attempting to construct a basic webpage utilizing HTML and PHP to display various videos, each video within its own videoplayer. The issue arises when I try to find the videos (they are stored in a folder on my secondary hard drive labeled E:&bso ...

How can we use CSS and JavaScript to transform <td> elements into a visually appealing bar graph?

Is there a way to visually represent a percentage in an HTML table cell using either CSS or JavaScript? I want to create a bar graph effect next to the percentage value, and I'm unsure which method would be easier. The web page is built using a combin ...

What is the proper way to align text based on the text above using CSS?

I have a container with a width of 50% of the viewport width, which contains some text. I want to align some other text below it to the right side. You can find an example here: https://jsfiddle.net/hadr4ytt/1/ Here is the current CSS for this: .containe ...

Issue with fadeout() on absolutely positioned element loaded via AJAX in jQuery

Currently, I am utilizing AJAXify on a website project to implement page transitions and encountering some abnormal behavior with jQuery. Below is my code: HTML (I am transitioning through backgrounds using jQuery) <div id="backgrounds"> <img s ...

What are the buttons featured in the header of this mobile-friendly bootstrap panel

Can anyone offer advice on how to make a bootstrap panel header responsive? The panel has a title with several buttons on the right side. While it looks good on a large screen, it becomes messy on smaller browser sizes. You can find my complete code here ...

Ensure that the pseudo element inherits the background color of its parent

My dilemma involves multiple pseudo elements connected to diverse parent divs, each with a unique background color. My goal is for these before and after pseudo elements to mimic the background color of their respective parent divs without the use of Jav ...

Unable to set focus on a disabled button programmatically, issue persists

$(function () { $('#save').click(function() { $('#save').attr('disabled', 'disabled'); console.log($(document.activeElement).attr('id')); }); $('#test').focus(); co ...