Style Only P Element of Its Parent with CSS

Prabhas
Updated on 01-Jul-2020 08:59:10

178 Views

Use the CSS :only-of-type selector to style every element that is the only element of its parent.ExampleYou can try to run the following code to implement the :only-of-type selector:Live Demo                    p:only-of-type {             background: orange;             color: white;          }                              This is demo text 1.                      This is demo text 2.          This is demo text 3.          This is demo text 4.          

Role of CSS :nth-of-type Selector

Ankith Reddy
Updated on 01-Jul-2020 08:58:41

154 Views

Use the CSS :only-of-type selector to style every element that is the only element of its parent.ExampleYou can try to run the following code to implement the :only-of-type selectorLive Demo                    p:only-of-type {             background: orange;             color: white;          }                              This is demo text 1.                      This is demo text 2.          This is demo text 3.          This is demo text 4.          

HTML DOM Input Number Autofocus Property

Sharon Christine
Updated on 01-Jul-2020 08:55:59

134 Views

The HTML DOM input number autofocus property returns and modify whether the input number field should get focused or not when page load.SyntaxFollowing is the syntax −Returning autofocusobject.autofocus2. Modifying autofocusobject.autofocus = true | falseExampleLet us see an example of HTML DOM input number autofocus property − Live Demo HTML DOM autofocus property    body{       text-align:center;       background-color:#1b203a;       color:#ff8741;    }    p{       font-size:1.2rem;    }    input{       border:none;       background-color:#ffffff4a;       height:1.2rem;       padding:8px;       color:#fff; ... Read More

Array Diff Key Functionality in PHP

AmitDiwan
Updated on 01-Jul-2020 08:39:46

173 Views

It is an inbuilt function that compares the keys of one or more arrays, and returns their difference.Syntax of the array_diff_key functionarray array_diff_key($array1, $array2, ..)The function can take two or more array names as parameters, and compares the first array with the remaining arrays.Example Live DemoOutputArray (    [91] => Micheal )Inside the tags, three arrays are declared with certain values in them. They are printed by calling the ‘array_diff_assoc’ function by passing all the three arrays to it as parameters. The resultant value is the different between the first array, and second array as well as the difference ... Read More

Significance of 'in' in PHP

AmitDiwan
Updated on 01-Jul-2020 08:37:23

432 Views

The ‘^’ is a bitwise operator in PHP, i.e XOR (exclusive OR) bitwise operator, that is used to display the ASCII values of variables in question. For example − For evert bit in the value, the ^ operator checks if that bit is the same in the other value too. If the values are same, 0 is produced as an output, otherwise 1 is shown as output. Below is an example illustrating the same −Example Live DemoOutputb aDifferent variables are assigned character values and the ‘^’ operator is used to perform XOR on the two variables. Relevant output is displayed on the console.

Delete Element from Array in PHP and Re-index the Array

AmitDiwan
Updated on 01-Jul-2020 08:35:38

2K+ Views

The ‘unset’ function can be used to remove an element from the array and use the ‘array_values’ function that resets the indices of the array.Example Live DemoOutputThe array is array(5) {    [0]=>    string(4) "this"    [1]=>    string(2) "is"    [2]=>    string(1) "a"    [3]=>    string(6) "sample"    [4]=>    string(4) "only" } The array is now array(4) {    [0]=>    string(4) "this"    [1]=>    string(2) "is"    [2]=>    string(1) "a"    [3]=>    string(6) "sample" }An array is declared that contains string values. The array is displayed and the ‘unset’ function is used to delete a specific index element from the array. Then the array is displayed again to reflect the changes on the console.

Find Standard Deviation of Values Within an Array in PHP

AmitDiwan
Updated on 01-Jul-2020 08:33:25

939 Views

To find standard deviation of values within an array, the code is as follows in PHP −Example Live DemoOutputThe standard deviation of elements in the array is 35.423156268181A function named ‘std_deviation’ is defined counts the number of elements in the array and initializes the variance to 0. The average is calculated as the sum of elements in the array divided by the total number of elements in the array. Now, a ‘foreach’ loop is run over the array and the variance is calculated by subtracted the average value from every element of the array and squaring it.When the foreach loop goes ... Read More

Find Missing Elements from an Array in PHP

AmitDiwan
Updated on 01-Jul-2020 08:32:02

1K+ Views

The ‘array_diff’ function can be used to find the elements that are missing from the array.Example Live DemoOutputElements missing from first array are Array (    [1] => 46    [2] => 47    [4] => 49    [5] => 50    [9] => 54    [10] => 55 ) Elements missing from second array are Array (    [1] => 100    [3] => 102    [4] => 103 )A function named ‘absent’ is defined that checks to see the minimum number and the maximum number and generates an array within that range. The function then returns the difference between this array and the original array, using the ‘array_diff’ function, that gives the missing elements from the array.

Remove Duplicate Elements from an Array in PHP

AmitDiwan
Updated on 01-Jul-2020 08:30:36

832 Views

The ‘array_flip’ function can be used, that will reverse the values as indices and keys as values.Example Live DemoOutputThe original array contains Array (    [0] => 45    [1] => 65    [2] => 67    [3] => 99    [4] => 81    [5] => 90    [6] => 99    [7] => 45    [8] => 68 ) The array after removing duplicate elements is Array (    [0] => 45    [1] => 65    [2] => 67    [3] => 99    [4] => 81    [5] => 90    [6] => 68 )An array ... Read More

Get Screen DPI Programmatically in Android

Azhar
Updated on 01-Jul-2020 08:24:22

1K+ Views

This example demonstrates how do I get screen DPI programatically in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    Button button;    TextView textview;    float value = 0;    DisplayMetrics displaymetrics;    Activity activity;    @Override    protected void ... Read More

Advertisements