Is there a way to prevent my navbar from breaking buttons on mobile devices?

I am a beginner working on my practice portfolio and I have decided to make it fully responsive using flexbox as much as possible. I am following a "mobile-first" approach, so I can address any design issues for desktop later on. One problem I am facing is that my top navigation bar splits my buttons on mobile view. For example, the "About Me" button appears in two lines with the "me" part overlapping the "about". I aim to make all buttons fit within one line or neatly split over two lines without any overlap or text cutoff.

Here is a snippet of my code:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {

}
.nav-container {
  display: flex;

}

nav {
  display: flex;
  font-family: "Lato", sans-serif;
  flex-wrap: wrap;
  position: fixed;

}

nav ul {
  display: flex;
  margin: 5px;
  padding: 10px;
  list-style-type: none;
  justify-content: space-around;
  width: 100%;
}

nav ul li {
  margin: 5px;
  padding: 5px;
}

.header-container {

}

header {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
top: 100px;
}

.headings {
  display: flex;
  flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
text-align: center;
}

.cv-container {
  display: flex;
  align-self: flex-end;
  margin-left: 30px;
  position: relative;
  top: 30px;
  right: 30px;
  color: #000;
  border: 1px solid #000;
}

.cv-container a,
.nav-container a {
  text-decoration: none;
  color: #000;
  padding: 5px;
}

.cv-container a:hover,
.nav-container a:hover {
  background-color: #f442aa;
}

strong {
  font-style: bold;
}

header h1 {
  display: flex;
  align-self: center;
  font-family: "Lato", sans-serif;
  padding: 15px;
}

header h2 {
  display: flex;
  align-self: center;
  font-family: "Playfair Display", serif;
  padding: 15px;
}

