Media Query Not Working With Larger Viewport Sizes - css

I have a set of social media icons at the top of my sidebar: outtacontext. But I'm having trouble positioning them in the right place at different viewport sizes. Actually, it's working for all the smaller viewports but the positioning is off for the larger screens.
Here's my main css for this positioning:
#top #sidebar_bg .social_bookmarks {
position: absolute;
right: 69px;
z-index: 152;
margin-top: 102px;
}
#media only screen and (max-width: 989px) and (min-width: 768px){
#top #sidebar_bg .social_bookmarks {
right: 33px;
margin-top: 65px;
}
}
For some reason, with the larger screens the icons appear to get centered within the sidebar. But any media queries I make to adjust just start adding problems.
Can anyone point me in the right direction? Thx.

First of all, I'm Argentinean, so forgive me for my English!
Here's my help...
The HTML markup is:
<div id="sidebar_bg">
<ul class="social_bookmarks">
<li class='twitter'>
<a href='http://twitter.com/outtacontext'>Follow us on Twitter</a>
</li>
<li class='facebook'>
<a href='http://facebook.com/chamomileteaparty'>Join our Facebook Group</a>
</li>
<li class='gplus'>
<a href='https://plus.google.com/106461359737856957875/posts'>Join me on Google Plus</a>
</li>
<li class='linkedin'>
<a href='http://linkedin.com/jeffgates'>Add me on Linkedin</a>
</li>
<li class="rss">
RSS
</li>
<li class="flickr">
Flickr
</li>
</ul>
</div>
The CSS styles:
#top #sidebar_bg {
text-align: center; /* This will center EXACTLY on the middle the icons (acording to the #sidebar_bg width on every screen resolution */
}
#top #sidebar_bg .social_bookmarks {
display: inline-block;
z-index: 152;
margin-top: 102px;
}
#media only screen and (max-width: 989px) and (min-width: 768px){
#top #sidebar_bg .social_bookmarks {
margin-top: 65px;
}
}
ALTERNATIVE CSS - if you want to put it right or left, and use media queries to determine the separation width from one of the sides, you can use this:
#top #sidebar_bg {
text-align: *****; /* right or left */
}
#top #sidebar_bg .social_bookmarks {
margin-*****: 40px; /* right or left */
display: inline-block;
z-index: 152;
margin-top: 102px;
}
#media only screen and (max-width: 989px) and (min-width: 768px){
#top #sidebar_bg .social_bookmarks {
margin-*****: 25px; /* right or left */
margin-top: 65px;
}
}

I solved the problem. I had tried making a media query for what I thought was the largest viewport size. As it turns out, I wrote it for the wrong width (just "barely" wrong but you know what that means -g). The media query for positioning should have been set for a min-width of 1140 px. I had set it for 1122px. So close. LOL

Related

CSS Responsive images with same position

I create one page with bootstrap and add 3 svg images. Now, on desktop is look good, but when I change view on mobile two images disappear. How I can fix this view for mobile?
This is desktop screenshot
This is mobile when I lose two images
HTML:
<div class="col-lg-12 row-1 mid">
<div class="col-lg-8">
<img class="img-fluid img-icon icon1" src="img/icon/web-dizajn.svg" alt="Potrebna vam je pomoc oko izrade web sajta?">
<img class="img-fluid img-icon icon2" src="img/icon/graficki-dizajn.svg" alt="Potrebna vam je pomoc oko izrade web sajta?">
<img class="img-fluid img-icon icon3" src="img/icon/web-hosting.svg" alt="Potrebna vam je pomoc oko izrade web sajta?">
</div>
<div class="col-lg-4">
<h4>Web Dizajn</h4>
<p></p>
<p>
Pročitaj više
</p>
</div>
</div>
CSS:
.row-1 {
display: flex;
}
.mid {
text-align: center;
background: linear-gradient(to top, #ffffff 0, #ffffff 100%);
border-radius: 35px;
padding: 50px;
border: 15px solid #f7f7f7;
}
.img-fluid {
max-width: 100%;
height: auto;
}
.img-icon {
width: 50%;
}
.icon1 { padding:0px; }
.icon2 { position: absolute; left: 0; padding:75px; top:50px; }
.icon3 { position: absolute; right: 0; padding:75px; top:50px; }
When your viewport size is < 992px, the icon size with padding is 150px. Since you have a padding of 75px, the left and right padding "eat up" the whole width space (75 + 75 = 150), which leaves no room to show the actual image. You need to reduce the padding with a CSS media query, like this:
#media (max-width: 991px) {
.icon2 { position: absolute; left: 0; padding:35px; top:50px; }
.icon3 { position: absolute; left: 0; padding:35px; top:50px; }
}
And maybe change the top value as well. Experiment with different values until you get the exact look you're aiming for.
From your live demo, seems like you're using padding to reduce size of your svn image. Problem is padding is larger than container, causing image having inside width and height 0. Consider using percent width and height like your first image or use media queries to reduce padding values on mobile.
When you decrease the screen size you will need to edit the css for .icon2 and .icon3 so that the padding doesn't result in the image disappearing so that there is no space for the image to display.
Try this
#media (max-width: 992px) {
.icon2 {
padding:10px;
top:20px;
}
.icon3 {
padding:10px;
top:20px;
}
}
992px is the biggest width before the large screen changes. The position and left will be same throughout.
You need to change the positions for icon2 and icon3 in mobile resolution and try remove the padding for these icons. If you post a plunker it will be helpful to give the exact solution.

