Is there a way to position an X item on the first row and another X item on the following row using flexbox?

I want to use flexbox to arrange 10 buttons in a row on a large screen. On a medium screen, I'd like 5 buttons on the first row and 5 on the second row. For small screens, 2 buttons per row, and for very small screens, one button per row. It's important that the total number of buttons displayed is always a multiple of 10.

body,
html {
  margin: 0;
  background: whitesmoke;
}

h1 {
  text-align: center;
  font-family: cursive;
}

#content {
  margin: 2px;
}

.toolbar>div {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

#contain {
  background: #EEEEEE;
  overflow-y: auto;
}

#marginTop {
  margin-top: 15px;
}

#onglets {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
}

input:hover,
select:hover {
  border: 1px solid #B829fA;
}

input:focus {
  border: 1px solid #B829BA;
}

select:focus {
  border: 1px solid #B829ff;
}

input[type="submit"] {
  width: 150px;
  float: left;
  text-decoration: none;
  color: black;
  font-family: "Trebuchet MS";
  font-size: 14px;
  border-radius: 4px;
  transition: 0.25s;
  background: rgb(250, 250, 252);
  border: 1px solid #ccc;
  font: inherit;
  line-height: 1;
  margin: 0.5em;
  padding: 1em 2em;
  cursor: pointer;
  /*box-shadow: 0px 1px 3px #ccc;*/
}

input[type="submit"]:hover {
  background: white!important;
  color: white!important;
  box-shadow: inset 0 0 0 2em #B829fA!important;
  border: 1px solid white!important;
  text-decoration: underline;
}

input[type="submit"]:focus {
  background: white;
  color: white;
  box-shadow: inset 0 0 0 2em #B829fA;
  border: 1px solid white;
}

input[type="submit"]:focusout {
  background: white;
  color: white;
  box-shadow: inset 0 0 0 100% #B829BA;
  border: 1px solid white;
}

.inputContent {
  min-height: 19px;
}

.contents {
  visibility: hidden;
  display: none;
}

.border {
  border: 1px solid #ccc;
  padding: 1px;
  padding-left: 3px;
  padding-right: 3px;
  margin: 2px;
}

.block {
  padding: 5px;
  border: 1px solid #ccc;
  margin-bottom: 15px;
  margin-right: 15px;
  box-shadow: /*inset*/
  0px 1px 3px #ccc;
  border-radius: 4px;
  background: rgb(250, 250, 252);
  width: 100%;
  box-sizing: border-box;
}

.block:hover {
  border: 1px solid #B829FA;
}

.data,
.divValue {
  display: flex;
  justify-content: space-between;
  padding-bottom: 1px;
  padding-top: 1px;
  flex-wrap: nowrap;
  width: 100%;
}

.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
}

.subcontainer {
  display: flex;
  flex-direction: column;
  height: auto;
  width: 400px;
  justify-content: flex-start;
}

.spanCenter {
  display: flex;
  justify-content: flex-start;
  color: #B829BA;
  text-decoration: bold;
  padding-bottom: 5px;
  padding-top: 5px;
  margin-bottom: 5px;
}

.widthContain {
  width: 196px;
}
<!DOCTYPE html>
<html>

<body>
  <div id="onglets">
    <!--Menu-->
    <input id="inputGeneral" class="buttonMenu" type="submit" value="General">
    <input id="inputConditionement" class="buttonMenu" type="submit" value="Conditionement">
    <input id="inputMesure" class="buttonMenu" type="submit" value="Mesure">
    <input id="inputMat" class="buttonMenu" type="submit" value="Mat. Dangereuse">
    <input id="inputAlgorithme" class="buttonMenu" type="submit" value="Algorithme">
    <input id="inputPicking" class="buttonMenu" type="submit" value="Picking">
    <input id="inputCode" class="buttonMenu" type="submit" value="Code Barre">
    <input id="inputImage" class="buttonMenu" type="submit" value="Image">
    <input id="inputInventaire" class="buttonMenu" type="submit" value="Inventaire Tournant">
    <input id="inputChamps" class="buttonMenu" type="submit" value="Champs Libres">
  </div>
</body>

</html>

Answer №1

To optimize the display of 10 buttons on a larger screen, utilize media queries. By incorporating the following code snippet, the buttons will be formatted appropriately:

@media (min-width: 1200px){
    input[type="submit"] {
        width:122px;
        float: left;
        font-size: 12px !important;
        padding: 1em 1em;
    }
}

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

The accuracy of IE9 <section> is not quite up to par

When viewing This Page in IE9, the element section#tcs-website-content appears as 990px wide even though its CSS property is set to width: 100%. This occurs despite all parent elements also having a width of 100%, resulting in a browser width of 1024px. A ...

