img.logo {
height: auto;
width: auto\9; /* ie8 */
left: 50%;
margin-top: -250px;
margin-left: -134px;
position: absolute;
top: 50%;
resize: both;
That's the code I'm using. It's a combination of resizing and centering, and yet it's only centering for some reason. I need the image to scale because, as it is currently, it's overlapping with an upper element of the page at very small browser sizes.
You can try using CSS media queries. Basically we define breakpoints based on screen width/browser width, and adjust the image widths accordingly.
img {
width: auto;
height: auto;
}
#media all and (max-width: 600px) {
img { width: 500px; }
}
#media all and (max-width: 500px) {
img { width: 400px; }
}
#media all and (max-width: 400px) {
img { width: 300px; }
}
#media all and (max-width: 300px) {
img { width: 200px; }
}
#media all and (max-width: 200px) {
img { width: 100px; }
}
See this example
Hope this can suit your needs
EDIT:
You could even combine the above suggestion with transform: translateX(-50%) translateY(-50%); to keep the image centered at all times. For instance:
img {
position: absolute;
left: 50%;
top: 50%;
width: auto;
height: auto;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
#media all and (max-width: 600px) {
...
}
...
Here's an example
Use simple % for implementing the image width and height and the rest will take care automatically. The overlapping here I think is because the image is trying to maintain proportions with the auto attribute.
Or else you can try something like this in css
img.resize{
width:60%; /* Use either % or px*/
height: auto;
}
Related
I am trying to move a shortcode which I put in Wordpress header. The problem is that from the 2 css rules below only the first works. If I change the order then again only the first works.
#media only screen and (max-width: 1024px) {
.right-header-wrap-flags {
position: absolute;
top: 25px;
left: 22px;
}
.navigation-wrap{
padding-top: 60px;
} #media only screen and (min-width: 1025px) {
.right-header-wrap-flags {
position: relative;
left: 600px;
top: 50px;
}
if you want the "Navigation-wrap" class to be part of the first media query:
#media only screen and (max-width: 1024px) {
.right-header-wrap-flags {
position: absolute;
top: 25px;
left: 22px;
}
.navigation-wrap{
padding-top: 60px;
}
} <-- this was missing!
#media only screen and (min-width: 1025px) {
.right-header-wrap-flags {
position: relative;
left: 600px;
top: 50px;
}
}
if "navigation-wrap" should be independent from your media querys:
#media only screen and (max-width: 1024px) {
.right-header-wrap-flags {
position: absolute;
top: 25px;
left: 22px;
}
} <-- this was missing!
.navigation-wrap{
padding-top: 60px;
}
#media only screen and (min-width: 1025px) {
.right-header-wrap-flags {
position: relative;
left: 600px;
top: 50px;
}
}
reason: You forgot the bracket, which basically meant that the second media query was aprt of your first, so it could never occur! When your screen size reached 1025px the first media query is not active anymore and the second one was inside of the first one, so it also couldnt happen anymore. That should fix it
Yes , Only the first CSS code works, you should use javascript, to change the styles based on the Conditions you specify .
I have problems with the media-query, it detects me well the first but when they are less than 768px it no longer detects the average
this are my media-querys.
#media screen and (max-width:1920px){
#log {
bottom: 36%;
left: 35%;
}
}
#media screen and (max-width:1440px){
#log {
left: 41%;
width: 57%;
bottom: 30%;
}
#img2 {
width: 100%;
}
}
#media screen and (max-width:1024px){
#log {
left: 61%;
width: 72%;
bottom: 30%;
}
#img2 {
width: 100%;
}
}
#media screen and (max-width:765px){ /***** this is the one that does not work
#Table_01 {
margin-top: -12%;
}
}
You can try this: jsfiddle Demo
#Table_01 {
display: block;
width: 100%;
height: 500px;
border: 1px solid black;
margin-top: 20px;
}
#media screen and (max-width: 768px) {
#Table_01 {
margin-top: -12%;
}
}
<table id="Table_01"></table>
Note: in some #media questions you have 2 spaces, try to use one only to avoid any possible issue.
The last media query just works when the width of the screen is equal or lower than 765px not 768px. Also need to close the comment with */
#media screen and (max-width:768px) { /* this is the one that does not work */
#Table_01 {
margin-top: -12%;
}
}
I've been trying to enlarge the logo of our site when viewed on mobile phone but no code seems to work. I've tried different versions of this but to no avail:
#media (max-width: 360px) {
.header-logo img {
max-width: 50%;
max-height: 50%;
}
}
I'm not sure what to adjust further since Firebug seems to be displaying code for the desktop version. And I don't really want to change anything on desktop view. Just mobile.
Will appreciate any feedback.
You can make the below changes in the css.
.header-logo img {
max-width: 100%;
max-height: auto;
}
Try this out
.header-logo img {
width: 100%;
height: 400px;
background-image: url('img_flowers.jpg');
background-repeat: no-repeat;
background-size: contain;
border: 1px solid red;
}
At max-width of 360px change style property for class .custom-logo-link as below,
#media screen and (max-width : 360px){
.custom-logo-link {
width: 50%;
}
}
You have to specify only width, it will adjust height automatically.
.header-logo img {
width: 100%;
}
This may be a silly question, but are you sure max-width and max-height is what you want to change here? Those parameters just set the upper limit of how tall and wide the element can be.
https://www.w3schools.com/CSSref/pr_dim_max-width.asp
Perhaps try one of these?
#media (max-width: 360px) {
.header-logo img {
width: 50%;
height: 50%;
}
}
or:
#media (max-width: 360px) {
.header-logo img {
transform: scale(0.5);
}
}
How would you resize a carousel according to browser's height ?
For resizing according to width, Im able to make it responsive with this in CSS
#media (max-width: #screen-xs-max) { ... }
#media (min-width: #screen-sm-min) and (max-width: #screen-sm-max) { ... }
#media (min-width: #screen-md-min) and (max-width: #screen-md-max) { ... }
#media (min-width: #screen-lg-min) { ... }
But for making it responsive towards height, im not sure how would I do it.
Any clue ?
You can use css unit vh for using screen height purposes. 100vh means whole viewport height. vh is dynamic so it changes as you change the screen size.
Here is one demo from fiddle
.carousel .item {
max-width: 100%; /*slider width*/
max-height: 100vh; /*slider height*/
}
Thanks Sachin Kanungo.
I had the same issue as Max.
But for me it worked with these settings:
.carousel {
height: 80vh; /*slider height equals to 80% of viewport height*/
margin-bottom: 60px;
}
.carousel .item {
min-width:100%;
height:80vh; /*slider height equals to 80% of viewport height*/
background-color: #777;
}
.carousel-inner > .item > img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: 80vh; /*slider height equals to 80% of viewport height*/
}
Note: I'm using bootstrap 3.3.6
I have a blog template which I'm making responsive, how can i change the background of the body at smaller resolutions, I'm trying the following but it doesn't work.
#media (max-width: 30em) {
.post-template {
background-color: #color_01;
}
}
my body has the class
<body class="post-template">
The MixIn which applies the body color styling is as follows
.BodyColor () {
background-color: #color_01;
background-image: url(../images/body.jpg);
color: #color_05;
overflow-x: hidden;
background-attachment: fixed;
&:after {
content: ' ';
width: 100%;
height: 50%;
background-color: darken(#color_01, 10%);
.transform(~"skew(-20deg) rotate(-20deg)");
left: 0;
top: 30%;
.opacity(0.5);
position: fixed;
}
}
I want to overwrite the .transform call, so there isn't a skew on smaller resolutions as it renders too slowly
however I've set some properties of the body:afterpseudo class which I want to overwrite at smaller resolutions.
#media screen and (min-width: 30em) {
.post-template {
background-color: #big_size_color;
}
.post-template:after {
yourcode...
}
}
#media screen and (max-width: 30em) {
.post-template {
background-color: #color_01;
}
}
This keeps the body:after code from being shown unless the page is bigger than 30em. This rule applies to anything you want to only work on higher resolutions and be "overridden" on smaller ones. Don't declare it by itself outside of the #media call.