Hide the text and display only the icon within the @media query for a minimum width of 768px

On my website, I have a tab menu that is causing unexpected behavior when resizing the page. My goal is to only display the font awesome icon without the text when the device width is equal to or below 768px.

This is how the current menu looks like:

<div>
          <div class="d-flex flex-row text-white align-items-stretch text-center">
            <div class="port-item p-4 bg-primary" data-toggle="collapse" data-target="#home">
              <i class="fa fa-home d-block"></i> Home
            </div>
            <div class="port-item p-4 bg-success" data-toggle="collapse" data-target="#resume">
              <i class="fa fa-graduation-cap d-block"></i> Resume
            </div>
            <div class="port-item p-4 bg-warning" data-toggle="collapse" data-target="#portfolio">
              <i class="fa fa-folder-open d-block"></i> Portfolio
            </div>
            <div class="port-item p-4 bg-danger" data-toggle="collapse" data-target="#contact">
              <i class="fa fa-envelope d-block"></i> Contact
            </div>
          </div>
        </div>

I want to hide the text "Home", "Contact", "Resume", and "Portfolio" when the device width is @media(min-width:768px).

Here is my current @media query:

   @media (max-width: 768px) {
  #main-header .port-item {
    width: 25%;
  }

  #main-header .port-item .fa {
    font-size: 1em;
  }

  .map-responsive {
    margin-top: 15px;
  }
}

A visual reference of what I am trying to achieve can be seen in this image:

https://i.sstatic.net/JHY8A.png

Answer №1

Wrap your text in a span tag and hide it using the display: none property within a media query, like @media (max-width: 768px).

This is how your HTML code should look:

<div>
  <div class="d-flex flex-row text-white align-items-stretch text-center">
    <div class="port-item p-4 bg-primary" data-toggle="collapse" data-target="#home">
      <i class="fa fa-home d-block"></i> <span class="item-label">Home</span>
    </div>
    <div class="port-item p-4 bg-success" data-toggle="collapse" data-target="#resume">
      <i class="fa fa-graduation-cap d-block"></i> <span class="item-label">Resume</span>
    </div>
    <div class="port-item p-4 bg-warning" data-toggle="collapse" data-target="#portfolio">
      <i class="fa fa-folder-open d-block"></i> <span class="item-label">Portfolio</span>
     </div>
     <div class="port-item p-4 bg-danger" data-toggle="collapse" data-target="#contact">
       <i class="fa fa-envelope d-block"></i> <span class="item-label">Contact</span>
     </div>
  </div>
</div>

And here is the CSS code for the media query:

@media (max-width: 768px) {
  #main-header .port-item {
    width: 25%;
  }
  #main-header .port-item .fa {
    font-size: 1em;
  }
  .map-responsive {
    margin-top: 15px;
  }
  #main-header .port-item .item-label {
    display: none;
  }
}

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

Positioning a div around a multi-layered canvas for a centered effect

I am looking to create a unique HTML5 canvas setup where multiple canvases are stacked on top of each other to allow for rendering with different layers using JavaScript. The challenge is to have these canvases centered both horizontally and vertically on ...

Enhancing the appearance of page navigation

