creating a square root symbol using css

Creating a scalable square root symbol using CSS can be achieved with the following code snippet:

.root {
  display: inline-block;
  vertical-align: middle;
}
.radix1 {
  display: inline-block;
  width: 0.2em;
  height: 1.5ex;
  vertical-align: bottom;
  border-top: 0.2ex solid;
  border-right: 0.15ex solid;
  transform: skew(25deg);
}
.radix2 {
  display: inline-block;
  vertical-align: bottom;
  border-top: 0.2ex solid;
  border-left: 0.15ex solid;
  transform: skew(-15deg);
}
.radicand {
  display: inline-block;
  padding-left: 0.5em;
  transform: skew(15deg);
}

To represent larger arguments such as fractions or matrices, line breaks can be used in conjunction with this method.

Among the questions and wish list for further development are:

  • In the current implementation, radix1 and radix2 span components only perfectly align together in the first example. How can additional margin be inserted between them based on the total height of the square root?
  • Is there a way to scale the height of radix1 dynamically according to the overall height of the square root? For instance, setting the height to a percentage value like 40% does not yield the desired outcome.
  • Exploring alternative methods: Are there better approaches to achieve this visual effect?

Answer №1

Consider trying a method utilizing only one element to form the root square. Subsequently, incorporate a pseudo-element for the smaller part to easily adjust its position in relation to the main part.

.root {
  display: inline-block;
  vertical-align: middle;
  border-top: 1px solid;
  border-left: 1px solid;
  transform: skew(-15deg);
  transform-origin: bottom left;
  margin: 0 10px;
  position: relative;
}

.root:before {
  content: "";
  position: absolute;
  bottom: 0;
  height: 40%;
  width: 5px;
  left: -5px;
  border-top: 1px solid;
  border-right: 1px solid;
  transform: skew(30deg);
  transform-origin: bottom right;
}

.radicand {
  display: inline-block;
  padding-left: 0.5em;
  transform: skew(15deg);
}
<p>Lorem ipsum
  <span class="root">
      <span class="radicand">
        2<var>xy</var>
</span></span> lorem ipsum.</p>
<p>Lorem ipsum
  <span class="root">
      <span class="radicand">
        2<var>x y</var><br>2<var>pq</var>

  </span> </span> lorem ipsum.</p>
<p>Lorem ipsum
  <span class="root">
      <span class="radicand">
        2<var>xy</var><br>2<var>pq</var><br>123,456,789
 
  </span> </span>lorem ipsum.</p>

Answer №2

Are you looking for a more efficient method? Absolutely. By incorporating a JavaScript library like MathJax, you have the ability to compose your equations in LaTeX syntax. This will result in visually appealing displays and on command prompt browsers, they will be rendered as LaTeX for enhanced clarity rather than experiencing the disappearance of mathematical symbols.

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

Angular can be used to compare two arrays and display the matching values in a table

Having two arrays of objects, I attempted to compare them and display the matching values in a table. While looping through both arrays and comparing them by Id, I was able to find three matches. However, when trying to display these values in a table, onl ...

Using various designs on elements generated from ng-repeat

Is it possible to apply different styles to buttons created using ng-repeat by having b.color return a value from the btnValues object? Currently, it is not returning the value. If this is not possible, are there alternative methods to achieve this? < ...

Add a CSS and jQuery hover effect to display text over an image, requiring users to click twice on their mobile device

I have a bunch of panels for different categories that change the background image when hovered over, display some introductory text, and lead to a URL when clicked. However, on mobile devices, you need to tap the panel twice to activate the URL. What I&a ...

While attempting to scrape data, the console.log function displays the information, however it is not being returned

