Placing circular buttons below the navigation bar

I'm currently working on implementing a navigation bar on my master page. Here is the code snippet for the navigation bar:

    <nav class="navbar" style="background-color: #264653; position:absolute; top:0px; left:50%; transform:translateX(-50%); width:90%; height:14% ">
  <div class="container-fluid">
    <span class="navbar-brand" style="display:flex;">
      <img src="~/Images/Logo_Circle.png" alt="RCA" width="80" height="80" class="d-inline-block align-middle mr-2" runat="server" />
       <span style="font-size:25px;color:white;"><span style="color:#e9c46a">My City Name</span><br />My Company Name</span>
    </span>
  </div>

</nav>

I am now looking to add rounded buttons right below the navigation bar, without any space in between. This is how the navigation bar looks like currently:

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

The goal is to have the rounded buttons displayed horizontally beneath the navbar. Below is the attempted code:

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

Here is the code snippet for the buttons:

<div data-role="navbar">
<ul>
    <li> <a href="#" class="ui-btn-active nav-border" id=viewtherecent> Recent </a> </li>
    <li> <a href="#" class="nav-border" id=viewthefrequency> Frequent </a> </li>
</ul>
</div>

Despite my efforts, the buttons are displaying vertically instead of horizontally underneath the navbar.

Any assistance with this issue would be highly appreciated.

Answer №1

If you're looking to style buttons in a flexible way, flexbox can help you align them either vertically or horizontally based on your preference.

Take a look at the code snippet below where I've created a navbar with the buttons laid out as per your request:

*{
margin:0;
}
nav{
  background:blue;
 }
 
 ul{
 display:flex;
 }
 
 .buttons{
 display:flex;
 width:100%;
 }
 
 button{
 width:200px;
 border-radius:20px;
 }
 
 button:nth-of-type(1){
background:lightblue;
color:white;
}

button:hover{
background:yellow;
}
<nav>
  <ul>
    <li>Home</li>
    <li>Page1</li>
  </ul>
</nav>

<div class="buttons">
  <button>Now</button>
  <button>Recent</button>
</div>

Answer №2

When adding display: flex to an element, it is recommended to use .d-flex or one of the responsive variants like .d-sm-flex.

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="63010c0c17101711021323564d524d50">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<nav class="navbar" >
  <div class="container-fluid">
    <span class="navbar-brand" style="display:flex;">
      <img src="~/Images/Logo_Circle.png" alt="RCA" width="80" height="80" class="d-inline-block align-middle mr-2" runat="server" />
       <span style="font-size:25px;color:white;"><span style="color:#e9c46a">My City Name</span><br />My Company Name</span>
    </span>
  </div>
</nav>

<div>
  <ul class="d-flex">
    <li><a href="#" class="ui-btn-active nav-border" id=viewtherecent>Recent </a> </li>
    <li><a href="#" class="nav-border" id=viewthefrequency>Frequent</a></li>
  </ul>
</div>

Answer №3

By default, <ul> elements are displayed as blocks, while <li> elements are displayed as "list-item", which essentially translates to block in this scenario. When styled with display: block, elements will create line breaks both before and after them when they are in the normal flow.

To have the <li> links appear next to each other, you need to apply the following style to the <ul> element:

ul {
  display: flex;
  flex-direction: row;
}

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

Neatly incorporating a checkbox into a miniaturized image

I need help with the code snippet below, where I want each thumbnail image to have a checkbox overlay. I want the images to take up all the space in the table cell without any white space above. It is essential that the "left" and "right" divs are aligned ...

Firefox 3.5: The Notorious Code Copycat

Encountering an issue in Firefox 3.5.2 where after clicking a link on the page and then returning using the back button or another link, extra HTML code appears. Unsure if it's added by Firefox or related to PHP code. Unfortunately, unable to share t ...

Position the personalized radio button to be in line with the first choice text

I frequently update this section with a new Jsfidle link to demonstrate the issue when the max-width is set to 300px. For responsive design, adding the "span" tag before radio buttons helps align input content with custom checkbox backgrounds. To see the ...

Position the dropdown items of the navbar side by side

I am currently struggling to align my Bootstrap 4 dropdown items side by side as shown below: https://i.sstatic.net/i3pP0.png The desired layout involves having Item 1 and Item 2 as dropdown options when hovering over the first Test item. I attempted to ...

