Prevent using the same image multiple times for various screen resolutions in Bootstrap 4

Greetings! I currently have a functional website where the logo is displayed twice, each with different classes for various resolutions

<a class="navbar-brand" href="/">
<img class="d-none d-sm-block" width="279" height="70" src="logo.png">
<img class="d-block d-sm-none" width="232" height="58" src="logo.png">
#</a>

While this setup serves its purpose, it appears cluttered. I have been tasked with eliminating the duplicate image. Is there a way to achieve this in a single line of code?

Answer №1

To achieve this, utilizing CSS media queries is necessary, however it cannot be achieved inline.

.navbar-img {
  width: 232px;
  height: 58px;
}

@media screen and (min-width: 767px) {
  .navbar-img {
    width: 279px;
    height: 70px;
  }
}
<a class="navbar-brand" href="/">
  <img class="navbar-img" src="http://lorempixel.com/400/200/cats">
</a>

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 horizontally aligning an item in a flexbox only when it wraps onto a new line

In my layout, I have a container that consists of text on the left and a button on the right. The challenge I'm facing is ensuring proper alignment when they are on the same line versus when the button wraps to a new line on smaller screens. Ideally, ...

Instructions on utilizing *ngFor for every category I have

Seeking assistance with a specific issue. I currently have four labeled tabs, each containing projects. My goal is to ensure that when I save a project, it remains in the same tab where I initiated the save operation, rather than appearing across all tabs. ...

Discovering the window scroll unit when clicking, as a page smoothly transitions to the top for a specified target position

Is there a way to achieve parallax scrolling on window scroll and navigation click simultaneously? When navigating and animating the page to the top to show the target, I also want to get the window scroll unit. How can I obtain the window scroll unit on ...

OpenWeatherMap API call failing - not visible in Network tab of Console

I am facing an issue with my API call while trying to retrieve temperature data for a specific city. I am unsure if the problem lies with my API key or the code itself. Can you please provide guidance on how I can resolve this issue? Upon entering the city ...

Which specific CSS rule is responsible for the issue I am currently experiencing?

I have styled a left-hand border on items in a list, with the border-left-color set to transparent for all of them. The active item, marked by the css class "active day", has a specific color for its border. Below is a snippet of the code (certain styles h ...

Guide on incorporating Bootstrap JS into HTML5 reusable web elements

RESOLVED: the solution is in a comment TL;DR: Issues triggering Bootstrap's JS, likely due to incorrect import of JS scripts I've been working on integrating Bootstrap with my custom reusable web components across all pages. Specifically, I&apo ...

How can you activate color printing in CSS when using ng-style in AngularJS?

My application generates data in a table, where each cell has a unique combination of background color and text color determined by its properties. The code to achieve this is simple: ng-style='{"background-color": lt.backgroundColor, "color": lt.te ...

Borders appear to be missing in the card-like div layout

Despite using the same color for the outer border and inner borders, I am having trouble getting the inner borders to show up. Can anyone provide guidance on how to display both the inside and outside borders? Note: I have attempted changing the color, bu ...

Trouble keeping HTML/Javascript/CSS Collapsible Menu closed after refreshing the page

My issue is that the collapsible menu I have created does not remain closed when the page is refreshed. Upon reloading the page, the collapsible menu is always fully expanded, even if it was collapsed before the refresh. This creates a problem as there is ...

Tips for utilizing the data-target feature in Bootstrap?

<button id="btn-id" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#bs-navbar-collapse-1"> <span class="navbar-toggler-icon"></span> <span c ...

Is misbehavior expected at approximately 600 pixels in width?

What is happening with my website when the width is minimized, and how can I resolve it? Issue The website appears fine on mobile devices and full screens, but at reduced sizes, the background image disappears and the top bar behaves strangely (with the l ...

Tips for distinguishing individual rows within a table that includes rowspans?

My Vue application calculates a table with rowspans by using an algorithm based on a configuration file. This allows the application to render columns (and maintain their order) dynamically, depending on the calculated result. For example, see the code sn ...

Bootstrap 4 custom dropdown menu

Looking to revamp the design of my dropdown menu, but struggling to achieve the desired outcome. My goal is to have the drop-down menu match the size of its container. (refer to screenshot below) I've attempted various modifications to the dropdown- ...

What is the best way to keep a <div> class anchored to the bottom of an HTML page?

I am looking to incorporate a footer into my website that stays fixed at the bottom of the screen. However, I have encountered an issue: Here is what I have attempted so far: .footer { position: absolute; width: 100%; background: #0084FF; ...

The proper way of aligning text in the middle of a button

I'm currently working on designing a CSS button that will be placed in the top left corner and serve as a back button to the previous page. However, I am facing challenges when it comes to centering the arrow or text perfectly in the middle of the but ...

What is the process for adjusting row height in FullCalendar?

This is my control panel. $calendar = Calendar::addEvents($events) ->setOptions([ //set fullcalendar options 'firstDay' => 1, 'height' => '200px', 'themeSystem' => &ap ...

Tips for activating a dropdown in Bootstrap 4

I am currently working on a dropdown menu where I want to set an active state upon a click. The active class is added successfully when a link is clicked, but the issue arises when trying to remove the active class when another link is clicked. I only want ...

CSS: elements that are only visible when positioned above specific elements

Can we create an element that is only visible above specific other elements? For instance, in the following code snippet, I want the .reflection element to be visible only above the .reflective elements (located at the top and bottom) and not visible on t ...

The CSS in Django seems to be malfunctioning on various pages, particularly on header elements

My CSS file is linked in 'main/static/css/style.css' and my pages are located in 'main/templates/main/pages.html'. However, the CSS does not seem to be working properly for some pages; for example, the h2 tag is not taking on the specif ...

Using Slick Slider and Bootstrap CSS to display text on top of images

Currently, I am utilizing the slick slider from and I want to overlay text on top of the image. I tried using bootstrap carousel-caption, which works well with any image. However, with slick slider, it seems like the text is not at the highest level as I ...