1

enter image description hereI have made a text as a button and want to create a menu with that. What I am trying to do is to change the text. When I click the button, it works as a circular menu and shows me options.

For example, it was L(litter) = 1, when I click the button it shows me other parameters such as mL, gallon, ounce. If I click mL, the text will change from L = 1000 to mL = 1000.

Could you help with me actual coding if possible? This is what I currently have. When I click, I can type a value and it changes the value. I don't need to type the value but it should display one of the values I already stored in depending on what I click on the menu.

var para = document.querySelector('button');
para.addEventListener('click', updateValue);
function updateValue() {
  var value = prompt('Enter a new value');
  para.textContent = value;
}
2
  • Basically: you want a <select> component (but without using the <select> tag so you can style it as you please), yes? Commented Jul 25, 2018 at 2:40
  • Is there something wrong with <select>? Commented Jul 25, 2018 at 3:54

1 Answer 1

1

If I get you clear so this example is what you need

body {
  font-family: Alegreya Sans;
  background: #feeded;
}

.menu {
  position: relative;
  background: #cd3e3d;
  width: 3em;
  height: 3em;
  border-radius: 5em;
  margin: auto;
  margin-top: 5em;
  margin-bottom: 5em;
  cursor: pointer;
  border: 1em solid #fdaead;
}

.menu:after {
  content: "";
  position: absolute;
  top: 1em;
  left: 1em;
  width: 1em;
  height: 0.2em;
  border-top: 0.6em double #fff;
  border-bottom: 0.2em solid #fff;
}

.menu ul {
  list-style: none;
  padding: 0;
}

.menu li {
  width: 5em;
  height: 1.4em;
  padding: 0.2em;
  margin-top: 0.2em;
  text-align: center;
  border-top-right-radius: 0.5em;
  border-bottom-right-radius: 0.5em;
  transition: all 1s;
  background: #fdaead;
  opacity: 0;
  z-index: -1;
}

.menu:hover li {
  opacity: 1;
}


/**
 * Add a pseudo element to cover the space
 * between the links. This is so the menu
 * does not lose :hover focus and disappear
 */

.menu:hover ul::before {
  position: absolute;
  content: "";
  width: 0;
  height: 0;
  display: block;
  left: 50%;
  top: -5.0em;
  /**
   * The pseudo-element is a semi-circle
   * created with CSS. Top, bottom, and right
   * borders are 6.5em (left being 0), and then
   * a border-radius is added to the two corners
   * on the right.
   */
  border-width: 6.5em;
  border-radius: 0 7.5em 7.5em 0;
  border-left: 0;
  border-style: solid;
  /**
   * Have to have a border color for the border
   * to be hoverable. I'm using a very light one
   * so that it looks invisible.
   */
  border-color: rgba(0, 0, 0, 0.01);
  /**
   * Put the psuedo-element behind the links
   * (So they can be clicked on)
   */
  z-index: -1;
  /**
   * Make the cursor default so it looks like
   * nothing is there
   */
  cursor: default;
}

.menu a {
  color: white;
  text-decoration: none;
  /**
   * This is to vertically center the text on the
   * little tab-like things that the text is on.
   */
  line-height: 1.5em;
}

.menu a {
  color: white;
  text-decoration: none;
}

.menu ul {
  transform: rotate(180deg) translateY(-2em);
  transition: 1s all;
}

.menu:hover ul {
  transform: rotate(0deg) translateY(-1em);
}

.menu li:hover {
  background: #cd3e3d;
  z-index: 10;
}

.menu li:nth-of-type(1) {
  transform: rotate(-90deg);
  position: absolute;
  left: -1.2em;
  top: -4.2em;
}

.menu li:nth-of-type(2) {
  transform: rotate(-45deg);
  position: absolute;
  left: 2em;
  top: -3em;
}

.menu li:nth-of-type(3) {
  position: absolute;
  left: 3.4em;
  top: 0.3em;
}

.menu li:nth-of-type(4) {
  transform: rotate(45deg);
  position: absolute;
  left: 2em;
  top: 3.7em;
}

.menu li:nth-of-type(5) {
  transform: rotate(90deg);
  position: absolute;
  left: -1.2em;
  top: 5em;
}

.hint {
  text-align: center;
}
<link href='https://fonts.googleapis.com/css?family=Alegreya+Sans:400,800' rel='stylesheet' type='text/css'>
<nav class="menu">
  <ul>
    <li><a href="#products">Products</a></li>
    <li><a href="#services">Services</a></li>
    <li><a href="#careers">Careers</a></li>
    <li><a href="#about">About</a></li>
    <li><a href="#contact">Contact</a></li>
  </ul>
</nav>

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much!! I will try testing. Can I ask if I get another question after testing it? Have a great night :)
How can I change the position of the menu? I mean how can I make the text as a menu? It looks like a text but if I click it it works as the menu you gave. I just uploaded a picture to help your understanding.
Oh I am terribly sorry for making you to misunderstand... If you see the uploaded image, you will see that d=-0.32 is in green and I made it as a button. I wonder how I can make that d=-0.32 work as a menu u made. So, if I click that d=-0.32, it expands as a circular menu (as u did before) and if I click one of them (instead of products, services, and others) will change the text from d=-0.32 to a = 1.23 for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.