vertical and horizontal responsive list

i want to ask you how can i make a responsive list with 3 items in wich when i reduce the size of my browser the items go vertical and the one is below the other, when the browser window is growing the items will be in one. My code for the list is the following , i managed to order them in center and in one row but i am getting confused about the responsive..
<div class="list">
<ul id="2" class="3">
<li>< </li>
<li> </li>
<li> </li>
</ul>
</div>
and the css
.list{
position: relative;
width: 100%;
display: block;
}
.list li {
width: 33.3%; /* nice 3 columns */
float: left;
padding: 0; /* should have zero paddng/margin */
margin: 0;
}
.list li > span {
margin: 6% 6% 0 0; /* now margins are specified relative to outer <li> width */
display: block;
}
What you are looking for are css media queries. For example, add this to your css:
#media (max-width:500px){
.list li {
float:none;
}
}
Here's a jsfiddle.
Suggest you read this:
https://developers.google.com/web/fundamentals/layouts/rwd-fundamentals/use-media-queries?hl=en
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
http://cssmediaqueries.com/what-are-css-media-queries.html
You can use media queries to set a breakpoint and set the ".list li" width to 100% when the window width is less than the size you want.
Here's a link about media queries: http://cssmediaqueries.com/

Evenly distribute available responsive height over vertically stacked li elements

For responsiveness, I'm developing a website with bootstrap (1st time) and php. In the upper part of the page I want to use a row divided into 2 colums (col-sm-3 & 9), the wider one occupying an image carousel, the other one an unsorted list with 2 list elements, one image, one text. Now I want the elements to have the same height, i.e. 50% of the (responsive) height of the carousel image. The carousel image has a 100% width of the column, so when the display gets smaller, so will the height of the carousel. Thus the height of the list elements has to diminish accordingly.
<!-- Carousel Row -->
<div class="row" id="top">
<!-- Sidebar -->
<div class="col-sm-3 sidebar" id="sidebar">
<ul class="nav navbar-nav-custom">
<li class="logo">
<img>
</li>
<li class="text">
|
|
</li>
</ul>
</div>
<!-- Carousel -->
<div class="col-sm-9" id="carouselbar">
<div id="carousel" class="carousel slide" data-ride="carousel">
|
|
</div><!-- /.carousel -->
</div>
</div>
I tried to find a solution myself but didn't succeed nor could I find a solution after a real extensive internet search. Could anyone help me out giving these list elements a responsive height, preferably CSS only.
EDITED after comments below.
You can get a responsive height by setting the height to 0 and adding padding-bottom as a percentage. You would need to adjust the acutal percentage depending on your aspect ratio.
You could then add the text inside as an absolutely positioned div with height: 100% and width 100%.
Here's a fiddle I had to use media queries to get the height to stay at 50%.
<li class = 'text_holder'>
<div id ='text'>
My text here
</div>
</li>
.text_holder {
height: 0;
padding-bottom: 85%;
background-color: yellow;
}
#text {
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#media (min-width: 992px) {
.logo {
padding-bottom: 83%;
}
.text_holder {
padding-bottom: 83%;
}
}
/* Large devices (large desktops, 1200px and up) */
#media (min-width: 1200px) {
.logo {
padding-bottom: 81%;
}
.text_holder {
padding-bottom: 81%;
}
}
For the image, you would just use the same method as the carousel, give it a percentage based width, and the height will scale accordingly.
Otherwise, you can adjust font-size to be smaller for lower res screens. You would need to adjust the following to suit your actual design.
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
.text {
font-size: 1.1em;
}
/* Small devices (tablets, 768px and up) */
#media (min-width: 768px) {
.text {
font-size: .8em;
}
}
/* Medium devices (desktops, 992px and up) */
#media (min-width: 992px) {
.text {
font-size: .9em;
}
}
/* Large devices (large desktops, 1200px and up) */
#media (min-width: 1200px) {
.text {
font-size: 1em;
}
}

How do I keep my navigation attached to this fluid image?

