i am trying to use media queries to have a style for screens larger than 768px and another one for smaller than 768px
when i resize the window the changes are happening but when i'm opening the website with phone or with the phone view in the Chrome inspector it doesnt work as I expect..
thanks !
#media (max-width: 768px) {
body {
background-color: lightblue;
}
}
#media (min-width: 768px) {
body {
display: flex;
justify-content: center;
}
#cont {
background-color: aqua;
width: 80vw;
}
#header {
height: 30vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#tophead {
background-color: blueviolet;
height: 5vh;
display: flex;
justify-content: space-between;
align-items: center;
}
#lefttophead {
height: 80%;
width: 40%;
background-color: yellow;
}
#righttophead {
height: 80%;
width: 20%;
background-color: orange;
}
#lowhead {
height: 10vh;
background-color: gold;
display: flex;
align-items: center;
}
#navbar {
height: 80%;
width: 100%;
background-color: hotpink;
display: flex;
justify-content: space-between;
align-items: center;
}
#onglets {
width: 70%;
height: 80%;
background-color: cadetblue;
}
#searchbar {
width: 20%;
height: 80%;
background-color: skyblue;
}
}
Related
I'm trying to set width of a Div to 95% in #media but it gets canceled by the browser.
It works fine with other divs.
#media screen and (max-width: 700px) {
.proj {
flex-direction: column;
align-items: center;
border: 1px solid white;
width: 300%
}
.innp {
width: 50%;
}
}
.proj {
display: flex;
justify-content: space-between;
width: 100%
}
.innp {
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
border: 1px solid white;
overflow: hidden;
}
Here is what the browser does:
https://i.stack.imgur.com/35aJG.png
Put #media at last. In CSS, the one appear later in the code override earlier rules
.proj {
display: flex;
justify-content: space-between;
width: 100%
}
.innp {
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
border: 1px solid white;
overflow: hidden;
}
#media screen and (max-width: 700px) {
.proj {
flex-direction: column;
align-items: center;
border: 1px solid white;
width: 300%
}
.innp {
width: 50%;
}
}
More information: What is the order of precedence for CSS?
So i have this navbar and I just set my last element to have the margin-right: 0
but when media query runs, I see my navbar pop up and see the last item has margin-right: 0 applied as well and I dont want that. How can I fix this? I am not sure if I have to insert all the code here
.navbar {
font-size: 30px;
padding: 30px;
display: flex;
flex-direction: row;
justify-content: space-between;
height: auto;
background: rgb(255, 236, 65);
}
.list {
list-style-type: none;
}
.list-item {
display: inline-block;
margin-right: 40px;
}
.list-item:nth-child(4) {
margin-right: 0;
}
#media all and (max-width: 650px) {
.navbar {
flex-direction: column;
}
.list {
width: 100%;
text-align: center;
display: none;
}
.list-item {
display: block;
margin-top: 50px;
margin-bottom: 45px;
}
.menu {
display: block;
position: absolute;
top: 35px;
right: 42px;
}
.active {
display: block;
}
}
Try this
I Hope it will work 😊
.navbar {
font-size: 30px;
padding: 30px;
display: flex;
flex-direction: row;
justify-content: space-between;
height: auto;
background: rgb(255, 236, 65);
}
.list {
list-style-type: none;
}
.list-item {
display: inline-block;
margin-right: 40px;
}
.list-item:nth-child(4) {
margin-right: 0;
}
#media all and (max-width: 650px) {
.navbar {
flex-direction: column;
}
.list {
width: 100%;
text-align: center;
/* display: none; */
}
.list-item {
display: block;
margin-top: 50px;
margin-bottom: 45px;
}
.list-item:nth-child(4) {
margin-right: 40px;
}
.menu {
display: block;
position: absolute;
top: 35px;
right: 42px;
}
.active {
display: block;
}
}
how to make the footer down below and vertical?
I want it for the mobile version to make the footer down below.
I tried many solutions but it didn't work very well.
the output
as you see it become like this, I don't know if it's from the footer or the content itself?
/* mobile styles */
.footer {
height: auto;
border: 1px solid red;
}
.footer .footer-content {
height: auto;
flex-direction: column;
}
.footer .footer-content .footer-section {
height: auto;
}
/* desktop styles */
.footer {
height: 200px;
width: 100%;
}
.footer .footer-bottom {
height: 20px;
width: 100%;
text-align: center;
bottom: 0px;
left: 0px;
padding-top: 20px;
}
.footer .footer-content {
height: 180px;
display: flex;
}
.footer .footer-content .footer-section {
flex: 1;
}
Try this:
.footer {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
If you are using bootstrap simply use col classes
My page is working properly on bigger screen size devices but on mobile devices it is not working properly. please help
https://codesandbox.io/s/ships-q64g6?file=/src/App.js
Try this CSS
* {
box-sizing: border-box
}
.App {
font-family: sans-serif;
text-align: center;
width: 100%;
height: 100%;
background-color: #00171f;
}
.App h4 {
font-size: 25.5px;
text-align: center;
color: whitesmoke;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: column;
display: inline-block;
width: 100%;
}
.container ul {
width: 100%;
max-width: 800px;
padding: 10px;
}
.container li {
width: 100%;
list-style: none;
font-size: 20px;
font-weight: 1.5em;
}
.container img {
width: 100%;
height: 500px;
}
.container .name {
max-width: 660px;
width: 100%;
height: 20px;
text-align: left;
color: #57e1ed;
}
.container .port {
margin-top: -20px;
font-size: 20px;
text-align: right;
color: #57e1ed;
}
Centering a flex item is easy. However I like to shift it upwards a bit so that the the relation between the upper and lower space is e. g. 1/2. Easy too when using fillers. But is there a way to do this whithout fillers?
HTML:
<div id="filler-top"></div>
<div id="the-item">
</div>
<div id="filler-bottom"></div>
CSS:
#the-item {
width: 80vw;
height: 30vh;
border: 2px solid lightblue;
}
body {
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
#filler-top {
width: 100%;
flex: 1;
}
#filler-bottom {
width: 100%;
flex: 2;
}
https://jsfiddle.net/Sempervivum/b2wotc8e/3/
Applying margin-top and margin-bottom doesn't work as a percentage is relative to the width.
instead of adding 2 elements to the markup, you can use :before and :after pseudo-elements:
#the-item {
width: 80vw;
height: 30vh;
border: 2px solid lightblue;
}
body {
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
body:before {
content: "";
width: 100%;
flex: 1;
}
body:after {
content: "";
width: 100%;
flex: 2;
}
<div id="the-item"></div>
Another option is to simply use a mixture of position:relative, top and transform:
#the-item {
width: 80vw;
height: 30vh;
border: 2px solid lightblue;
position: relative;
top: 33.333%;
transform: translateY(-33.333%);
}
body {
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
}
<div id="the-item"></div>