#StackBounty: #php #css #mysql #bootstrap-4 #navbar Build boostrap4 navmenu from multiple mysql tables

Bounty: 50

I want to make a bootstrap 4 nav-menu, I have the following SQL query and I have some codes below it but I can’t get my head around how to do this!

These are the tables

TABLE menu
--------------------------------------
| id | title       | url             |
| 1  | Home        | index.php       |
| 2  | Menu        | #               |
| 3  | Contact     | #               |
| 2  | Winkelwagen | winkelwagen.php |
--------------------------------------

TABLE categories
-------------------------------------
| id | title_cat | url | cparent_id |
| 1  | Auto's    | #   | 2          |
| 2  | Drank     | #   | 2          |
-------------------------------------

TABLE products
-------------------------------------
| id | product  | url  | pparent_id |
| 1  | Ferrari  | #    | 1          |
| 2  | Heineken | #    | 2          |
-------------------------------------

Here is the query:

$query =    "SELECT
            X.level,
            X.id,
            X.name,
            X.url,
            X.parent_id
        FROM
            (
            SELECT
                1 AS LEVEL,
                id AS id,
                title AS NAME,
                url AS url,
                0 AS parent_id,
                id AS id_1,
                -1 AS id_2,
                -1 AS id_3
            FROM
                menu
            WHERE
                1
            UNION
        SELECT
            2 AS LEVEL,
            id AS id,
            title_cat AS NAME,
            url AS url,
            cparent_id AS parent_id,
            cparent_id AS id_1,
            id AS id_2,
            -1 AS id_3
        FROM
            categories
        WHERE
            1
        UNION
        SELECT
            3 AS LEVEL,
            products.id AS id,
            products.product AS NAME,
            products.url AS url,
            products.pparent_id AS parent_id,
            categories.cparent_id AS id_1,
            categories.id AS id_2,
            products.id AS id_3
        FROM
            products
        LEFT JOIN categories ON products.pparent_id = categories.id
        WHERE
            1
        ) X
        WHERE
            1
        ORDER BY
            id_1,
            id_2,
            id_3";

Which gives the following table with levels (and I added the parent_id too, but with the parent_id buildTree($array) goes into a loop):

level   id  name        url             parent_id   
1       1   Home        index.php       0   
1       2   Menu        #               0   
2       1   Auto's      #               2   
3       1   Ferrari     #               1   
2       2   Drank       #               2   
3       2   Heineken    #               2   
1       3   Contact     contact.php     0   
1       4   Winkelwagen winkelwagen.php 0   

I want the nav-menu to look like this:

        <li class="nav-item">
            <a class="nav-link" href="index.php">Home</a>
        </li>
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Menu</a>
            

I have the following codes, first we make a array from the query fetched which you already saw above:

$sql = $pdo->prepare($query);

function menu_builder($sql) {
    if ($sql->execute()) {
        while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
            $array[] = $row;
        }
        buildTree($array); // or menu_builder($sql);
    }
}

The next code doesn’t work because it goes into a infinite loop (and if it works I still need to make the html right :):

function buildTree($array, $parent_id = 0, $parents = array()) {
    if($parent_id == 0) {
        foreach ($array as $element) {
            if (($element['parent_id'] != 0) && !in_array($element['parent_id'], $parents)) {
                $parents[] = $element['parent_id'];
            }
        }
    }
    $menu_html = '';
    foreach($array as $element) {
        if($element['parent_id'] == $parent_id) {
            if(in_array($element['id'], $parents)) {
                $menu_html .= '<li class="dropdown">';
                $menu_html .= '<a href="'.$element['url'].'" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">'.$element['name'].' <span class="caret"></span></a>';
            }
            else {
                $menu_html .= '<li>';
                $menu_html .= '<a href="' . $element['url'] . '">' . $element['name'] . '</a>';
            }
            if(in_array($element['id'], $parents)) {
                $menu_html .= '<ul class="dropdown-menu" role="menu">';
                $menu_html .= buildTree($array, $element['id'], $parents);
                $menu_html .= '</ul>';
            }
            $menu_html .= '</li>';
        }
    }
    return $menu_html;
}

And this one makes a normal <ul>/<li> menu which I don’t know how to get it working for me with bootstrap:

function menu_builder($sql) {
    $level = 0;
    if ($sql->execute()) {
        while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
            while($level < $row['level']) {
                echo "<ul>" . PHP_EOL;
                $level++;
            }
            while($level > $row['level']) {
                echo "</ul>" . PHP_EOL;
                $level--;
            }
            echo "    <li>#" . $row['id'] . "->" . $row['name'] . "</li>" . PHP_EOL;
        }
    }
    while($level-- > 0) {
       echo "</ul>" . PHP_EOL;
    }
}

If you need more information please ask me, I tried to make the question as clear as possible with the codes I’m trying and the table I’m using.