I created a break point for my background-image using media queries that starts below 989px (the largest image size). I am not using to display the image because I want to use different images for different devices (So that a mobile device doesn't download the largest image of course). (Each image is defined in a specific break-point). Just to say it early, this is live at http://www.glorkianwarrior.com
The css for this goes like so:
.splash {
max-width: 988px;
margin:auto;
height:380px;
}
#media (min-width: 989px) {
.splash {
background: url('../images/academy.png') no-repeat;
}
}
#media (max-width: 989px) and (min-width: 321px) {
.splash {
background: url('../images/academy-mid.png') no-repeat;
max-width: 640px;
padding: 4px;
position: relative;
background-size: 100%;
}
}
That makes it so once the page reaches 988 px or below (down to 321px), the splash image becomes fluid. It actually doesn't change it's width/height until the browser is less than 640px wide. What happens in the navigation bar below it which is nested under .splash won't change its location. This is because its connected to the height of the .splash. The html looks like so:
<header class="splashhead">
<div class="splash">
<nav class="kochalka">
<ul>
<li class="navclass first active"><a href="http://glorkianwarrior.com/" title="Home" >Home</a></li>
<li class="navclass"><a href="news/" title="News" >News</a></li>
<li class="navclass"><a href="gallery.html" title="Gallery" >Gallery</a></li>
<li class="navclass last"><a href="guide.html" title="Guide" >Guide</a></li>
</ul>
</nav>
</div>
</header>
If I don't give it that height, it will disappear. I have tried giving it 100% or a percentage of the page itself. I tried giving its parent a specific height and then doing 100% on .splash, but that didn't change the placement of the navigation bar.
Is it possible to have this navigation change its size based on browser size? Will I have to figure out a way to use images on the page each image within their own div and use media queries to display:none on non-relevant divs?
You need to wrap your nav within a div and then give it an aspect ration using some clever CSS. See Below -
Here is your code:
I have added a wrapper div around the navas you can see
<header class="splashhead">
<div class="splash">
<div class="wrapper">
<nav class="kochalka" style="">
<ul>
<li class="navclass first active">Home</li>
<li class="navclass">News</li>
<li class="navclass">Gallery</li>
<li class="navclass last">Guide</li>
</ul>
</nav>
</div>
</div></header>
Add the following style also and then it will work as you wish
<style>
.wrapper {
width: 100%;
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 56.25%; /*16:9 ratio*/
display: block;
content: '';
}
</style>

Variable width DIV using pixel minimum and maximum widths?

Kinda stuck on a small issue trying to use a div with a background image in the top left [a logo] not sure how to get this done.... since the variable width is not dependent on a percentage width... i.e.
the maximum width of the div is 1200px
the minimum width of the div is 900px
When someone resizes their browser I need that div to expand or contract depending on the viewport size.
Any thoughts on how I can do this [is this possible without javascript?]?
UPDATE
This is where I got to - seems to work well in most browsers until I hit IE7..
<div id="viewport" class="[[*layout]]">
<div id="contentwrapper">
<div class="wrapper logo">
<div id="header">
[[$TopNav]]
</div>
<div id="content" class="homepage">
[[!If? &subject=`[[*id]]` &operator=`==` &operand=`1` &then=`[[$HomePageTpl]]` &else=`[[$DefaultPageTpl]]` ]]
</div>
</div>
</div>
<div class="wrapper footer">
<div id="footer">
<div id="footnav">[[$FootNav]]</div>
<div id="copyright">[[$Copyright]]</div>
<div id="news-feed">[[$NewsFeed]]</div>
</div>
</div>
div {border: 1px dotted #ccc;}
div#viewport {width:100%;float:left;min-height:100%;position:relative;background-color:#000000;}
div#contentwrapper {width:100%;float:left;background-color:#ffffff;margin-top:8px;}
div#content, div#footer, div#header {float:right;width:900px;padding-left:100px;}
div#header {}
.wrapper {
margin:0 auto;
height:150px;
width:100%;
max-width:1110px;
min-width:1060px;
text-align:left;
}
.wrapper.logo {
background:transparent
url(/assets/images/layout/anderson-lyall-consulting-group-logo.png) no-repeat left top;
}
div#topnav {width:900px;float:right;margin:0 auto;border:1px solid #cc0000;}
CSS has 2 properties for those scenarios, that work from IE7+ called:
min-width: https://developer.mozilla.org/en/CSS/min-width
max-width: https://developer.mozilla.org/en/CSS/max-width
That's probably what you are looking for, you could set the width to 100% first then add the min/max width to control it.
For a no-js solution on modern browser you can use CSS media queries like so
#media screen and (max-width: 1199px) {
div { width: 900px; }
}
#media screen and (min-width: 1200px) {
div { width: 1200px; }
}
this will automatically resize the div depending on your window width and not on the content. Media queries support: http://caniuse.com/css-mediaqueries
a simple proof-of-concept demo
<html>
<head>
<style>
div { margin: 0 auto; border: 1px red solid }
div:after { display: block; }
#media screen and (max-width: 1199px) {
div { width: 900px; }
div:after { content: " max-width is 1199px" }
}
#media screen and (min-width: 1200px) {
div { width: 1200px; }
div:after { content: " min-width is 1200px" }
}
</style>
</head>
<body>
<div>Resize your browser</div>
</body>
</html>

Resources