raimond raimond - 1 month ago 5
CSS Question

How to change width of an element without using media queries?

I have a page with a bunch of paragraphs, which look too stretched out on large screens. So I set width: 600px to p. Which made it look nice.

Only problem is that on small screens the paragraphs are still at 600px.

Any way to go around this without messing around with media queries?

In short I want .p to have width:600px; on large screens and no width setting on smaller than 600px.

Answer

You can usemax-width like snippet below:

div {
    width:100%;
    max-width:400px;
  }
<div>I have a page with a bunch of paragraphs, which look too stretched out on large screens. So I set width: 600px to p. Which made it look nice.</div>

Comments