This code is now working perfectly! However, I am struggling to organize the data into an array of separate objects. getGAS: function(url) { var self=this; rp(options) .then(($) => { let gasset = []; $('.stations-list').each(functio ...

angular use ngFor directive to restrict the number of rows displayed in a table

In my angular 6 project, I am trying to limit the display to just five rows in a table using ngFor. My current code snippet is as follows: <tbody> <tr *ngFor="let item of routines; let i = index"> <td style="display: none"> ...

Obtain the ID of a YouTube video from an iFrame link using jQuery

Check out this YouTube video: iframe width="560" height="315" src="//www.youtube.com/embed/XbGs_qK2PQA" frameborder="0" allowfullscreen></iframe>` (Hell Yeah! Eminem :P) I only want to extract "XbGs_qK2PQA" from the link provided. Using $(&apo ...

The overflow property is not functioning as anticipated

I've browsed Google and this site, but I couldn't find a solution to my issue. On my webpage, I have a shoutbox and a teamspeak viewer with a specific height for the outer div. The scrollbars don't look good on our new design, so I attempt ...

Form is protected from XSS attacks

Here's a basic form that I'm attempting to exploit with XSS using Chrome. <?php echo $_GET['comment']; ?> <script>alert('from HTML')</script> <form method="GET" action=""> Name: <input t ...

Which names can be used for HTML form tags in jQuery?

Recently, I encountered an issue related to jQuery form serialization which stemmed from naming a form tag "elements". The problem arose when using jQuery $(’form’).serialize(). Here is an example of the problematic code: <form> <input name=" ...

Creating a responsive layout with full-height divs within Bootstrap 4 columns

I am struggling to achieve uniform height for all my .element elements and need the image to be vertically aligned in the middle if it is too small to fill the space. I have tried numerous approaches but haven't been able to find a solution. .eleme ...

show a division once it's clicked

I'm currently facing an issue with a script that I can't seem to solve on my own. Essentially, I am attempting to make a div appear after clicking on the "Products" button. Here is what I have so far: <div id="header"> <div id=" ...

Creating interconnected circles with lines utilizing canvas

I am currently utilizing the canvas tag to generate circles on a world map image. My objective is to link these multiple circles with lines using the Canvas tag. Although I have successfully drawn the circles, I am facing difficulty in drawing the connecti ...

Angular and Ionic collaborate by using ngFor to pass on the item.id during a (click) event

I have a list of items and I want to dynamically change the height of a card when I click on a button that is located on the card. Can anyone guide me on how to achieve this? I attempted to pass the item.id through a click event and use the id in a functi ...

`Unable to activate label function in HTML`

As I dabble around with HTML and CSS, I've been experimenting with creating a custom file selection button. I came across a method on the internet that involves hiding the original button and superimposing a new one over it using the following code: ...

Issue with cutting of rotating pseudo element

Trying to rotate a pseudo element with a background-image is posing a challenge. The background, positioned at the center of the main element for visual effect, ends up being cut off when rotated. An illustrative example has been created using random imag ...

Log into your account by choosing a button using Selenium with Python

While attempting to access my account via this specific link on the Market Watch webpage using Python and Selenium, I encountered a roadblock. Despite successfully selecting the "Sign In" button, no action is triggered, preventing me from entering the desi ...

The name 'SafeUrl' cannot be located

I'm working on resolving the unsafe warning in the console by using the bypassSecurityTrustUrl method, but unfortunately, I keep encountering an error. user.component.ts import {Component,OnInit} from '@angular/core'; import { DomSanitizer ...

What is the best method for creating a loop script within a widget using script?

I am trying to implement a loop within a widget, however, the widget contains an internal script: <!DOCTYPE html> <html><head></head><body> <script> list=["AMAR3","BBDC4", "BEEF3", "BPAN4", "BRFS3", "B3SA3", "CVCB3" ...

The functionality of my PHP code for email transmission is currently malfunctioning

I'm having trouble sending mail from my HTML form using PHP. I've uploaded the necessary files to my hosting server but the mail is still not being sent. Here is my HTML code: <!-- Form --> <form action="http://example.com/sendEmail.php ...

The radio button fails to register the selection

I need to ensure a radio button is checked if it has a value, but the output of my code is not displaying as expected: <input id="radio2" type="radio" checked="checked" value="2" name="radio"> Despite specifying checked="checked", the radio button ...