Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change actual text (easily?) based on screen width?

I'm setting up an off-the-shelf shopping cart with a responsive design template. I have a section that is horizontally oriented with larger viewports and vertically oriented with smaller devices. I want to use copy that says "see to the right for [whatever]"... but on a smaller device, it isn't "to the right" but rather underneath. So I'd like to make it dynamically say "see below" when the viewport changes.

Possible? And simple? I don't want a mess of code that myself or other furture admin are going to have to adjust if they want to reword it. But if it can be done with a simple or whatever with all the code contained in css then that's fine.

Otherwise I'll accept "no" if that's the better answer.

like image 283
bcsteeve Avatar asked Jul 15 '15 07:07

bcsteeve


People also ask

How do I change the text size on my screen?

To change your display in Windows, select Start > Settings > Accessibility > Text size. To make only the text on your screen larger, adjust the slider next to Text size. To make everything larger, including images and apps, select Display , and then choose an option from the drop-down menu next to Scale.

How do you change the width of text in HTML?

In HTML, you can use the width attribute to set the width of an element. Alternatively, you can also use the size attribute to define the width of the <input> .

How do you change the width and height of text in HTML?

In HTML, you can change the size of text with the <font> tag using the size attribute. The size attribute specifies how large a font will be displayed in either relative or absolute terms. Close the <font> tag with </font> to return to a normal text size.


2 Answers

You can do this using media query and the following approach.

Declare two spans having the desired data, one for large screens and other for smaller ones:

<span class="lg-view">See to the right</span>
<span class="sm-view">See below</span>

In css, display the lg-view span by default and hide the other one:

.lg-view{
   display:inline-block;
}

.sm-view{
   display:none;
}

Then inside media query, reverse the above styles:

@media screen and (max-width: 500px) {
    .lg-view{
       display:none;
    }

    .sm-view{
       display:inline-block;
    }
}
like image 154
Nikhil Batra Avatar answered Sep 20 '22 15:09

Nikhil Batra


One way would be to use pseudo elements and media queries. You could do something like this:

HTML:

<div><!-- empty by design --></div>

CSS:

@media screen and (max-width: 300px) {
  div:before {
    content: "see below for [whatever]";
  }
}

@media screen and (min-width: 301px) {
  div:before {
    content: "see to the right for [whatever]";
  }
}

Obviously this is just a bare bones markup, but with a bit of tweaking it should do exactly what you want.

like image 36
David Mann Avatar answered Sep 21 '22 15:09

David Mann