I'm trying to represent this structure horizontaly, but I'm having some issues on what should I change so that this can work properly. What I hope to achieve is that those small squares in the bottom appear the same, only verticaly, on top of each other, while the bigger square keeps it's model.
.date-grid {
width: 120px;
height: 100px;
display: flex;
flex-direction: column;
}
.node {
width: 100%;
height: 100%;
background: #e9ecef;
border: none;
padding: 0;
}
time {
display: block;
height: 75%;
font-size: 24px;
display: flex;
flex-direction: column;
justify-content: center;
}
.smallHolder {
width: 100%;
height: 25%;
display: flex;
}
.smallHolder>div {
width: 25%;
height: 100%;
flex-shrink: 0;
flex-grow: 1;
}
.next { background: #0060df; }
.last { background: #d53343; }
<div class="date-grid">
<button class="node">
<time>3</time>
<div class="smallHolder">
<div class="next"></div>
<div class="last"></div>
</div>
</button>
</div>
Is this the sort of thing you're looking for? grid is great for this sort of thing.
.date-grid {
height: 100px;
display: grid;
grid-template-columns: 120px 25px;
grid-template-rows: 1fr 1fr;
grid-template-areas: "gray next" "gray last";
padding: 0;
border-style: none;
}
.gray {
grid-area: gray;
display: grid;
place-content: center;
background: #e9ecef;
}
time {
font-size: 24px;
}
.next {
grid-area: next;
background: #0060df;
}
.last {
grid-area: last;
background: #d53343;
}
<button class="node date-grid">
<time class='gray'>3</time>
<div class="next"></div>
<div class="last"></div>
</button>
Related
Here is the JSfiddle complete code link:
CODE
my clock code output
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
font-size: 28px;
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
Can any one tell me how to improve this code
I tried to make is completely responsive but it is not not working,
I tired to use flex to make the element appear in center of page.
Then I use grid to create the clock layout and i didn't knew how to align the cells so I used grid again in them. I was using rem and em to make responsive code but it didn't work out well. please review my code.
This is because of the font-size of the time-box div that is not responsive (28px whatever the device size), To make it responsive I added media queries to change the font depending on the device width, As presented in this example:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
}
#media (min-width:768px) {
.time-box {
font-size: 18px;
}
}
#media (min-width:1024px) {
.time-box {
font-size: 22px;
}
}
#media (min-width:1280px) {
.time-box {
font-size: 28px;
}
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
You can as well use calc() function, so you can calculate your font size relative to the screen width like this:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: #0b172a;
font-family: sans-serif;
}
#container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 5rem;
color: white;
text-transform: uppercase;
}
.clock-ctr {
position: relative;
border: 2px solid white;
height: 80vh;
width: 80vw;
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.hour-ctr {
grid-area: hour;
}
.min-ctr {
grid-area: min;
}
.sec-ctr {
grid-area: sec;
}
.ampm {
grid-area: ampm;
background: #bc4123;
}
.time-ctr {
position: absolute;
height: 70%;
width: 90%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
gap: 10px;
grid-template-areas: "hour min sec" "ampm ampm ampm";
}
h1 {
margin-bottom: 1rem;
letter-spacing: 8px;
font-size: 2.5rem;
}
.time-box {
background: #bc4123;
border-radius: 10px;
display: grid;
justify-items: center;
align-items: center;
height: auto;
text-align: center;
font-weight: bold;
font-size: calc(18px + 0.390625vw);
}
<div id="container">
<h1 class="clock-title">Clock</h1>
<div class="clock-ctr">
<div class="time-ctr">
<div class="hour-ctr time-box">
<p class="hour-value">00</p>
<p class="hour-title">Hour</p>
</div>
<div class="min-ctr time-box">
<p class="min-value">00</p>
<p class="min-title">Minute</p>
</div>
<div class="sec-ctr time-box">
<p class="sec-value">00</p>
<p class="sec-title">Second</p>
</div>
<p class="ampm time-box">AM</p>
</div>
</div>
</div>
the issue with the CSS code in the Stack Overflow question is that the left and right values for the #nav element are set to 0. This causes the element to take up the full width of its parent element, which is likely not the intended behavior.
To fix this issue, you can try setting the left and right values to auto like this:
#nav {
position: fixed;
top: 0;
left: auto;
right: auto;
width: 100%;
height: 60px;
background-color: white;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
z-index: 1000;
}
With this change, the #nav element will no longer take up the full width of its parent element and will instead be positioned at the top of the page with its width set to 100%.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
Locked. Comments on this question have been disabled, but it is still accepting new answers and other interactions. Learn more.
I want to create something similar to this one:
... and have it in flex, so it will rearrange. I don't know why I can't get to rearrange it to the right side (it overlaps on top of the chart). See the below what I have got:
I would like it to be at the right side, and occupy the rest of the window. How can I arrange this with CSS?
In simple terms, I would like to have the green container to the right side, and when making smaller the navigator, and the green container to flex and go under the red container. I am trying to do this, but for some reason it’s not happening.
I dont uderstand why the right container goes to right side of the first column.
Here’s my snippet:
* {
margin: 0px;
padding: 0px;
}
.general {
margin: auto;
display: grid;
margin-top: 0%;
width: 100%;
height: 100%;
background-color: #4f6d7a;
}
.enlaces {
float: center;
display: center;
width: 100%;
height: 100px;
background-color: #166088;
}
.tablas_carpetas {
position:grid;
display: flex;
flex-wrap: wrap;
width: 100%;
height: 300px;
background-color: #DBE9EE;
}
.tablas {
position:left;
grid-template-columns: auto;
display: flex;
flex-wrap: wrap;
flex-direction:column;
order: 1;
background-color: #dfc0c0;
height: 300px;
}
.tablas > div {
display:right;
float:right;
background: #ddd;
line-height: 20px;
height: 20px;
margin: 1px;
text-align: center;
}
.tablas_carpetas > .carpetas {
display:flex;
position:left;
order: 2;
height: 100%;
background-color: green;
}
.anuncios{
float: center;
display: center;
width: 100%;
height: 100px;
background-color: red;
}
.pie{
float: center;
display: center;
width: 100%;
height: 100px;
background-color: black;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#botones").mouseenter(function () {
$("#resto").show();
});
$("#botones").mouseleave(function () {
$("#resto").hide();
});
});
</script>
<div class="general">
<div class="enlaces"></div>
<div class="tablas_carpetas">
<div class="tablas">
<div>AA</div>
<div>AKo</div>
<div>AQo</div>
<div>AJo</div>
<div>ATo</div>
<div>A9o</div>
<div>A8o</div>
<div>A7o</div>
<div>A6o</div>
<div>A5o</div>
<div>A4o</div>
<div>A3o</div>
<div>A2o</div>
<div>AKs</div>
<div>KK</div>
<div>KQo</div>
<div>KJo</div>
<div>KTo</div>
<div>K9o</div>
<div>K8o</div>
<div>K7o</div>
<div>K6o</div>
<div>K5o</div>
<div>K4o</div>
<div>K3o</div>
<div>K2o</div>
<div>AQs</div>
<div>KQs</div>
<div>QQ</div>
<div>QJo</div>
<div>QTo</div>
<div>Q9o</div>
<div>Q8o</div>
<div>Q7o</div>
<div>Q6o</div>
<div>Q5o</div>
<div>Q4o</div>
<div>Q3o</div>
<div>Q2o</div>
<div>AJs</div>
<div>KJs</div>
<div>QJs</div>
<div>JJ</div>
<div>JTo</div>
<div>J9o</div>
<div>J8o</div>
<div>J7o</div>
<div>J6o</div>
<div>J5o</div>
<div>J4o</div>
<div>J3o</div>
<div>J2o</div>
<div>ATs</div>
<div>KTs</div>
<div>QTs</div>
<div>JTs</div>
<div>TT</div>
<div>T9o</div>
<div>T8o</div>
<div>T7o</div>
<div>T6o</div>
<div>T5o</div>
<div>T4o</div>
<div>T3o</div>
<div>T2o</div>
<div>A9s</div>
<div>K9s</div>
<div>Q9s</div>
<div>J9s</div>
<div>T9s</div>
<div>99</div>
<div>98o</div>
<div>97o</div>
<div>96o</div>
<div>95o</div>
<div>94o</div>
<div>93o</div>
<div>92o</div>
<div>A8s</div>
<div>K8s</div>
<div>Q8s</div>
<div>J8s</div>
<div>T8s</div>
<div>98s</div>
<div>88</div>
<div>87o</div>
<div>86o</div>
<div>85o</div>
<div>84o</div>
<div>83o</div>
<div>82o</div>
<div>A7s</div>
<div>K7s</div>
<div>Q7s</div>
<div>J7s</div>
<div>T7s</div>
<div>97s</div>
<div>87s</div>
<div>77</div>
<div>76o</div>
<div>75o</div>
<div>74o</div>
<div>73o</div>
<div>72o</div>
<div>A6s</div>
<div>K6s</div>
<div>Q6s</div>
<div>J6s</div>
<div>T6s</div>
<div>96s</div>
<div>86s</div>
<div>76s</div>
<div>66</div>
<div>65o</div>
<div>64o</div>
<div>63o</div>
<div>62o</div>
<div>A5s</div>
<div>K5s</div>
<div>Q5s</div>
<div>J5s</div>
<div>T5s</div>
<div>95s</div>
<div>85s</div>
<div>75s</div>
<div>65s</div>
<div>55</div>
<div>54o</div>
<div>53o</div>
<div>52o</div>
<div>A4s</div>
<div>K4s</div>
<div>Q4s</div>
<div>J4s</div>
<div>T4s</div>
<div>94s</div>
<div>84s</div>
<div>74s</div>
<div>64s</div>
<div>54s</div>
<div>44</div>
<div>43o</div>
<div>42o</div>
<div>A3s</div>
<div>K3s</div>
<div>Q3s</div>
<div>J3s</div>
<div>T3s</div>
<div>93s</div>
<div>83s</div>
<div>73s</div>
<div>63s</div>
<div>53s</div>
<div>43s</div>
<div>33</div>
<div>32o</div>
<div>A2s</div>
<div>K2s</div>
<div>Q2s</div>
<div>J2s</div>
<div>T2s</div>
<div>92s</div>
<div>82s</div>
<div>72s</div>
<div>62s</div>
<div>52s</div>
<div>42s</div>
<div>32s</div>
<div>22</div>
</div>
<div class="carpetas">
<div class="botones">
<button id="principal_1">Redes Sociales</button>
<div class="resto" hidden>
<button>Facebook</button>
<button>Twitter</button>
<button>LinkedIn</button>
<button>Gooogle</button>
</div>
</div>
</div>
</div>
<div class="anuncios"></div>
<div class="pie"></div>
</div>
Here is what I changed:
.tablas_carpetas {
display: flex;
width: 100%;
height: 600px;
background-color: #DBE9EE;
}
.tablas {
width: 50%;
gap: 1%;
display: flex;
flex-wrap: wrap;
background-color: #dfc0c0;
height: 100%;
}
.tablas > div {
background: #ddd;
display: flex;
justify-content: center;
align-items: center;
line-height: 20px;
height: 35px;
flex: 0 0 6%;
margin: 1px;
text-align: center;
border-radius: 5px;
}
.tablas_carpetas > .carpetas {
width: 50%;
height: 100%;
background-color: green;
}
Here's a complete snippet:
* {
margin: 0px;
padding: 0px;
}
.general {
margin: auto;
display: grid;
margin-top: 0%;
width: 100%;
height: 100%;
background-color: #4f6d7a;
}
.enlaces {
float: center;
display: center;
width: 100%;
height: 100px;
background-color: #166088;
}
.tablas_carpetas {
position:grid;
display: flex;
flex-wrap: wrap;
width: 100%;
height: 300px;
background-color: #DBE9EE;
}
.tablas {
position:left;
grid-template-columns: auto;
display: flex;
flex-wrap: wrap;
flex-direction:column;
order: 1;
background-color: #dfc0c0;
height: 300px;
}
.tablas > div {
display:right;
float:right;
background: #ddd;
line-height: 20px;
height: 20px;
margin: 1px;
text-align: center;
}
.tablas_carpetas > .carpetas {
display:flex;
position:left;
order: 2;
height: 100%;
background-color: green;
}
.anuncios{
float: center;
display: center;
width: 100%;
height: 100px;
background-color: red;
}
.pie{
float: center;
display: center;
width: 100%;
height: 100px;
background-color: black;
}
.tablas_carpetas {
display: flex;
width: 100%;
height: 600px;
background-color: #DBE9EE;
}
.tablas {
width: 50%;
gap: 1%;
display: flex;
flex-wrap: wrap;
background-color: #dfc0c0;
height: 100%;
}
.tablas > div {
background: #ddd;
display: flex;
justify-content: center;
align-items: center;
line-height: 20px;
height: 30px;
flex: 0 0 7%;
margin: 1px;
text-align: center;
border-radius: 5px;
}
.tablas_carpetas > .carpetas {
width: 50%;
height: 100%;
background-color: green;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$("#botones").mouseenter(function () {
$("#resto").show();
});
$("#botones").mouseleave(function () {
$("#resto").hide();
});
});
</script>
<div class="general">
<div class="enlaces"></div>
<div class="tablas_carpetas">
<div class="tablas">
<div>AA</div>
<div>AKo</div>
<div>AQo</div>
<div>AJo</div>
<div>ATo</div>
<div>A9o</div>
<div>A8o</div>
<div>A7o</div>
<div>A6o</div>
<div>A5o</div>
<div>A4o</div>
<div>A3o</div>
<div>A2o</div>
<div>AKs</div>
<div>KK</div>
<div>KQo</div>
<div>KJo</div>
<div>KTo</div>
<div>K9o</div>
<div>K8o</div>
<div>K7o</div>
<div>K6o</div>
<div>K5o</div>
<div>K4o</div>
<div>K3o</div>
<div>K2o</div>
<div>AQs</div>
<div>KQs</div>
<div>QQ</div>
<div>QJo</div>
<div>QTo</div>
<div>Q9o</div>
<div>Q8o</div>
<div>Q7o</div>
<div>Q6o</div>
<div>Q5o</div>
<div>Q4o</div>
<div>Q3o</div>
<div>Q2o</div>
<div>AJs</div>
<div>KJs</div>
<div>QJs</div>
<div>JJ</div>
<div>JTo</div>
<div>J9o</div>
<div>J8o</div>
<div>J7o</div>
<div>J6o</div>
<div>J5o</div>
<div>J4o</div>
<div>J3o</div>
<div>J2o</div>
<div>ATs</div>
<div>KTs</div>
<div>QTs</div>
<div>JTs</div>
<div>TT</div>
<div>T9o</div>
<div>T8o</div>
<div>T7o</div>
<div>T6o</div>
<div>T5o</div>
<div>T4o</div>
<div>T3o</div>
<div>T2o</div>
<div>A9s</div>
<div>K9s</div>
<div>Q9s</div>
<div>J9s</div>
<div>T9s</div>
<div>99</div>
<div>98o</div>
<div>97o</div>
<div>96o</div>
<div>95o</div>
<div>94o</div>
<div>93o</div>
<div>92o</div>
<div>A8s</div>
<div>K8s</div>
<div>Q8s</div>
<div>J8s</div>
<div>T8s</div>
<div>98s</div>
<div>88</div>
<div>87o</div>
<div>86o</div>
<div>85o</div>
<div>84o</div>
<div>83o</div>
<div>82o</div>
<div>A7s</div>
<div>K7s</div>
<div>Q7s</div>
<div>J7s</div>
<div>T7s</div>
<div>97s</div>
<div>87s</div>
<div>77</div>
<div>76o</div>
<div>75o</div>
<div>74o</div>
<div>73o</div>
<div>72o</div>
<div>A6s</div>
<div>K6s</div>
<div>Q6s</div>
<div>J6s</div>
<div>T6s</div>
<div>96s</div>
<div>86s</div>
<div>76s</div>
<div>66</div>
<div>65o</div>
<div>64o</div>
<div>63o</div>
<div>62o</div>
<div>A5s</div>
<div>K5s</div>
<div>Q5s</div>
<div>J5s</div>
<div>T5s</div>
<div>95s</div>
<div>85s</div>
<div>75s</div>
<div>65s</div>
<div>55</div>
<div>54o</div>
<div>53o</div>
<div>52o</div>
<div>A4s</div>
<div>K4s</div>
<div>Q4s</div>
<div>J4s</div>
<div>T4s</div>
<div>94s</div>
<div>84s</div>
<div>74s</div>
<div>64s</div>
<div>54s</div>
<div>44</div>
<div>43o</div>
<div>42o</div>
<div>A3s</div>
<div>K3s</div>
<div>Q3s</div>
<div>J3s</div>
<div>T3s</div>
<div>93s</div>
<div>83s</div>
<div>73s</div>
<div>63s</div>
<div>53s</div>
<div>43s</div>
<div>33</div>
<div>32o</div>
<div>A2s</div>
<div>K2s</div>
<div>Q2s</div>
<div>J2s</div>
<div>T2s</div>
<div>92s</div>
<div>82s</div>
<div>72s</div>
<div>62s</div>
<div>52s</div>
<div>42s</div>
<div>32s</div>
<div>22</div>
</div>
<div class="carpetas">
<div class="botones">
<button id="principal_1">Redes Sociales</button>
<div class="resto" hidden>
<button>Facebook</button>
<button>Twitter</button>
<button>LinkedIn</button>
<button>Gooogle</button>
</div>
</div>
</div>
</div>
<div class="anuncios"></div>
<div class="pie"></div>
</div>
I hope this helps, the code for you to review in case you have doubts: https://jsfiddle.net/0kqzL6dn/37/
Ok, so during the last weeks I've been trying to understand how html and CSS work, right now I'm struggling trying to make a grid layout. I'm trying to make my web responsive but when I work with percentages the percentages don't seem to apply correctly. For example there's an orange rectangle that's supposed to fit all the width of the screen, but with my code when the screen is pretty small it isn't large enough.
Here's the HTML and CSS (there are different settings depending on the media):
#media screen and (max-width:480px) {
body {
background-color: mediumspringgreen;
display: grid;
grid-template-columns: 100%;
grid-template-rows: 30% 6% 60% 4%;
grid-template-areas: "header" "nav" "main" "footer";
}
header img {
display: block;
align-self: center;
justify-self: center;
max-height: 5%;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.rectangle {
width: 100%;
height: 4%;
background: gold;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
}
.button1 {
background-color: green;
color: gold;
border: 3px solid mediumspringgreen;
border-radius: 12px;
display: inline-block;
cursor: pointer;
}
nav {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
main {
display: grid;
grid-template-columns: 100%;
grid-template-rows: 70% 30%;
grid-template-areas: "imatge" "descripcio";
}
.imatge {
background-color: mediumspringgreen;
display: inline-block;
}
.descripcio {
background: gold;
justify-content: center;
align-items: center;
display: inline-block;
width: 100%;
height: 50%;
}
footer {
display: inline-block;
width: 100%;
align-items: center;
justify-content: center;
}
}
#media screen and (min-width:481px) {
body {
background-color: mediumspringgreen;
display: grid;
grid-template-columns: 100%;
grid-template-rows: 30% 6% 60% 4%;
grid-template-areas: "header" "nav" "main" "footer";
width: 100%;
height: 100%;
}
header img {
display: block;
align-self: center;
justify-self: center;
max-height: 5%;
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
.rectangle {
width: 100%;
height: 4%;
background: gold;
position: absolute;
display: flex;
align-items: center;
justify-content: center;
}
.button1 {
background-color: green;
color: gold;
border: 3px solid mediumspringgreen;
border-radius: 12px;
display: inline-block;
cursor: pointer;
}
nav {
display: flex;
width: 100%;
align-items: center;
justify-content: center;
}
main {
display: grid;
grid-template-columns: 50% 50%;
grid-template-rows: 100%;
grid-template-areas: "imatge descripcio";
}
.imatge {
background-color: mediumspringgreen;
}
.descripcio {
background: gold;
justify-content: center;
align-items: center;
display: flex;
position: absolute;
width: 100%;
height: 50%;
}
footer {
display: inline-block;
width: 100%;
align-items: center;
justify-content: center;
}
span {
color: gold;
}
}
<header style="width: 100%;">
<p style="text-align:center;">
<a href="pàgina%20home.html">
<img src="https://i.imgur.com/BSHMhUe.png" alt="logo">
</a>
</p>
</header>
<nav style="width: 100%;">
<p class="rectangle">
<button class="button1" onclick="location.href='pàgina%20productes.html'">Productes</button>
<span> </span>
<button class="button1" onclick="location.href='pàgina%20contacte.html'">Contacte</button>
</p>
</nav>
<main>
<section style="text-align:center;" class="Imatge">
<h2 style="font-size:150%;">Producte Destacat</h2>
<a href="pàgina%20producte.html">
<p style="text-align:center;">
<img src="https://clubtech.es/wp-content/uploads/2018/12/playstation_4_console_controller_ps4_92842_3840x2160.jpg" alt="Producte destacat" style="width:40%">
</p>
</a>
</section>
<article style="text-align:center;" class="Descripcio">
<p></p>Description</article>
</main>
<footer>
<p style="text-align:center;">
Avís Legal-Privadesa-Termes d'ús
</p>
<p style="text-align:center; font-size:75%;">
Logo vector created by freepik - www.freepik.com
</p>
</footer>
Right now my problems are that elements don't change their size proportionally to the resolutions of the screen, they decrease or increase their size at different speeds. Also, sometimes elements from a grid cell overlap with elements of another cell, like if I leave the header img at 100% it overlaps with the rest of the elements in the html.
JSFiddle: https://jsfiddle.net/915seaLc/
Reset the margin of the body, and I recommend reset the padding to
body {
margin: 0;
padding: 0;
}
I am trying to have 4 little squares inside one big square. Those small squares need to be position at the bottom inside a big square, so far my code looks like this
.date-grid button {
position: relative;
border: 0;
width: 7.5ch;
height: 7.5ch;
background-color: #A1A100;
margin-bottom: 2px;
}
.smallHolder {
display: flex;
align-items: flex-end;
}
.small1 {
border: 0;
width: 2.5ch;
height: 2.5ch;
background-color: gray;
}
.small2 {
width: 2.5ch;
height: 2.5ch;
background-color: red;
}
.small3 {
border: 0;
width: 2.5ch;
height: 2.5ch;
background-color: green;
}
.small4 {
border: 0;
width: 2.5ch;
height: 2.5ch;
background-color: blue;
}
<div class="date-grid">
<button class="vrs22">
<time>3</time>
<div class="smallHolder">
<div class="small1"></div>
<div class="small2"></div>
<div class="small3"></div>
<div class="small4"></div>
</div>
</button>
</div>
What I am trying to achieve is this:
Idea is to have this flexible so if I have 2 small squares, results should be like this:
Can anybody try to help me with this?
This could be a solution. It uses your unaltered HTML, but with completely different CSS. Changing the height and width of the outer container will still result in 4 small squares, as long as width and height of the outer container are equal.
* {
box-sizing: border-box;
}
.date-grid {
width: 100px;
height: 100px;
background: #eee;
display: flex;
flex-direction: column;
}
.vrs22 {
width: 100%;
height: 100%;
background: green;
border: none;
padding: 0;
}
time {
display: block;
height: 75%;
font-size: 24px;
display: flex;
flex-direction: column;
justify-content: center;
}
.smallHolder {
width: 100%;
height: 25%;
display: flex;
}
.smallHolder>div {
width: 25%;
height: 100%;
flex-shrink: 0;
flex-grow: 1;
}
.small1 {
background: #fb0;
}
.small2 {
background: #bf0;
}
.small3 {
background: #f07;
}
.small4 {
background: #ba0;
}
<div class="date-grid">
<button class="vrs22">
<time>3</time>
<div class="smallHolder">
<div class="small1"></div>
<div class="small2"></div>
<div class="small3"></div>
<div class="small4"></div>
</div>
</button>
</div>
With different container size:
* {
box-sizing: border-box;
}
.date-grid {
width: 150px;
height: 150px;
background: #eee;
display: flex;
flex-direction: column;
}
.vrs22 {
width: 100%;
height: 100%;
background: green;
border: none;
padding: 0;
}
time {
display: block;
height: 75%;
font-size: 24px;
display: flex;
flex-direction: column;
justify-content: center;
}
.smallHolder {
width: 100%;
height: 25%;
display: flex;
}
.smallHolder>div {
width: 25%;
height: 100%;
flex-shrink: 0;
flex-grow: 1;
}
.small1 {
background: #fb0;
}
.small2 {
background: #bf0;
}
.small3 {
background: #f07;
}
.small4 {
background: #ba0;
}
<div class="date-grid">
<button class="vrs22">
<time>3</time>
<div class="smallHolder">
<div class="small1"></div>
<div class="small2"></div>
<div class="small3"></div>
<div class="small4"></div>
</div>
</button>
</div>
And a variation with only two squares at the bottom:
* {
box-sizing: border-box;
}
.date-grid {
width: 100px;
height: 100px;
background: #eee;
display: flex;
flex-direction: column;
}
.vrs22 {
width: 100%;
height: 100%;
background: green;
border: none;
padding: 0;
}
time {
display: block;
height: 50%;
font-size: 24px;
display: flex;
flex-direction: column;
justify-content: center;
}
.smallHolder {
width: 100%;
height: 50%;
display: flex;
}
.smallHolder>div {
width: 25%;
height: 100%;
flex-shrink: 0;
flex-grow: 1;
}
.small1 {
background: #fb0;
}
.small2 {
background: #bf0;
}
<div class="date-grid">
<button class="vrs22">
<time>3</time>
<div class="smallHolder">
<div class="small1"></div>
<div class="small2"></div>
</div>
</button>
</div>
im a bit lost:
im trying to make the space between 3 divs (horizontally) 40px, but it doesnt seem to work when i do it:
https://github.com/itsolidude/Tea_Cozy
i want the yellow marked parts to be 40px:
html {
font-family: Helvetica;
font-size: 22px;
color: seashell;
background-color: black;
opacity: 0.9;
text-align: center;
}
header {
display: flex;
align-items: center;
justify-content: space-between;
height: 69px;
border-bottom: 1px solid seashell;
position: fixed;
width: 100%;
z-index: 2;
background-color: black;
top: 0;
}
#locations h2 {
flex: 1 0 100%; /* shorthand for: flex-grow:1;
flex-shrink: 0;
flex-basis: 100%; */
text-align: center;
position: absolute; /* found this to be a simpler solution, and i sticked with it even tho i dont have exact 10px :p */
top: 1510px;
z-index: 3;
}
img {
height: 50px;
padding-left: 10px;
}
nav span {
color: seashell;
padding-right: 30px;
}
.mission-banner {
background-color: black;
}
.mission-banner h4 {
padding-bottom: 10px;
}
a {
cursor: pointer;
text-decoration-color: seashell;
}
#mission {
background-image: url(../images/img-mission-background.jpg);
position: relative;
margin: 70px auto 0;
width: 1200px;
height: 700px;
display: flex;
flex-direction: column;
justify-content: center;
}
#tea-of-month {
display: flex;
flex-wrap: wrap;
justify-content: center;
width: 1000px;
margin: 0 auto 70px;
}
#tea-of-month img {
height: 200px;
width: 300px;
margin-bottom: 10px;
}
.item {
display: flex;
flex-direction: column;
padding: 10px;
}
.contact {
height: 200px;
}
#locations {
height: 500px;
width: 1200px;
margin: 0 auto;
background-image: url(../images/img-locations-background.jpg);
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
}
.address {
background-color: black;
width: 300px;
height: 300px;
display: flex;
flex-direction: column;
justify-content: center;
opacity: 1;
}
#copyright {
text-align: left;
margin-left: 20px;
}
<div id="locations">
<h2>Locations</h2>
<div class="address">
<h3>Downtown</h3>
<p>384 West 4th St</p>
<p>Suite 108</p>
<p>Portland, Maine</p>
</div>
<div class="address">
<h3>East Bayside</h3>
<p>3433 Phisherman's Avenue</p>
<p>(Northwest Corner)</p>
<p>Portland, Maine</p>
</div>
<div class="address">
<h3>Oakdale</h3>
<p>515 Crescent Avenue</p>
<p>Second Floor</p>
<p>Portland, Maine</p>
</div>
</div>
i put in the whole css. just in case something is affecting it. Pls explain what and why you did it :p
Don't use justify-content: space-between; as this will allot space depending on the available space.
Instead, center the flex-children and give them side margin of 20px (2 * 20px = 40px).
.wrap {
display: flex;
justify-content: center;
width: 90%;
margin: auto;
border: 1px solid grey;
}
.box {
background: #000;
width: 150px;
height: 150px;
margin: 20px;
}
<div class="wrap">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
Alternatively, you could set a max-width of the parent container, thus making less available space for the children to spread out with the space-between style.