jQuery:

$('.dropdown-menu a.dropdown-toggle').on('click', function(e) {
    if (!$(this).next().hasClass('show')) {
        $(this).parents('.dropdown-menu').first().find('.show').removeClass("show");
    }
    var $subMenu = $(this).next(".dropdown-menu");
    $subMenu.toggleClass('show');
    $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function(e) {
        $('.dropdown-submenu .show').removeClass("show");
    });
    return false;
});

CSS:

.dropdown-submenu {
  position: relative;
}

.dropdown-submenu a::after {
  transform: rotate(-90deg);
  position: absolute;
  right: 6px;
  top: .8em;
}

.dropdown-submenu .dropdown-menu {
  top: 0;
  left: 100%;
  margin-left: .1rem;
  margin-right: .1rem;
}


Get this bounty!!!

#StackBounty: #javascript #html #css #window Split view function: the browser window splitted in 2 horizontal panes (vanilla html js css)

Bounty: 100

Untill HTML 4 it was possible to create layouts with frames loading different html files in different panes.

What I want to do is to achieve a similar result but loading and showing on screen two different part of the same document.

My ideal paradigm is MS Word which allows to split the window in 2 horizontal parts to show in each one different sections of the same document (extremely useful when comparing different parts of the document or when moving parts from one distant side to the other on long documents) or MS Excel (even LibreOffice or OpenOffice Calc have a similar feature) that allows to split the pane of the sheet in 2 (or even in 4) sections for the same reason or to keep visible some rows on top or some columns at the right (row or column header for example).

Is that possible to do a similar thing in pure html js css (no jquery or other framework please)?

Constrains:

  1. The document must be the same for all 2 panes (top and bottom) (old frameset needs to load two different documents or the same document twice: I’m using this already but I want a more clean approach if possible!)
  2. The separator (gutter?) has to be resizable
  3. The two different parts of the document are perfectly in sync in the sense that if I modify something in the top (or bottom) pane the bottom (or the top) pane shows instantly the edit just done as does MS Word or Excel… so if I delete something in any bottom pane table cell even the top content is adjusted accordingly (even the column size), as happens with MS Word, Excel, Calc
  4. The splitted view will be switched on and off on click on a specific button
  5. I don’t care about old browsers, just ECMA script 2015 or more recent ones

Why I’ll use it?

I have a bunch of tables into a LOCAL html file (no web server involved) that loads data from a csv file or from the browser session storage and I frequently need to compare data from different points or to keep the header fixed on top while scrolling the rest of a specific table or while inserting new data or updating old data in one of them to continuously see in which table cell I’m inserting or updating data in.

Situation:

At the moment I’m using the following code:

function splitView()
{
    var tgtSrc = location.href;
    var frameset =  '<frameset rows="*,*">' +
                        '<frame name="' + upFrame + '" src="' + tgtSrc + '">' +
                        '<frame name="' + dwFrame + '" src="' + tgtSrc + '">' +
                    '</frameset>';
    document.write(frameset);   
}

The above function splits horizontally the current window pane in two frames called upFrame and dwFrame (that are two variables). After splitting a resizable gutter is placed between the two frames.

Plus the algorithm to sync both instances of the document’s data: it works by saving at each data edit in one frame the data into the session storage of that frame and reloads the same data into the other frame.

It kinda works but frames aren’t the way to go, I would like to get rid of the need to load the document twice and sync each instance with all the relative drawback involved. So unfortunately this isn’t the ultimate answer I’m looking for because it has some drawbacks:

  1. The frame and frameset tags are not supported in modern HTML5 compliant files even if they are still supported by browsers
  2. The file has to be loaded twice (once per frame) this means a noticeable lack of performance and difficult to sync in real time any edits in one frame with the other frame (possibly bidirectional sync is needed so edits could be done in both shown part of the document). Unfortunately even the sync process needed means loosing performances that lock the UI for some instant every sync loop
  3. The sync process isn’t in real time, it has some delay (some seconds): if I make it shorter I have a large lack of performances that includes browser freezing

So I’m open to better answers with cleaner and more efficient solutions.
(I have even proposed to Chrome devs to implement a function for it in the browser, because I really think this is a Must Have feature especially considering the expanding online data management systems.)

What I’m looking for:

So the ultimate solution I’m looking for is something similar to the splitting function used by google spreadsheet, here an image with the example https://i.imgur.com/X7hm6Lr.png. Look carefully at it: there is the gutter that is possible to move horizontally (there is a vertical gutter too, but I don’t really care about vertical splitting, just horizontal) and when the spreadsheet scrolls down the rows disappear under it: in fact the first row above the gutter is the n. 1 the first row down the gutter is n. 45.
Also notice the little double headed white arrow indicated by the big red arrow at the extreme left of the picture…

