skip to Main Content

Can I set min-width and max-width at the same time? Is this acceptable?
It is for my task for course but I don’t know that is this okay projects.I didn’t try it.

I don’t know that is this okay for real projects? Like is this okay for developers?

2

Answers


  1. Yes, it is perfectly acceptable to set both min-width and max-width properties on an element in CSS. In fact, it’s a common practice in web development, especially for creating responsive layouts.

    .container {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    
    .box {
      padding: 20px;
      background-color: lightblue;
      border: 2px solid blue;
      min-width: 200px;
      max-width: 400px;
    }
     <div class="container">
        <div class="box">
          This is a box with min-width and max-width.
        </div>
      </div>

    In this example, we have a .box element within a .container. The .box element has a minimum width of 200px and a maximum width of 400px.

    for more best concept vist MDN Web Docs: max width …… min width

    Login or Signup to reply.
  2. Yes, you can set both. This is usually used in responsive design so the content works both in small devices such as smartphones and big screen devices such as desktops, I really don’t see a problem.

    Take a look at the w3schools explanations:
    max-width
    min-width

    See this question if you want to learn more about their use in media queries.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search