Ways to keep the original width of an SVG image while centering it

Within my trio of blocks, I've embedded an svg image, but the styling is like so:

.rating {
text-align: center;
background-color: var(--light-grayish-magenta);
color: var(--very-dark-magenta);
font-weight: 700;
border-radius: 7px;
max-width: 26em;
margin-left: auto;
margin-right: auto;
}

.rating::before {
content: '';
width: 5.625em;
height: 1em;
display: block;
background-image: url(images/icon-star.svg);
background-repeat: space;
}

Additionally, a @media query has been implemented.

@media screen and (min-width: 21.885em) /* breakpoint 350px phones ---> tablets */ {
.status {
    max-width: 20em;
    margin-left: auto;
    margin-right: auto;
}
    .rating {
    padding: 0.9em;
}
    .rating::before {
    margin-right: 0;
    margin-left: 0;
    margin-bottom: 7px;
    display: block;
    max-width: 300px;
}

The HTML snippet is as follows:

    <div class="status flow-content">
        <div class="rating">Rated 5 Stars in Reviews</div>
        <div class="rating">Rated 5 Stars in Report Guru</div>
        <div class="rating">Rated 5 Stars in BestTech</div>
    </div>

Unfortunately, when the screen size decreases, the image also shrinks and starts behaving erratically. Various adjustments have been made with margins, displays, etc., but the issue persists. Any helpful suggestions?

Answer №1

I tried to reproduce the problem you mentioned with the code you shared, but I couldn't. However, I was able to successfully align the stars in the center and it looked much better that way. You can improve it further by adding the following line of code to '.rating::before' in your CSS:

margin: 0 auto;

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

What's causing ng-show to malfunction in IE11 on AngularJS?

I am experiencing a strange issue with my code - ng-show works perfectly fine on Firefox, but not on IE 11. <div ng-show="isExist" class="panel panel-default"> Here is the relevant code snippet from the controller: $scope.isExist = false; if(user ...

"Learn how to showcase a picture in full-screen mode when the webpage is opened

I recently came across a script on Stack Overflow that allows me to select an image at random from an array. The script can be found here: Script to display an image selected at random from an array on page load However, I want to take this concept furthe ...

The variation in CSS output between Google Chrome on Windows and Ubuntu

My code includes a div tag: <a href="#"><div class="field btn half green" id="register-btn">Register</div></a> Here is the CSS code for the tag: .field { position: absolute; width: 205px; left: 22px; color: #eaeae ...

Utilizing Jquery to create a carousel with looping functionality for flowing text

I am currently facing an issue with a carousel that contains multiple images and text. In order to make the text responsive, I have implemented a script called FlowText. The script works perfectly on the initial carousel image (the active one), but as soon ...

What is the best way to highlight rows for expansion in a primeng table?

Currently, I am experimenting with primeng table row expansion by following this specific example: https://stackblitz.com/edit/github-7gxyuy?file=src/app/app.component.html Despite my efforts to have each expansion row selected individually, I encountered ...

forward various submit buttons to separate pages

I created a form in HTML with multiple choices, and I want each choice to redirect the user to a different page once clicked. Can anyone advise me on how to achieve this? I am coding in PHP. echo "<form action='home.php' method='po ...

A step-by-step guide on dynamically binding products in a snippet carousel using Angular4

Currently, I am developing a dynamic snippet carousel for products in an Angular4 application. The challenge is to generate the products dynamically instead of having static ones. This requires receiving product data as a JSON response and using it to popu ...

Experience the distinct features of Visual Studio Code as it presents "Launch with Live Server" and "Launch with Default Browser" displaying diverse web pages on each option

Recently, I was working on an HTML file in Visual Studio Code using Live Server. However, to my surprise, when I opened the file in Chrome, all the elements seemed to be enlarged. It was weird because the dimensions of the elements were not displaying cons ...

How can I eliminate the spacing in CSS?

Seeking assistance to eliminate the extra space above the navbar. Can someone guide me through this? Here is my HTML code for reference: And here is my CSS code: ...

Creating a Stylish ExtJS Container with CSS: A Step-By-Step

I've been experimenting with the ExtJS properties cls, bodyCls, and componentCls but unfortunately, I'm not achieving the desired outcome. As an illustration: Ext.create('Ext.form.Panel', { renderTo: document.body, title: &apo ...

What is the best way to customize the color of a bootstrap badge?

I'm trying to customize a bootstrap badge with a different color. As I am relatively new to frontend development, I may be asking a basic question, but I created the following CSS: .badge .badge-danger{ color:#FFFFFF; } I then added the new CSS af ...

Create a shape using a series of points without allowing any overlap between the lines

JS fiddle There is an array of coordinates that gets populated by mouse clicks on a canvas. var pointsArray = []; Each mouse click pushes x and y values into this array using a click event. pointsArray.push({x: xVal, y: yVal}); The script iterates thr ...

How to send PHP email using HTML form

After attempting to find an answer to my inquiry here, I am now starting a new thread. Just a brief explanation: I have a Contact Form with 180 input fields and calculations for each field. I wish to send all the fields along with the calculated values v ...

The conversion of a 2D json array into a string is mistakenly performed

On hand is an outer array that contains 2 arrays within it, making it a 2-dimensional array. This is how the array is initialized: $outerArray = array(); $nestedArray = array("first", "second", "third", "fourth"); $outerArray[] = $nestedArray; $nest ...

Unusual display of footer controlled by CSS in certain template pages

I recently made changes to the footer on a template-based website. I noticed that, for some unknown reason, the footer is not appearing at the bottom of the page as it should be. I wonder if the footer functionality is faulty altogether and if I only got ...

Populate a secondary dropdown menu using the selection from a primary dropdown menu and retrieve the corresponding "value" instead of displaying the value as a dropdown option

I am attempting to create two dropdowns that are populated by another dropdown. Below is the code: HTML: <form type=get action="action.php"> <select name="meal" id="meal" onChange="changecat(this.value);"> <option value="" disabled select ...

Selenium Webdriver is encountering an issue where the tooltip text for the SVG image is not being retrieved

<span id="tooltip" class="tooltip"> <svg class="svg-inline--fa fa-question-circle fa-w-16" data-fa-transform="grow-6" aria-hidden="true" focusable="false" data-prefix="fas" data ...

Switching from a click event to a hover event in JavaScript

I've been experimenting with animating a burger bar on hover and came across an example online that I managed to adapt for mouseenter functionality. However, I'm struggling to make it revert back to the burger bar shape once the mouse leaves on m ...

I am encountering challenges in ensuring that my code is adaptable to smaller screen sizes

https://i.sstatic.net/5WtRR.jpg https://i.sstatic.net/1eV0M.png I'm working on ensuring that my code is responsive, so that the layout adapts well to smaller screens, maintaining the same side-by-side display of times and days as on larger screens. ...

Creating an interactive drop-down menu in HTML populated with data from an Excel or Access

I have just started my programming journey and am slowly getting the hang of it. I feel comfortable with HTML, CSS, and have a basic grasp of Javascript. Currently, I am working on creating a website to streamline our order processing system. The website ...