IMHO this is a feature that every browser (even those for portable devices) have to have implemented natively and without using the old technology of frames that are no more supported in html 5. Unfortunately this possibility to split the same document to show and edit different parts of it (as a very long table for example) isn’t (yet) a browser feature, so in the meanwhile… is needed a workaround.

Thanks in advance.


Get this bounty!!!

#StackBounty: #css #css3 #clipboard #flexbox flexbox adding newline to clipboard

Bounty: 50

I’m working a layout that uses flexbox. Works good so far but i have a problem with copying text to clipboard.
Apparently, using flexbox seems to add a newline character after each child node

Fiddle: http://jsfiddle.net/zv4mamtm/

It can be seen on the fiddle, copying text “LabelMessage” works normally (paste it and it remains one-line). But if you add display:flex to container a newline is added after “Label” upon copying to clipboard

What is causing this? Is there any way around it?


Get this bounty!!!

#StackBounty: #css #reactjs #webpack Webpack doesn't respect import order

Bounty: 50

We are currently working with Webpack and React using Bootstrap for the design and a custom CSS/SASS that overrides some of bootstraps styles.

On a simple HTML page we use:

<!-- Custom styles for this template -->
<link href="./../../css/creative.css?v=1.9" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css"> 

Our style overrides bootstrap for example our <hr>

the one shown is the one defined in our creative.css

hr {
  max-width: 50px;
  border-width: 3px;
  border-color: #F05F40;
}

However when I move the design to the project using react and webpack only bootstrap overrides everything.

I have tried:

import './css/creative.css'
import './css/bootstrap.css'

And:

import './css/bootstrap.css'
import './css/creative.css'

Also tried to wrap app.js into a index.js and style the parent then the child like this:

  • index.jsx : import './css/bootstrap.css'

  • app.jsx : import './css/creative.css'

also tried the other way:

  • index.jsx : import './css/creative.css'
  • app.jsx : import './css/bootstrap.css'

But my custom style never overrides the bootstrap style.

This doesn’t only happen for the HR but for example we have completely restyled the form inputs but they just appear as bootstraps default.


Get this bounty!!!

#StackBounty: #ios #css #objective-c #xcode Load .CSS file from within app in uiwebview

Bounty: 50

i am trying to load .js and .css files from within app resources to uiwebview. and i am able to load .js file but can not load .css file please help. here is my code

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    //NSString *cssFile = @"styling.css";

    NSString *jsFile = @"storage.js";
    NSString *jsFilePath = [[NSBundle mainBundle] pathForResource:jsFile ofType:nil];
    NSURL *jsURL = [NSURL fileURLWithPath:jsFilePath];
    NSString *javascriptCode = [NSString stringWithContentsOfFile:jsURL.path encoding:NSUTF8StringEncoding error:nil];
    [webView stringByEvaluatingJavaScriptFromString:javascriptCode];
}

this code it working perfectly for .js file but how can i use .css file in it?


Get this bounty!!!

#StackBounty: #css #css3 #google-chrome #printing #scale What CSS property corresponds to Chrome's "scale" setting

Bounty: 100

In Chrome’s print dialog (under “advanced”), there is a “scale” setting.

Chrome's print dialog's "scale" setting

What CSS property maps to this setting?

Using this setting, I can adjust the scale of the content to be printed so that it wraps correctly. If I can determine the corresponding CSS property, I can define that scale in the print media rules.

I have tried transform:scale(0.75); and zoom:75%;, but neither setting seems to behave the same way.


Get this bounty!!!

#StackBounty: #woocommerce #jquery #css Add slider to product thumbnails in WooCommerce

Bounty: 50

I want to display my product thumbnails in a slider like this one: http://flexslider.woothemes.com/thumbnail-slider.html

I found a way to add some options to the image slider itself:

// Update WooCommerce Flexslider options
add_filter( 'woocommerce_single_product_carousel_options', 'ud_update_woo_flexslider_options' );

function ud_update_woo_flexslider_options( $options ) {

    $options['directionNav'] = true;

    return $options;
}

But I found no way to add a slider to the thumbnails and let them sync with the image slider (like in the example).

Is there any way to do this?


Get this bounty!!!

#StackBounty: #css #angular #flexbox #angular-material2 How to make a flexbox in a div to have 2 columns with ngFor of mat-chips/angula…

Bounty: 50

I have a list of fruits with 10 entries. I want to make it so that the fruit name text (next to a mat-chip) are displayed in two columns with 5 in each column. The chips I am using are here: https://material.angular.io/components/chips/api

My CSS:

.flexp {
    display: flex;
    flex-wrap:wrap;
}

.flexc {
    flex-grow: 1;
    display: inline-block;
}

HTML

       
{{fruit.typeOfFruit}} {{fruit.name}}
</div>

How can I do this? Right now my flexbox is going from top to bottom.

