Positioning for quick response

I know a decent amount of HTML, CSS, jQuery and PHP. But when it comes to creating a responsive web page, I'm really new to this. So basically on my main web page called "colors.html" I have 4 divs. 4 colors - yellow, blue, red and green. Therefore, understanding what a sensitive web page should be, I did all my positioning, heights and widths in%. All my positioning is placed in the body, which is relative, and all the elements inside it are absolute. It seems to work fine, and I set the minimum width for all divs, so that when the user resizes the browser window, it doesn't all cross. Am I doing it right or is there a better way to do this?

<!doctype html>
<html>
<head>
    <title> Test </title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link type="text/css" rel="stylesheet" href="colors.css">
</head>

<body> 
    <div id="red"></div>
    <div id="green"></div>
    <div id="blue"></div>
    <div id="yellow"></div>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">    </script>
        <script>    
            $('#red').click(function() {
                alert('Red');
            })

            $('#green').click(function() {
                alert('Green');
            })

            $('#blue').click(function() {
                alert('Blue');
            })

            $('#yellow').click(function() {
                alert('Yellow');
            })
        </script>
</body>
</html>

body {
margin: 0;
position: relative;
}

#blue {
position: absolute;
width: 20%;
height: 10%;
background-color: blue;
color: white;
text-align: center;
font-size: 150%;
font-family: Roboto;
cursor: pointer;
border-radius: 5px;
left: 3%;
top: 5%;
min-width: 150px;
}

#yellow {
position: absolute;
width: 20%;
height: 10%;
background-color: yellow;
color: white;
text-align: center;
font-size: 150%;
font-family: Roboto;
cursor: pointer;
border-radius: 5px;
left: 3%;
top: 20%;
min-width: 150px;
}

#red {
position: absolute;
width: 20%;
height: 10%;
background-color: red;
color: white;
text-align: center;
font-size: 150%;
font-family: Roboto;
cursor: pointer;
border-radius: 5px;
right: 3%;
top: 5%;
min-width: 150px;
}

#green {
position: absolute;
width: 20%;
height: 10%;
background-color: green;
color: white;
text-align: center;
font-size: 150%;
font-family: Roboto;
cursor: pointer;
border-radius: 5px;
right: 3%;
top: 20%;
min-width: 150px;
}
+4
2

, ... , . u...

:

.css , , . responsive.css (div, ul, li ..)... ur html ...

, :

#blue {
position: absolute;
width: 20%;
height: 10%;
background-color: blue;
color: white;
text-align: center;
font-size: 150%;
font-family: Roboto;
cursor: pointer;
border-radius: 5px;
left: 3%;
top: 5%;
min-width: 150px;
}
Hide result

Media Rule :

@media screen and (max-width: 699px) and (min-width: 520px) {
  #blue {
    position: absolute;
    width: 20%;
    height: 10%;
    background-color: blue;
    color: white;
    text-align: center;
    font-size: 150%;
    font-family: Roboto;
    cursor: pointer;
    border-radius: 5px;
    left: 3%;
    top: 5%;
    min-width: 150px;
  }
  
  #red {
  }
  
  .div {
  }
  
}

@media screen and (max-width: 1000px) and (min-width: 700px) {
}
Hide result

... dor a desctop, table, phone screen.

@media screen and (max-width: 1680px){
}

@media screen and (max-width: 1600px) {
}

@media screen and (max-width: 1440px) {
}

@media screen and (max-width: 1400px) {
}

@media screen and (max-width: 1366px) {
}

@media screen and (max-width: 1360px) {
}

@media screen and (max-width: 1280px) {
}

@media screen and (max-width: 1152px) {
}

@media screen and (max-width: 1024px) {
}
Hide result
480 . , .

, :)

+1

, , , position: absolute . . , , , , -.

, , . !

, CSS. , : ?:

  • , 1 ( > 75em)
  • : , (62em > 74.9em)
  • : / (48em > 61.9em)
  • , (34em > 47.9em)
  • ( 33.9)

, , , :

( ):

// CSS for very large screens

@media (max-height: 74.9em) {
    // CSS overrides for large screens
}

@media (max-height: 61.9em) {
    // CSS overrides for medium screens
}

@media (max-height: 47.9em) {
    // CSS overrides for small screens
}

@media (max-height: 33.9em) {
    // CSS overrides for very small screens
}

- . , , , , , divs.

.color {
    position: absolute;
    width: 20%;
    color: white;
    text-align: center;
    font-size: 150%;
    font-family: Roboto, sans-serif;
    cursor: pointer;
    border-radius: 5px;
    min-width: 150px;
}

#{color} {...} div.

, font-family, Roboto, , , .

@import url(https://fonts.googleapis.com/css?family=Roboto);

font-family, , .

, , , - : CSS , , 3 , .

!

!

+1

Source: https://habr.com/ru/post/1618973/


All Articles