Creating responsive text styles in CSS

I'm encountering an issue with a button that says Upgrade my account.

My goal is to have different text for screens smaller than 990px, where it should display just Upgrade due to length constraints.

Is there a CSS solution to achieve this without having both versions in the HTML and using display: none?

I attempted to resolve it with:

@media(max-width: 990px) {
    .navbar-btn {
      content: 'Upgrade'
    }
}

Unfortunately, this approach did not produce the desired outcome...

Any assistance would be greatly appreciated!

Answer №1

One way to handle responsive design is by using the span element and toggling its visibility based on screen size:

Here's an example in HTML:

<button class='navbar-btn'>
    Upgrade<span> my Account</span>
</button>

And here's how you can achieve this with CSS:

@media(max-width: 990px) {
    .navbar-btn span {
        display:none;
    }
}

For a live demonstration, check out this JSFiddle link.

Answer №2

Assume your HTML looks like this:

<div class="menu">
    <span>Order Now</span>
</div>

A possible media query for this can be:

@media(max-width: 990px) {
    .menu:before {
      content: 'Order'
    }
    .menu > span {display:none;}
}

View Example

Answer №3

Check it out

JS Fiddle Link

The content property is specifically for the :before and :after pseudo elements in CSS. It involves inserting text content directly within your CSS, which may not always be the best practice.

Here's an example in HTML:

<div class='navbar-btn'></div>

And here's how you can style it with CSS:

.navbar-btn {
    position:relative;
}
.navbar-btn:after {
    position:absolute;
    left:0;
    content:'Upgrade my Account';
}
@media(max-width: 990px) {
    .navbar-btn:after {
        content:'Upgrade';
    }
}

Answer №4

If you're looking for a way to enhance your navbar button, I recommend trying out the approach showcased in this demo

Including the following CSS:

@media(min-width: 990px) {
  .navbar-btn:after {
    content: ' account'
  }
}

And adding the corresponding HTML:

<button class='navbar-btn'>Upgrade</button>    

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

How can jQuery be used to adjust the width and height of an iframe?

After researching a solution on a website, I attempted to implement it but encountered issues. It seems like there may be another script dictating the styling, so I need to add some code directly to the page to override it. This is what I tried: <scri ...

Switch back to default text style in case web fonts are taking too long to load?

Currently implementing Google web fonts in this manner: @font-face { font-family: "Vollkorn"; font-style: normal; font-weight: normal; src: local('Vollkorn Regular'), local('Vollkorn-Regular'), url('http://themes.googleuse ...

Tips for making a sidebar sticky when scrolling

In order to keep the right-side bar fixed, I have implemented this javaScript function: <script type="text/javascript> $(document).ready(function () { var top = $('#rightsidebar-wrapper').offset().top - parseFloat($('#rightsideb ...

Preventing Flash of Unstyled Content in ElectronJS Browser Windows

Upon creating a new BrowserWindow and utilizing loadURL to incorporate an html file within the renderer, there is a brief instance where unstyled content is displayed for approximately half a second before the css is loaded. window.loadURL('file://&a ...

`vertical navigation on the left side with expanding submenus`

Trying to create a navigation system on the left side of the page with submenus appearing on the right without impacting the main content. If anyone has any code snippets or resources that can help achieve this, I would really appreciate it. The objectiv ...

What is the best way to differentiate the behavior of two identical classes using a single JavaScript function?

Can someone help me figure out how to make two circles move differently with the same JavaScript function? I'm new to JavaScript and struggling to differentiate between classes in HTML to achieve this. My goal is to have each circle move randomly and ...

Adjust the active carousel item to 0 within onsen-ui (displaying a list of carousel items in a sliding menu)

In my sliding menu, each menu item contains a carousel with two items. I am trying to make the first carousel item show after closing and reopening the menu, or by clicking a button outside of the list on the menu page. This is my current setup: <ons- ...

Arranging elements in a Material-UI card in a horizontal layout

I am currently working on designing a user profile display. I want to create a card layout that showcases the details listed below. My goal is to have these items displayed side by side instead of being divided as shown in the image. Despite trying to giv ...

How can I change the cursor of a button to a pointer in Bootstrap 4 when the button is not disabled?

I'm working with a bootstrap button <button class="btn btn-primary">Login</button> My goal is to change the cursor to a pointer (hand) on this button when it's not disabled, instead of the default arrow. The disabled property of th ...

How to position radio buttons in line with labels containing inline inputs using Vue and Bootstrap

Currently, I am facing an issue with my form containing a radio button group where one of the radio button labels includes another numerical input. The layout is not aligned correctly, and I am struggling to adjust the spacing using CSS. I am unable to gr ...

Insert content into a designated DIV

Progress bars are essential for tracking certain metrics. Take a look at the progress bars below: <div id="lifeBar-holder"> <div id="lifeBar"></div> </div> <div id="discretionBar-holder"> <div id="discretionBar"&g ...

Is it possible to have an icon change color in a TableRow column when hovering over any part of that particular row?

I am currently using material-ui version 4.9.5. To illustrate my issue, I have created a simplified example here. I have a Table that is populated with basic JSON data. Each row in the table consists of an icon element along with its corresponding color a ...

How come the overlay only appears the first time the button is clicked in JQUERY? What could be the issue here?

Why is my purple overlay with yellow text showing only once after the button is clicked, even though I have toggled the function? Check out my codepen to test the issue: https://codepen.io/cat999/project/editor/AEeEdg $('.animate-this').cl ...

I am struggling to assign the height style attribute to a div element

I have created the code below where I am attempting to set a div to 'display: flex' and include two divisions, one with a width of 200px and the other with a width of 100%. <div style="clear:both;display:flex; height: 100%;"> <div ...

Showcasing text behind an element with reduced opacity when the element directly above it is selected using rails, CSS, and jQuery

I have a password field on my page where the password is hidden, but I want users to be able to copy and paste the clear text version of the password on another website. In order to achieve this, I followed the instructions in an article titled Mask text, ...

Exploring the origins of CSS through patch design

Want to learn how to create a background like this using CSS? Check out this link for inspiration! ...

What is the procedure to reduce my final search result by 1?

When the search is triggered, I want to filter the images by name. However, the issue arises when trying to make everything disappear on filter addition. <ul id="list2"> <li class="in2"> An extra number is added ...

Updating the CSS class for a particular text segment enclosed in a <p> or <span> element

My <p> tag is set to contain several lines of text with a specific CSS class, but I am looking to modify the text format within certain parts of the paragraph. In the past, I would achieve this using the <font> tag, however it seems that HTML5 ...

Issue encountered while trying to display images next to each other using only HTML and CSS

https://i.sstatic.net/OAjCG.jpg I am facing an issue with the vertical space between the top and bottom rows of my portfolio. There seems to be some unwanted space in the rows that I cannot account for. It doesn't seem to be a margin or padding withi ...

Trouble with setting the color attribute using setProperty in a GXT text area

Help needed in dynamically changing the font color of a text area from the color menu. Existing attempts to change it have not been successful. Can someone provide assistance? final ColorMenu fontColorMenu = new ColorMenu(); fontColorMenu.getPalette().a ...