Adjusting diagram size based on screen width using Bootstrap and jQuery

I recently created a diagram that adjusts its size according to the screen width. However, when I implemented this code on my page, I encountered an issue where the final circle or glyph would drop to the next line instead of staying on the same line as intended. You can view the recreated (poorly) version in the fiddle.

Check out my fiddle here.

Below is the code snippet:

html

<div class="glyphicon-belt">

        <div id="rectangle"></div>

        <div class="container circle-container circle-1">
            <i class="icon-steak" style="font-size: 60px"></i>
        </div>

        <div class="container circle-container circle-2">
            <i class="icon-brain" style="font-size: 60px"></i>
        </div>

        <div class="container circle-container circle-3">
            <i class="icon-happy" style="font-size: 60px"></i>
        </div>

</div>

css

.circle-container {
    background-color: #FDA220;
    width: 100px;
    height: 100px;
    border-radius: 100px;
    text-align: center;
    display: inline-block;
    line-height: 100px;
    margin-top: -60px;
}

.glyphicon-belt {
    width: 50%;
    left: 25%;
    position: absolute;
    text-align: center;
    margin-top: 100px;
//  background-color: black;
}

#rectangle {
    width: 80%;
    margin-left: 10%;
    height: 20px;
    background: #E7292A;
}

.circle-1 {
    margin-right: 26%;
}

.circle-2 {
    margin-right: 26%;
}

.circle-3 {
//  margin-right: -5%;
}

.glyph-connect {
//  left-margin: 25%;
    text-align: center;
    padding: 0px;
    background-color: black;
}

jQuery

var screen = $(window).width();
var fontRatio = 60 / screen;
var circleRatio = 100 / screen;
var barRatio = 20 / screen;

$(window).on('resize', function() {
    var screen = $(window).width();
    var fontSize = screen * fontRatio;
    var circleSize = screen * circleRatio;
    var lineHeight = circleSize + "px";
    var barHeight = screen * barRatio

    $(".icon-steak").css("font-size", fontSize);
    $(".icon-brain").css("font-size", fontSize);
    $(".icon-happy").css("font-size", fontSize);

    $(".circle-container").css("width", circleSize);
    $(".circle-container").css("height", circleSize);
    $(".circle-container").css("line-height", lineHeight);

    $("#rectangle").css("height", barHeight);
});

Answer №1

After carefully interpreting your query and experimenting with it, it appears that the issue lies in rectifying the circle-3:

.circle-3 {
  margin-right: 1%;
}

It is unclear why you had it commented out, but uncommenting it and adjusting the percentages seems to resolve the problem.

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

Tips for Troubleshooting External Evaluation Scripts

For a specific example, take a look at the haystack.js script from How Big is Your Haystack? I've been searching for a solution and it seems that using the //# sourceURL=name.js comment is the way to go. However, I am struggling with the process of a ...

PHP service encountering a failure during an AJAX call

After setting up a web service with PHP, I found that when accessing it from a rest client, the JSON response is correct. However, when calling the method from an AJAX call integrated into a Drupal site, the service response comes back as HTML, leading to ...

The resizing function on the droppable element is malfunctioning on Mozilla browsers

I've been working on making one div both droppable and resizable. Surprisingly, everything is functioning perfectly in Chrome but not in Firefox. If you'd like to see the issue for yourself, here is my jsFiddle demo that you can open in Firefox: ...

What is the best way to dynamically hide a textbox in JSP based on the selection of a

On my JSP page, I have a textbox and a checkbox. I attempted to use jQuery and JavaScript to hide the textbox when the checkbox is checked, but it doesn't seem to be working. Below is the code snippet: <p class="contact"> <input id="check" n ...

Cookie Multitree: An Innovative JsTree Solution

Hello everyone, I am currently using jstree and have come across a couple of issues with having multiple trees on the same page. Here are my two problems: 1) I am looking to implement cookies to keep track of which nodes are open in each tree. I attempted ...