I want to make to so that it looks like a table, but without having to create the structure. If there was a way for the ngFor to be smart enough to make it display in this way… that is what I am looking for:

<table>
<tr>
<td>Fruit 1</td><td>Fruit 6</td>
<td>Fruit 2</td><td>Fruit 7</td>
<td>Fruit 3</td><td>Fruit 8</td>
<td>Fruit 4</td><td>Fruit 9</td>
<td>Fruit 5</td><td>Fruit 10</td></tr>
</table>

If it is not possible, please state.


Get this bounty!!!

#StackBounty: #javascript #html #css #z-index #scaletransform Video and z-index inside scaled element: some divs disappear

Bounty: 50

I have a somewhat strange behaviour in Chrome and Safari. I have a scaled (transform: scale()) container with a video and other elements inside of it. At some scalings the absolute positioned elements with a high z-index disappears and does not come back again.

Example

I have made an example that scales the outermost container up and down. At a specifik scale value the element with class .on-top (and text "I should always be on top.") disappears. When scaling down again it suddenly appears.

Link to exmaple: https://jsfiddle.net/iafiawik/Lcox1ecc/

enter image description here

Conclusions

  • It seems like the size of the element matters. The larger I make it, the larger is the scale value before it disappears.
  • I have also tested to set transform: scale(1.4) with CSS directly on the element and the behaviour is the same.

The issue does not exist if I:

  • Replace the video tag with a div
  • Remove position: absolute; from siblings to .on-top (that is, .below)
  • Remove overflow: hidden; from .content
  • If I move .on-top so it is placed after the video tag in the document flow

Browsers

I have seen this issue in Chrome (Mac) and Safari (Mac).

Does anyone have a clue what I could do to prevent this from happening?


Get this bounty!!!

#StackBounty: #html #css #html5 Converting DIV-like page into blog-like layout within CSS?

Bounty: 50

This is my HTML page:

https://jsfiddle.net/62czmtvt/2/ (to actually see the HTML page working)

Code from JSFiddle:

  <meta charset="utf-8">

  <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
       Remove this if you use the .htaccess -->
  <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">
   <head>
<!-- this is the stylesheet in the file -- <link rel="stylesheet" type="text/css" href="style.css"> -->
<!-- contents of style.css -->
<style>
:root {
background-color: #FFFACD;
}
div.infoguide { 
width: 240px; 
font-family: Arial, sans-serif; 
font-size:13px; 
background-color: #F0FFF0;
}
div {
 margin:5;
  padding:0;
  border:0;
  outline:0;
}
A:link { text-decoration: underline; color: rgb(204, 51, 51); }
A:visited { text-decoration: underline; color: rgb(204, 51, 51); }
A:active { text-decoration: underline; color: rgb(204, 51, 51); }
A:hover { text-decoration: underline; color: rgb(204, 51, 51); }
body { margin-left: 0px; margin-top: 0px; }
body, td, th { font-family: Arial,Helvetica,sans-serif; font-size: 12px; color: rgb(46, 46, 46); line-height: 16px; }
h1 { font-family: Arial,Helvetica,sans-serif; font-size: 20px; font-weight: bold; line-height: 20px; margin-bottom: 0px; }
h2 { font-family: Arial,Helvetica,sans-serif; font-size: 15px; font-weight: bold; margin-bottom: 0px; }
h3 { font-family: Arial,Helvetica,sans-serif; font-size: 13px; font-weight: bold; margin-bottom: 0px; }
h3 A:link { text-decoration: none; color: rgb(204, 51, 51); }
h3 A:visited { text-decoration: none; color: rgb(204, 51, 51); }
h3 A:active { text-decoration: none; color: rgb(204, 51, 51); }
h3 A:hover { text-decoration: underline; color: rgb(204, 51, 51); }
ul { margin-left: 1.5em; padding-left: 0px; }
.info_data { border-color: rgb(137, 137, 137); border-style: solid; border-width: 1px; font-size: 11px; padding: 4px; text-align: center; }

.news_headline { font-family: Arial,Helvetica,sans-serif; font-size: 15px; font-weight: bold; line-height: 22px; }
.red { color: rgb(204, 51, 51); }
.red_padded { color: rgb(204, 51, 51); padding: 4px 0px; }
.redbg { background-color: rgb(220, 6, 0); } 
</style>
</head>
</head> 
      <title>First Drive: 2017 Porsche Panamera - Autos.ca</title>

It works!

It works!

A headline

It works!

It’s a sandbox page for a blog-like layout of a magazine site, and I’m trying to achieve this sort of look:

Magazine article

but so far I haven’t quite managed to get it to look the way I want to of being a three-column DIV with a header in a pseudo-blog-style layout.

I’ve been trying the :root element in my CSS file, is this encouraged or discouraged in a HTML5 page?

I would appreciate any advice or help with this!


Get this bounty!!!