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 on how to display a gif image during the loading of ajax content using JavaScript

Currently, I am attempting to load a gif image while waiting for the AJAX data to be loaded and displayed. However, I am struggling with this task. I would appreciate any assistance on how to implement a loading gif in my code for the advanced search feat ...

Opt for res.render() over res.send() when developing in Node.js

I recently developed an image uploader for ckeditor. After uploading a file, I need to send back an html file that includes the name of the image to the client. Check out the code snippet below: router.post('/upload', function (req, res, next) ...

Is it possible to identify the beginning of a download using Selenium?

Currently, I am using Python and Selenium to download a large batch of files. To ensure that each file is successfully downloaded, I am implementing a basic time.sleep() function, but I want to enhance efficiency and guarantee the completion of each downlo ...

Utilizing @Material-UI Tabs for a Stylish Navigation Bar

As a newcomer to the coding realm, I find myself on a quest for an answer that has proven elusive. Despite scouring various sources, none of the solutions I've stumbled upon seem to work in my case. The issue at hand revolves around my desire to util ...

jinja2.exceptions.UndefinedError: The variable 'asset' has not been defined

Currently in my project, I am using a Python backend to fetch data from an API and then rendering it through Flask to the Vue.js frontend. However, I have encountered an error titled that is causing some issues. I have double-checked and printed the varia ...

Animate out Material UI element with zoom effect and then remove it from the

I'm currently working on a dynamic user interface that allows for adding and removing items dynamically. Each item has both an add and remove button, with a special animation effect using Zoom. While this works smoothly when adding new items, I encoun ...

Encountering persistent issues while attempting to integrate socket.io into my Node.js application with Express

Recently, I've been exploring ways to create a textbox that allows multiple users to type simultaneously. Below is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> ...

The discovery of a commitment in the statement. The automation of unwrapping promises within Angular statements has been phased out

Struggling with errors while setting up a new AngularJS project. Here is the code for my app and controller; var app = angular.module('myApp', ['localytics.directives']) .config(['$parseProvider', function ($parseProvide ...

Here's a guide on using a button to toggle the display of password value in Angular, allowing users to easily hide

I have successfully implemented an Angular Directive to toggle the visibility of password fields in a form. However, I am facing an issue with updating the text displayed on the button based on the state of the input field. Is there a way for me to dynami ...

The validation process in reactive forms is experiencing some issues with efficiency

Trying to debug an issue with my reactive forms - the repeatPassword field doesn't update as expected. When entering information in the "password" field, then the "repeatPassword" field, and back to "password", the second entry is not flagged as inval ...

How to create a dynamic height grid using Bootstrap?

Seeking assistance with implementing the layout shown in the image below using bootstrap 4. I am facing an issue with adjusting the height of div 1 and 2 dynamically based on the content in div 3. Can anyone provide some guidance? https://i.sstatic.net/mk ...

Troubleshooting issue: Bootstrap button onclick function not firing

My node express app is using EJS for templating. Within the app, there is a button: <button type="button" class="btn btn-success" onclick="exportWithObjectId('<%= user.id %>')">Export to csv</button> Accompanying the button i ...

Retrieving Information from JSON Dataset

Having trouble retrieving data from this Json Data source: No errors are being displayed, but the requested data is not showing up. The issue lies in the response received from the API being an object instead of an array. What should be used to replace th ...

The next promise in a promise chain does not wait for the previous promise to resolve

I am completely new to the concept of Promises, but I have read that they are a powerful tool for executing functions one after another through Promise chaining. The code snippet below, under //RUN ON CLICK: CREATE TABLES, makes two AJAX calls - "Create D ...

How can I eliminate the empty spaces surrounding an image?

How can I remove the extra space around an image that is placed inside a bootstrap column? On the desktop version, I was able to solve the issue by setting -1rem margins on the left and right. I tried adjusting the body margin and padding to 0, as well as ...

Sequelize.Model not being recognized for imported model

I am encountering an issue while trying to implement a sequelize N:M relation through another table. The error message I keep receiving is as follows: throw new Error(${this.name}.belongsToMany called with something that's not a subclass of Sequelize ...

Cut off text inside an HTML anchor element using an ellipsis, while ensuring the image remains at the end - all without the need for JavaScript

How can I truncate link text on a header with an ellipsis but keep the image at the end as a glyphicon? And all of this without using JS. Here's my code: <!DOCTYPE html> <html> <body> <ul> <li> <a href="# ...

Show JSON information from a jQuery post request

Greetings, I am currently working on implementing a login script using Ajax. My objective is to retrieve and display data such as email and username, and then store it in local storage. Although I can successfully obtain the data in JSON format, I want to ...

Include a floating element within a modal box

I am trying to display some cards within a Bootstrap modal form. Inside the modal, I want the cards to appear in two columns by using the "col-md-5" class. .mycard.col-md-5 card contents However, when I use the "col-md-5" class, it adds a property o ...

React is unable to identify the `activeStyle` property on a DOM element

Is there anyone who can help with this error message? The warning states: React does not recognize the activeStyle prop on a DOM element. If you want it to be a custom attribute in the DOM, use activestyle in lowercase instead. If it was accidentally pas ...