What is the best way to add stripes to a button for a colorful touch

Can the button be styled with colors similar to those shown in the image? https://i.sstatic.net/3o1Jb.png

Answer №1

To achieve this design, you will need to create multiple div elements and style them using CSS.

It is essential to set the box-sizing property to border-box when applying borders to ensure proper alignment.

document.querySelector('.rainbow-button')
  .addEventListener('click', () => console.log('Clicked!'));
.as-console-wrapper { max-height: 5rem !important; }

body {
  background: #505661;
}

.rainbow-button {
  position: relative;
  min-width: 4em;
  min-height: 4em;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  outline: none;
  font-size: 2rem; /* Increase size */
}

/* More CSS styles here */

<button type="button" class="rainbow-button">
  <div class="stripes">
    <div class="stripe"></div>
    <div class="stripe"></div>
    <div class="stripe"></div>
    <div class="stripe"></div>
  </div>
  <div class="value">4</div>
</button>

An alternative approach is to use the `flex:1` property for stripes and remove the `width:25%` setting:

.rainbow-button .stripes {
  display: flex;
  flex-direction: column;
}

.rainbow-button .stripe {
  flex: 1;
  border: 0.15em solid grey;
}

This eliminates the need for percentage values in styling.

document.querySelector('.rainbow-button')
  .addEventListener('click', () => console.log('Clicked!'));
.as-console-wrapper { max-height: 5rem !important; }

body {
  background: #505661;
}

/* More CSS styles here */
<button type="button" class="rainbow-button">
  <div class="stripes">
    <div class="stripe"></div>
    <div class="stripe"></div>
    <div class="stripe"></div>
    <div class="stripe"></div>
  </div>
  <div class="value">4</div>
</button>

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

Creating a seamless transition from 2 CSS grid columns to 1 on mobile devices without the need for a media query

Is utilizing a media query the sole solution for keeping itemX and itemY in the same cell on each device? Are there any native CSS grid methods that could achieve the same result? Feel free to check out the demonstration on the following fiddle: https://j ...

Is there a way to dynamically enhance a JSON child array with additional value?

I am currently working on implementing a filter system similar to the one shown in the image. This project is being developed using Angular JS framework and JQuery. The main requirement is to have checkbox filters for Application Name, Status, and so on. ...

What could be the reason behind the varying outcomes browsers provide for the JavaScript expression new Date(-105998400000)?

When I use ASP.NET MVC 3 with the default Json serializer, I notice that dates from my JsonResults come back in the format /Date(-105998400000)/. To handle this, I extract the number and create a new Date object with this value. However, I am experiencing ...

JQuery Scroll Spy Implementation

I have structured the page with a header at the top and 3 columns below. The left column contains a menu, the middle column is a text container, and the right column is another section. As the page scrolls up, the menu becomes fixed in position which func ...

Error message: The import from './components/headerComponent/header' failed because it does not have a default export. Make sure to export it as default to be able to import it

I've been trying to bring a header from one file into another, but it's not cooperating. import React from 'react'; import { Typography, Card, CardContent } from '@material-ui/core'; import Header from './components/head ...

Creating a Custom Alert Box in Javascript with Image Alignment

I have just finished creating a custom alert box using Javascript, complete with text and images. However, I am facing an issue with alignment. The output is not as expected. I am trying to display the correct mark and text on the same line. Can someone ...

What are some ways to create a versatile wrapper?

I'm currently grappling with an issue involving my Formik fields. I need to utilize FastFields in certain scenarios and Fields in others within my FormikControl, a class designed for constructing formik inputs. The challenge lies in being able to swit ...

Ensuring the input field and button are positioned in a horizontal line

Currently, I am developing a to-do list application using React and Chakra UI. I am trying to align the input field and the button on the same line for a more organized layout. This is the current layout: image I aim to achieve a design similar to this: ...

Insert the object into a designated location within a multi-dimensional array

I've integrated a tree view into my Angular project and I'm looking to add an object to a specific position within an array. array const TREE_DATA: TreeNode[] = [{"name":"Demo","id":"demo_1","children ...

Looking for assistance with CSS coding for an XML table

Struggling with styling an XML file into a table using CSS. Despite multiple attempts, I just can't seem to achieve the desired look. Provided below is my XML code. Seeking assistance from anyone who can offer a solution to this perplexing issue. &l ...

What could be causing the 'Invalid element type' error to occur in my React Native application?

`import { StyleSheet, Text } from 'react-native'; import { Provider } from 'react-redux'; import { store } from './store'; import { HomeScreen } from './screens/HomeScreen'; import { SafeAreaProvider } from 'rea ...

Display the entire dataset retrieved from MongoDB and utilize the doT.js templating engine for rendering

I am facing an issue with extracting data from mongodb and passing it to the view. Despite all my efforts, only one record out of 10000 is showing up instead of all of them. I believe I am very close to resolving this problem but unfortunately, I am stuck. ...

Trigger JavaScript keypress event on keypress

In my code, I have a function called addMoney() that is triggered by pressing Enter in an input field: $('body').on('keypress', 'input[type=text]', function(e){ if(e.keyCode==13){ var val = $('input[type=te ...

User interface for creating a platform resembling Product Hunt or Reddit

I am currently developing a web application similar to Product Hunt. The back-end API is up and running smoothly, and I have successfully implemented AngularJS for the front-end. However, I lack experience in designing the look and feel of the site. Shou ...

Tips for aligning numbers in a monospaced ordered list

Is there a way to align the numbers in a numbered list within a table using monospace font so that they are at the same level as bullets on a bullet list? Simplest example: ol { font-family: monospace; } ul, ol { margin-top: 10px; margin-bottom: ...

Issues with navigation menus in Bootstrap/Wordpress

My mobile drop-down menu is giving me some strange issues. When you toggle the button, the menu briefly appears just below the button before moving to its correct position. Sometimes it doesn't work at all, and clicking has no effect. You can witnes ...

Troubleshooting Spring's difficulty in locating resource files (css, jsp...)

Currently, I am integrating a jsp file as a model from a Controller and aiming to incorporate CSS styles and JS libraries into the project structure. Project Structure Webcontent assets WEB-INF jsp For the configuration in web.xml: <web-app versio ...

Sliding and repositioning elements using jQuery

My goal is to build a simple slideshow for learning purposes. I want the list items to slide automatically to the left in a continuous loop. I've written some code that makes the slides move, but I'm struggling to set the correct position for ea ...

Website layout looking unique due to pixel width adaptation from standard width

I'm currently working on a website with full width design. On my computer, the website displays as full width, but on other computers it shows extra space on the sides. How can I ensure that this website is truly full width? .wrapper_boxed { wid ...

Is it possible to map through material-ui components within an array in React.js?

I've been attempting to implement material-ui and iterate over it within an array (to create ratings for items, similar to e-commerce websites). Unfortunately, the code is not functioning as expected. When I run it on my localhost server, no stars are ...