In my WordPress theme, I have set up a pagination at the bottom of search results using the following code: function custom_pagination($pages = '', $range = 2) { $showitems = ($range * 2)+1; global $paged; if(empty($paged)) $paged = ...

"Customized Bootstrap button featuring a tooltip and modal, experiencing incorrect padding within the button group design

I encountered an issue with a button-group containing 2 buttons, each with a tooltip and a modal. Bootstrap recommends wrapping the buttons with spans to manage two "data-bs-toggle" attributes, which is what I initially did. While the functionality works ...

How can we handle the selection event in ng-bootstrap's NgbTypeahead component?

By utilizing the typeahead feature, a user has the ability to choose a term from a provided list (Documentation, plnkr). I have successfully implemented a way to respond to enter key presses by adding a (keyup.enter) event to the input element and then in ...

Tips on showcasing lengthy string content from JSON in a structured list format using react with typescript

Is there a way to display long string data from a JSON file in a list format when the description string is too lengthy? How can I split or format the description using React and TypeScript? The JSON data I have is as follows: "options": [ ...

How to perfectly center a background image using CSS

I am currently working on a project that involves using a background image. However, I am facing some difficulties in trying to fully center the image, similar to what is shown in this My objective is https://i.sstatic.net/XUNTy.png What I have achieved s ...

Looking for assistance with CSS to properly align a dozen items

UPDATE: See the current layout in this JFiddle based on feedback received from others, still a few tweaks needed. In my setup, there are 12 divs housed within one container div. These 12 divs consist of 6 text components and 6 corresponding input fields. ...

Content obscured by a div element

I've created a cloud using HTML/CSS and I'm struggling to position some text in the center of it. Unfortunately, I can't get it to overlap the cloud divs properly. #cloud { height: 230px; margin: 40px; position: relative; ...

What are the steps to achieve a double-layered border that is inverted?

Can a unique scoop border style be created using CSS or jQuery? Similar to the design in the image below: ...

Achieve full height for div without causing it to expand (utilize scrollbar for overflow)

I am looking to achieve a specific layout for my webpage, as shown in the image below: The layout depicted in the image above is created using the following HTML and bootstrap classes: <div className="ContentWrapper d-flex mh-100 flex-row h-10 ...

The iconbar feature in the mobile menu is experiencing functionality issues

I am currently experimenting with the iconbar property of mmenu (here: ) Unfortunately, I am encountering an issue. The menu opens as expected when I run the code. However, upon closing the menu, it first closes completely and then the container slides sl ...

Angular implementing a carousel feature using the ngFor directive

Currently, I am working on implementing a carousel feature. The images in the carousel are sourced from a string array and I want to be able to cycle through them when clicking on the left or right arrows. How can I achieve this functionality using only ...

What causes delays in transition for 'margin' and 'padding' in webkit browsers?

I attempted to use CSS transition effects on the margin and padding properties. The goal was to create an illusion of a larger background upon hovering. To achieve this, I increased the padding and decreased the margin correspondingly on hover, ensuring t ...

Having trouble getting a resizable DIV inside a 100% height DIV with margin to work properly. Any tips or assistance would be greatly

I've encountered a common issue that is slightly different from others I've come across. Despite my best efforts, I have been unable to find a solution on my own. If anyone could offer me some guidance on this, I would greatly appreciate it. The ...

Is there a tree component available in the bootstrap framework?

Struggling to find a suitable tree component for building a tree in my Angular 12 and Bootstrap 4 project (ng-bootstrap@10). While aware of ngx-treeview, I am not satisfied with it and seems like it has not been updated or supported for quite some time. ...

Designing a Scrollable tbody Element while Preserving the Integrity of the tbody Columns

Currently, I am attempting to implement a scrollable tbody in order to run a React package smoothly. The challenge lies in achieving a scrollable tbody without having to resort to using display: block on the tbody element. Unfortunately, this solution dis ...

Displaying an image extracted from a database as a blob data type on a fresh PHP page

I have created a code that successfully retrieves an image from a database. However, I am facing a challenge with opening the image on a new page when the user clicks on it. I have attempted a few solutions but have been unsuccessful... Below is the code ...

setting the width of <input> fields to automatically adjust

Curious about CSS. I was under the impression that setting width:auto for a display:block element would make it 'fill available space'. However, when applied to an <input> element, this doesn't seem to hold true. For instance: <b ...

Align the content to the center

Currently, I am in the process of creating a profile card view and utilizing Bootstrap to achieve this. I have set up two div elements - one with the class col-lg-3 and the other with col-lg-9. However, I am facing an issue where the content within col-lg ...

The upper spacing is malfunctioning

Why is my margin-top not working when margin-left is functioning as expected? p.ex1 { margin-top: 15px; margin-left: 35px; } <div class="footer2"> <p class="ex1"> ABOUT US </p> <hr> <div class="footer"> &l ...