header a {
  font-family: "Lato", sans-serif;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <meta name='viewport'
      content='width=device-width, initial-scale=1.0, maximum-scale=1.0' />
  <title>My Name - Web Designer &amp; Developer</title>
  <link rel="stylesheet" href="styles.css"/>
  <link href="https://fonts.googleapis.com/css?family=Lato:300,400,400i,700|Playfair+Display:400,400i,700,700i" rel="stylesheet">
</head>
<body>
  <div class="nav-container">
    <nav>
      <ul>
        <li><a href="#">About Me</a></li>
        <li><a href="#">Portfolio</a></li>
        <li><a href="#">Links</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </div>


    <header>
      <div class="headings">
      <p><h1>Virginia Balseiro</h1></p>
      <p><h2>Web Designer &amp; Developer</h2></p>
    </div>
      <div class="cv-container">
        <a href="#"><strong>DOWNLOAD CV</strong></a>
      </div>
      <div class="social-container">
        <a></a>
        <a></a>
        <a></a>
      </div>
    </header>

I came across some "hacks" online but I would like to implement this properly and gain a better understanding of what I am doing. Thank you in advance for your assistance.

Answer №1

My recommendation is to implement the CSS property flex-wrap: wrap on your "ul" element.

By using flex wrap, you can wrap items into multiple lines within the container.

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

An icon wrapped in an <a> element using the link_to tag

I am encountering an issue with a navbar button: <%= link_to new_post_path do %> <a class="btn-navbar"><i class="fa fa-plus" aria-hidden="true"></i></a> <% end %> The button is unresponsive and does not direct me to ...

Difficulty aligning headings in HTML

I'm puzzled by a strange 1px gap on the left of my h2 heading, which sits atop an h3. The font sizes are set to 40px for h2 and 12px for h3. Can anyone help me solve this mystery? Any assistance would be greatly appreciated! Thank you body { pa ...

Can the navbar hamburger in Bootstrap be displayed at a screen size of 992px?

How can I display the bootstrap navbar Hamburger at md(992px) Screen? Here is the code snippet I am currently using: https://i.sstatic.net/OqBTQ.png Any suggestions on what steps I should take? ...

The text-decoration is here to stay

Currently, I am facing an issue with the customization of a wordpress theme related to the styling of links within posts. Although I have tried to change the color and remove underlining using CSS rules, I am unsuccessful so far: a, .entry-meta a, entry-c ...

"Triggering the scrollTop animation will trigger the scroll event to

I am facing an issue with my code that tracks the scrolling of a page. It successfully performs the necessary action when the "page" changes, but I am having trouble preventing the scroll event from being triggered when animating the scrollTop to the neare ...

jQuery - Enlarge Tree View to the level of the selected node

I am struggling to figure out how to expand the tree view up to a selected node level. If anyone has any ideas on how to accomplish this, please let me know. For instance, if we click on 'Parent d' in the 'Category list', I want to exp ...

Implementing jQuery during the navigation between Node routes

Below is a snippet of my jQuery code: $(function () { $('.mnav a').click(function () { el = $('.border'); el.addClass('blink'); el.one('webkitAnimationEnd oanimationend msAnimationEnd animatio ...

How can I resize an image to fit at the bottom of the screen, similar to a footer?

Currently, the image is not spanning the entire width of the screen I've looked into various solutions for similar issues, but they always end up aligning the image to the right or left and increasing its size. If anyone has any suggestions, I would ...

Transforming a CSS class within a function into a dynamic jQuery animation

Looking to implement a css class toggling feature in jQuery within a function (shoutout to @Laurence for the code): function rocksType_shift(direction) { $('#rocksType_DBitems_container .before').removeClass('before')[direction](). ...

Reveal the table only once a search has been completed

Currently, I am in the process of developing a small project and my aim is to have the table with the results appear only upon clicking the button or initiating a search. If you are interested, you can view it at this link: . My objective is to keep the t ...

Using JavaScript to apply styling on images with overlays

I am currently facing an issue with placing an overlay on top of a background image. Despite my efforts, I am unable to get the background color to appear on top of the image. Any helpful suggestions on how to resolve this would be greatly appreciated. M ...

"Is it possible to keep an eye on two different events and take action once they both

I have a menu with different submenus for each list item, all utilizing the same background tag. Currently, when one submenu is open and I hover over another list item, the previous submenus hide and the new one opens. What I want is for the content to cha ...

Difficulty in implementing jQuery accordion height style using either content or fill option

What I am looking for is to have only one specific div in my accordion (device properties) change its height based on the content. I have also noticed that if I use Firebug to remove the height property of the device div, it adjusts the height correctly. ...

Accordion symbol for adding or subtracting

Looking for a way to change the Toggle text in my angular 7 application accordion to images or content displaying a + sign for collapse and - for expand. I need to achieve this using CSS in my SCSS stylesheet so that I can later change the color of the sig ...

How to apply color to text in Node.js

I am in the process of creating a web-based compiler using NodeJS. My main objective is to highlight syntax in different colors. For example, consider the following C code: int var; printf("%d",var); In this code snippet, I would like the "int" and "prin ...

Step-by-step guide to creating a dynamic button that not only changes its value but also

I am trying to implement a translation button on my website that changes its value along with the text. Currently, I have some code in place where the button toggles between divs, but I am struggling to make the button value switch as well. Given my limit ...

Overlay a div on top of an image in an HTML email

To display text over an image in HTML email, I am looking for a solution since using margin or position is not working as required. Below is the code snippet I have tried: <div style="padding-right:25px;padding-left:20px"> <div style="padding-t ...

The correct terminology for divs, spans, paragraphs, images, anchor tags, table rows, table data, unordered lists, list

Just wondering, I've noticed that every time I come across a page element '<###>[content]<###>' and want to learn how to manipulate it, I usually search for something like "how to do x with div" or "how to get y from div". I know ...

The universal CSS variables of Material UI

Creating reusable CSS variables for components can greatly simplify styling. In regular CSS, you would declare them like this: :root { --box-shadow: 0 2px 5px -1px rgba(0, 0, 0, 0.3); } This variable can then be utilized as shown below: .my-class { ...

Unable to get CSS Filter to function properly in Firefox

I'm having trouble with the CSS filter on my Firefox (15.0) browser. Here is the HTML code: <div class="google"> <img src="https://www.google.com/images/srpr/logo3w.png"> </div> And here is the CSS code: .google{ -moz ...