How come my media query is not working? - css

I am trying to have my website 'responsive'. I have 2 columns and am trying to have them stack on each other when below 992px. This is the code I have for the columns and the code for the media query. Whenever I go below the 992px, col1 stays at 69% and col2 at 29% but both are floating left and stacked on top of each other. I am just wondering what I am doing wrong because I want them to take up the width of the screen when below 992px. Is the code for col1 and col2 overriding the #media? I have tried the #media with display: inline and display: block but neither worked. Sorry if it is messy, I only started learning last friday :)
#media (min-width: 768px) and (max-width: 991px) {
.col1 {
width: 98%;
}
.col2 {
width: 98%;
}
}
.col1 {
margin: auto;
float: left;
width: 69%;
background-color: #686472;
color: white;
padding: 5px;
font-family: geneva;
font-size: 14px;
}
.col2 {
margin: auto;
float: left;
width: 29%;
background-color: #454349;
color: white;
padding: 5px;
font-family: geneva;
font-size: 14px;
padding-bottom: 39px;
}

.col1 {
margin: auto;
float: left;
width: 69%;
background-color: #686472;
color: white;
padding: 5px;
font-family: geneva;
font-size: 14px;
}
.col2 {
margin: auto;
float: left;
width: 29%;
background-color: #454349;
color: white;
padding: 5px;
font-family: geneva;
font-size: 14px;
padding-bottom: 39px;
}
#media (min-width: 768px) and (max-width: 991px) {
.col1 {
width: 98%;
}
.col2 {
width: 98%;
}
}
Ideally though, you would create two more media queries, one with a max-width: 768px, and one with a min-width: 991px. This way you would account for the space above and below, and put all your numbers there so there are no conflicts.
Essentially what's happening is that anything that is outside of the media query applies to all widths. A simple, unorthodox solution to this problem would be to add '!important' to the rules inside media queries, without the need to change order.
#media (min-width: 768px) and (max-width: 991px) {
.col1 {
width: 98% !important;
}
.col2 {
width: 98% !important;
}
}
However, the use of '!important' can become highly problematic in large stylesheets where conflicts may occur and hair begins to get pulled off, use it wisely.

Related

Why doesn't #media only screen css work with !IMPORTANT;?

the only time I can get the css #media to work is if I use
!IMPORTANT; in the css like
#media only screen and (max-width: 600px)
.example {
padding-left: 2px !IMPORTANT;
}
.example {
width: 118px;
position: absolute;
padding-left: 21px;
padding-top: 11px;
}
If I don't use !IMPORTANT in the #meda css, the style won't pick up, so the question is, why?
I don't want to use !IMPORTANT; but the css #media won't work with it.
Please help
It's working fine for me. Maybe you have another css as well for that class that overwrites it.
.example {
width: 118px;
position: absolute;
padding-left: 21px;
padding-top: 11px;
background: red;
}
#media only screen and (max-width: 600px) {
.example {
padding-left: 2px;
background: blue;
}
}

How to fix this ui using media queries?

I thought like it is overlapping media queries issues but I didn't find any media query which overlaps.
I resize the width of menucontainer and searchcontainer but didn't work.
I thought it was that searchcontainer which has more size in padding,I tried to decrease and increase the padding value of searchcontainer but it didn't work.
4.When I click on 'Toggle device toolbar' it is not showing any dislocation of this three container(searchcontainer,contactcontainer and menucontainer) but when I remove 'Toggle device' option that time on chrome view it is dislocated their positions.
This dislocation occurs in between 786px to 771px width.
I want both side same view and this view can be supported all devices including desktop, tablets .
Click here to understand my code
Here is my code
`
#media only screen and (min-device-width : 768px) and (max-device-width : 768px), (min-width: 768px) and (max-width: 768px) and (orientation: landscape) {
.MenuContactContainer {
max-width: 100%;
width: 100%;
vertical-align: top !important;
padding-right: 0px;
text-align: center !important;
}
.MenuContact {
margin-bottom: 0px;
margin-top: 0px;
vertical-align: central;
padding-right: 10px;
font-weight: 400;
font-size: large;
text-align: center !important;
}
.search-container {
width: 102% !important;
display: inline-block;
height: 55px;
margin-left: 0px !important;
}
.Hamburger {
z-index: 257;
width: 465px;
height: 41px;
padding-bottom: 4px;
margin-left: 16px;
margin-right: auto;
margin-top: -53px;
position: relative;
border-color: transparent;
opacity: 1;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
filter: alpha(opacity=100);
background: transparent url(../images/hamburger.png) no-repeat center center;
background-size: contain;
}
.searchtextbox {
height: 32px;
background-color: #EAB640;
padding-left: 10px;
margin-top: -2px;
margin-bottom: 18px;
vertical-align: middle;
width: 270px;
margin-left: 32px;
}
}
`
How can I solve this issue? Please me find out that issue.
This is dislocation of three components are here.
This is showing in 'Toggle device' mode which is right position.

How to change css according to the size of the display