Unable to set a specific position for adding a new option in a dropdown menu

I have implemented a semantic UI dropdown using the code below: $('.ui.dropdown') .dropdown() ; <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <l ...

Performing an automated check on user messages every 60 seconds using JQuery and Ajax

I am in the process of developing a website with notification features, and I am looking to implement a script that will check for new messages every 60 seconds. The goal is to pass the user id through the script to trigger an alert (currently using a ba ...

The webpage's Document Object Model fails to refresh following a JavaScript modification

I have encountered an issue with a sample webpage where I am attempting to set the wmode of all YouTube elements on the page to "transparent." When inspecting the page using Chrome, I can see that my JavaScript code is functioning properly. However, the b ...

Steps for generating a hierarchical menu utilizing data from a CSV file

I am looking to use a CSV file to structure the menu on my webpage. Could someone assist me in creating a nested menu using JavaScript with the provided CSV data? The columns consist of: Level, Menu name, URL 0;"Service"; 1;"Service 1";"http://some-url- ...

Showing a database table in an HTML format using JavaScript

I am currently working on displaying a database table in HTML. I have written a PHP code snippet which retrieves the table data and formats it into an HTML table without any errors: function viewPlane() { if(!$this->DBLogin()) { $ ...

A fixed HTML div with a relative div is like having your own

I am in search of two divs with the following styles: <div style="height:20px;" /> <div style="height:100%;" /> These divs result in one being 20px tall and the other spanning 100% of the screen height, causing a vertical scrollbar that is eq ...

Unit testing with Jest involves creating mock implementations of IF conditions within functions to ensure complete code coverage

Currently, I am working with an API script stored in a file. const ApiCall = { fetchData: async (url) => { const result = await fetch(url); if (!result.ok) { const body = await result.text(); // uncovered line throw new Error(`Err ...

The ForEach function does not execute actions on every individual object, but rather only once

I am currently developing a Deck building application for a card game. In addition, I have set up a database to manage the cards that I sell and play with. The deck builder tool I created allows me to deplete the stock of sellable cards when adding them to ...

Separating the rules for development and production modes in the webpack configuration file

I'm currently in the process of working on a front-end project using HTML. Within my project, I have integrated the Webpack module bundler and am utilizing the image-webpack-loader package for image optimization. However, I've encountered an issu ...

How to Share Your Vuejs Component with the World by Publishing it on npm

I have recently developed a Vue.js 2 project using webpack which consists of 2 components. My goal is to share this project as an npm package so that the components can be easily reused in multiple projects. After publishing the project on npm with npm pu ...

Tips for customizing styles when an element is being dragged over in Material-UI?

If I want to alter the backgroundColor when hovering, I can utilize sx={{"&:hover":{backgroundColor:"yellow"}} Is there a way to adjust the backgroundColor on dragover? It appears that sx={{"&:dragOver":{backgroundCol ...

Navigational paths for the persistent sidebar in Material UI

I am looking to utilize this as a page navigation, but I am struggling with properly linking it to the index. I have attempted separating the items, but that approach did not work as intended. <List> {['Home' , 'Abo ...

Showing the heading again after a new page starts

Currently, I am using WeasyPrint to generate a document and facing an issue with long sections that may span multiple pages. When a section breaks across pages, the name of the section does not display after the page break as intended. The following examp ...

Dropdown Placement Based on Button Click

Looking to create an interactive dropdown menu with the Alloy UI Dropdown Component that appears when a user clicks on one of four buttons. The goal is for this dropdown to be positioned to the left of the clicked button. var toolsDropdown = new Y.Dropdow ...

There seems to be an issue with declaring Gulp Open

Here is the code snippet for my `open.js` task: import gulp from 'gulp'; import gulpOpen from 'gulp-open'; gulp.task('open', () => { // doesn't work with `function()` either. const options = { uri: 'local ...