Issue with FullPageJS: scrollOverflow feature not functioning upon click event

I am currently working on a Fullpage.js instance that needs to be initialized with a click event and then destroyed when switching to another page, and vice versa. The scrollOverflow feature works perfectly as long as the #fullpage element is not hidden up ...

Position on the chart in the Highcharts

I have developed 2 highcharts in the code below: <div> <p id="container"> </p> <p id="cont"> </p> </div> I specified the width and height as follows: $('#cont').highcharts({ char ...

Maintaining a live Angular website

I'm currently in the process of developing a website for a family friend using Angular as a Single Page Application with three main 'pages'. After completion, my plan is to package it into an html, css, and js file. I've also secured th ...

Modify the text of a button when hovered over (JavaFX)

Can anyone help me figure out how to change the text of a button when it is hovered over? Approach: if (button.isHover()){ button.setText("new message"); } I'm open to either a css fix or a code solution! ...

SVG to create a gradient mask that appears transparent

I require assistance with working on svg's. I have a "background image" with another "image" layered over it. The "image" needs to have a hole cut out of it so that the background image can shine through. I managed to achieve this by utilizing svg: ...

Troubleshoot: Unable to Change CSS on Click Using Javascript/jQuery

Having trouble creating three different buttons that toggle between various images using the CSS display property? Check out my code on https://jsfiddle.net/agt559e8/. function USradarChange1() { //document.getElementById("usradar1").src="weather/curr ...

Seamless animation when collapsing element using angular and css exclusively

I am attempting to incorporate a collapsible feature into my application. Rather than relying on external libraries like jQuery, I want to exclusively utilize Angular. For demonstration purposes, I have created a very basic example here: http://jsfiddle.n ...

Issue with Node.js connect-flash functionality not functioning as expected

I'm struggling to get an error message to display using connect-flash, but I can't seem to make it work. I've attempted various methods, but none of them have been successful. Interestingly, I have another web app with a similar configuratio ...

Having trouble with the scrolling feature on a read-only text area within a form

My form allows users to input their data, but once submitted, the form becomes read-only. However, I'm facing an issue where the data in the text area is not scrollable even though it should be. I need assistance in figuring out why the content in th ...

Tips for positioning the footer at the bottom of the page

During the process of constructing a new website, I included a footer that is neatly positioned at the bottom of my screen. https://i.sstatic.net/HgAbY.png However, I noticed that on pages with minimal content, the footer does not remain fixed at the bott ...

CSS is being affected by an HTML form's unintended margin

Something seems off with the alignment of my search bar. It's causing the horizontal line to shift down when I add it next to the vertical lines at the bottom. I've tried adjusting the padding, margins, and even played with positive and negative ...

The element remains stationary and does not shift positions

My form is not centralizing properly, it seems to be stuck to the left side of #wrapper. I've tried adjusting margin-top but it doesn't seem to affect its horizontal position at all. I've played around with different values for margin and ev ...

Is there a way to ensure that all elements on a page display properly across all screen resolutions without being cut off?

My website consists of three main elements: pictures, Cards (containing pictures and various typography), and Buttons. These elements are arranged in a column layout. The issue I am facing is that the pictures and buttons get cut off on the screen due to ...

jQuery UI Accordion - Adjusting Panel Height to Content Size

Currently, I am utilizing jQuery UI's Accordion feature from http://jqueryui.com/demos/accordion/, and my goal is to adjust it so that it resizes based on the contents of each panel rather than just fitting the largest one. In addition, I am seeking ...

Interactive Image Effects with Hover using HTML and JavaScript

I have observed that the transform works fine, but there is a slight issue when initially hovering or touching the image. After the first touch or hover, everything works great. Any assistance on fixing this minor issue would be greatly appreciated. Thank ...

What is the best way to enclose text within a border on a button?

I am trying to create a button with a colored border around its text. Here is the code for my button: <input id="btnexit" class="exitbutton" type="button" value="Exit" name="btnExit"></input> Although I have already added CSS styles for the ...

Ensure that the footer remains at the bottom of the webpage, without being positioned as fixed

I am encountering an issue on my work2 Website where the footer is not staying at the bottom of the page when there is limited content. I have searched extensively on Google, YouTube, and CSS tricks for a solution, but have not found one that works for my ...

Issues with the collapse feature in Bootstrap 5.1.3 accordion

I'm currently utilizing an accordion style to display various sets of information on a website. While all the correct information is being displayed, I am facing an issue where the accordion items are not collapsing as expected. Below is the code snip ...

Segment the progress bar into sections

Struggling with an Angular app, and still new to HTML and CSS, I am attempting to create a unique progress bar. I aim to split each section of the progress bar into two subsections with distinct background colors shown in this image: https://i.sstatic.net/ ...