Different time parameter for setting a timeout in Javascript

I am struggling to create a slideshow with varying time intervals for each image. My knowledge of Javascript is limited, and I have been working on resolving this issue for quite some time. /* function ShowEffect(element){ new Effect.Appear(element, ...

Creating a smooth sliding textarea in HTML

I am working on creating an HTML table with numerous text input areas (textarea) that expand downwards when clicked. Currently, the textarea element expands properly but disrupts the layout of the table. My goal is to achieve a design like this Instead o ...

How to style multiple tags using CSS

Is there a way to style specific tags in CSS? <style type="text/css"> [attribute*="test"] { background-color: red; } </style> However, this method does not seem to work for the following tags: <test-1> </test-1> <t ...

Drawing images on a Canvas using specified coordinates: A step-by-step guide

https://i.stack.imgur.com/YkibI.jpg I've been trying to position images on specific coordinates, but I'm having trouble getting the shapes and angles right. Currently, only the top left corner is matching correctly. var _width, _height; var im ...

Having trouble setting margin-bottom to 0 in react and antd - why won't it reset?

While practicing with React, I added <link rel="stylesheet" href="%PUBLIC_URL%/css/reset.css" /> to the head of index.html in order to reset the styles. However, I noticed that <h1> still had a margin-bottom:0.5em that I c ...

In the Bootstrap Grid system, all posts are aligned to the left side

I have created a gallery with Bootstrap in React.js. The posts are currently displayed using the bootstrap grid system, however, all posts appear on the left side and I am struggling to center them. Any ideas on how to achieve this? https://i.sstatic.net/ ...

Turkish text is not appearing correctly on the UIWebview when embedded in HTML

One of the challenges I encountered in my iOS project involved programming a UIWebView to load content in both English and Turkish from a web service. To accomplish this, I formatted the HTML string with the necessary headers and saved it locally before pr ...

There appears to be an issue with the onmousemove function

I am currently troubleshooting an issue with a script that I wrote for my button. Interestingly, the code works flawlessly when I test it on CodePen, but I encountered an error when I attempted to run it in VSCode. Even after trying to recreate the script ...

Navigate through the components of an array within HTML

I am a beginner in HTML and I need to customize a specific piece of code to suit my requirements. Here is the code snippet written in pseudo code: <app-myapp *ngIf="true" [exclude] = "[this.myUser.id]" ...

Laravel Conflicting Scripts, Bootstrap clashing issues

Currently working on a Laravel project, I'm trying to integrate both Bootstrap and MDBootstrap. However, I keep encountering the error TypeError: $(...).DataTable is not a function. After some online research, it seems like this issue is usually cause ...

javascript display hide choose among

I am attempting to display another set of options when the user selects a specific item. For example, if the user selects "Products," then a new selection box should appear with different product types. See my code below: <html> <head> <m ...

Acquire the Information from a Textarea That Has Been Edited by the User

My challenge lies in taking user-entered text from a content editable textarea and sending it via POST request, but the fields edited by the user are returning with an empty textContent. The code snippet below shows that each .entryRow (obj) contains multi ...

What is the maximum character limit for the JQuery validation plugin?

Currently, I am utilizing the JQuery validation plugin in my project. My goal is to set a maxlength for one of the fields. Here's an example of how it can be done by defining rules externally: rules: { Message: { required: false, maxLe ...

The alarm feature is malfunctioning

I have been struggling with a simple alarm application that I created using jQuery and Javascript. The issue lies in the alarm functionality not working as expected. Below is the relevant code snippet: var today = new Date(); var h = today.getHours(); var ...

What are some ways to customize the appearance of Stripe credit card form fields?

I've successfully implemented stripe using this HTML code and Bootstrap 4. <div class="form-control" id="card-element"></div> As a result, I get the displayed output: https://i.sstatic.net/Aw653.png However, I am loo ...

What are your preferred HTMLPurifier configurations for sanitizing CSS styles?

I'm currently in the process of developing an application that allows users to input their own custom CSS for their profiles, similar to platforms like MySpace, Friendster, and Blogger. However, I'm struggling to find an effective method to prot ...