Im so new in CSS and trying to fix the following code..
I want a simple thing where the screen size is smaller than 400 change the image size..
it should work but it doesn't..
I tried to make
* {
box-sizing: border-box;
}
body, html {
background: #fff;
height: 100%;
margin: 10px;
}
.left__img2 {
position: absolute;
float: left;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
border-radius: 20px;
width: 600px;
height: 400px;
}
#media screen and (max-width: 500px) {
.left__img2 {
width: 10px;
}
}
Media queries at the top of the CSS need !important to over rule the media query. Media queries at the bottom do not need !important. I placed the query at the top so I used !important to over rule any other style after.
#media screen and (max-width: 500px) {
.left__img2 {
width: 10px !important;
}
}
* {
box-sizing: border-box;
}
body, html {
background: #fff;
height: 100%;
margin: 10px;
}
.left__img2 {
position: absolute;
float: left;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
border-radius: 20px;
width: 600px;
height: 400px;
}
I think this will work.
#media screen and (max-width: 500px) {
.left__img2 {
max-width: 10px;
}
}
Your code works well in the following example (resize your window), maybe it comes from a side effect of the rest of your code, can you show us the rest of your code?
.left__img2 {
position: absolute;
float: left;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
border-radius: 20px;
width: 600px;
height: 400px;
background-color: red;
}
#media screen and (max-width: 500px) {
.left__img2 {
width: 10px;
background-color: yellow;
}
<div class="left__img2"><div>

How to adjust the Width of the Mobile Site of Wordpress

I created this website and i have a problem with the mobile site. Which it does not fit to the content. How do i need to fix this? i have attached the css of the responsive below.
I have tried several codes. But it does not fit to the content. The website is smaller than the device. And making the width 100% did not work.
Thanks in Advance
#media only screen and (max-width: 600px) {
.content-area {
float: center;
width: 100%;
}
.social-navigation li a::before,
.sidebar-toggle {
font-size: 16px;
}
.sidebar-toggle {
height: 46px;
}
.site-title {
font-size: 32px !important;
}
}
#media only screen and (max-width: 500px) {
.content-area {
padding: 0;
width: 100%;
}
.container {
width: 100%;
}
.site-logo {
width: 50px;
text-align: left;
}
.site-title,
.entry-title {
padding-top:20px;
font-size: 18px !important;
}
.site-description {
margin-top: 0;
font-size: 16px !important;
}
}

Responsive media queries

Im very confused at the moment, so im trying to create a responsive website.
For some reason my media queries are not triggering? I have the below CSS and it works fine from X-Small Below 480px and up to 575.98px. but past the media query, anything that I add into the 767.98px range isnt working at all?
#media only screen and (min-width : 480px) {
.card-4{
display: none;
}
}
#media (max-width: 575.98px) {
#about{
padding: 0 0.5rem 0 0.5rem;
}
.about-photo img{
width: 70%;
}
.about-text{
margin: auto;
text-align: center;
padding: 1rem 0 3rem 0;
}
.about-text h1, .about-text p{
text-align: center;
float: none;
}
.table{
margin: 0;
padding-left: 0;
}
.table li{
margin: auto;
padding-top: 0.3rem;
padding-left: 2rem;
text-align: left;
}
#skills-list{
margin: 0 2rem 0 2rem;
}
#skills-list li{
text-align: left;
padding-bottom: 1rem;
}
.card-1{
display: none;
}
.card{
margin-left: auto !important;
margin-right: auto !important;
text-align: center;
}
.cards-container{
margin: 0 !important;
}
.timeline > li > .timeline-panel {
width: 85%;
float: right;
padding: 1.2rem;
}
.timeline:before {
left: 6%;
}
.timeline > li > .timeline-badge {
width: 44px;
height: 44px;
left: 6%;
}
.timeline > li > .timeline-panel:before {
border-left-width: 0;
border-right-width: 15px;
left: -15px;
right: auto;
}
.timeline > li > .timeline-panel:after {
border-left-width: 0;
border-right-width: 14px;
left: -14px;
right: auto;
}
.square-1-text, .square-2-text, .square-3-text{
height: 31rem;
}
.square-1{
order:1;
}
.square-1-text{
order:2;
}
.square-2{
order:3;
}
.square-2-text{
order:4;
}
#passions-section{
padding-bottom: 0;
}
#skills-list li.i{
list-style-position: outside !important;
display: none;
}
/*// Small devices (landscape phones, less than 768px)*/
#media (max-width: 767.98px) {
}
/*// Medium devices (tablets, less than 992px)*/
#media (max-width: 991.98px) {
}
/*// Large devices (desktops, less than 1200px)*/
#media (max-width: 1199.98px) {
}
Using the right breakpoints in your CSS media queries is likely the most important decision when implementing a fully responsive site.
Min-width: 320px (smaller phone viewpoints)
Min-width: 480px (small devices and most phones)
Min-width: 768px (most tablets)
Min-width: 992px (smaller desktop viewpoints)
Min-width: 1200px (large devices and wide screens)
In your case Try this one
#media (min-width:500px) and (max-width:750px)

Resources