#media width doesn't fill full page, what I am doing wrong? - html

I want to make an 100% full page, within 4 images on each row. But if you resize the window you'll get 3 images than 2 images till there is 1 left. After research I become at #media to fill the full page without getting any blank spaces. Now i've made this jsfiddle but if you resize the results window you will see blank spaces who are not filled. What am I doing wrong?
#media only screen and (min-width : 354px) {
/* Smartphone view: 1 tile */
.image{
width: 100% }
https://jsfiddle.net/8hfLkb3k/
The image always must fill both width's, if the width is 50% for 2 both images must fill it in for 50%.
Thanks.

I recommend using max-widths for your media queries, but you don't have to do this, as long as what you do gives you the intended and correct result.
In my working example I've chosen to set the one-image container for 25% unless something changes like the viewport width.
At 1024, 767 and 600 I've chosen the 1/3 and 1/2 sizes and finally the 100% width.
I expect this is what you mean, but feel free to adapt this code as you see fit, especially to match the media query viewport attributes to what you desire.
* {
box-sizing: border-box;
}
.one-image {
width: 25%;
float: left;
border: 1px solid red;
}
.one-image img {
width: 100%;
border: 1px solid blue;
display: block;
}
#media screen and (max-width: 1068px) {
.one-image {
width: 33.33%;
}
}
#media screen and (max-width: 767px) {
.one-image {
width: 50%;
}
}
#media screen and (max-width: 600px) {
.one-image {
width: 100%;
}
}
<div class="one-image">
<img src="http://placehold.it/200x200">
</div>
<div class="one-image">
<img src="http://placehold.it/200x200">
</div>
<div class="one-image">
<img src="http://placehold.it/200x200">
</div>
<div class="one-image">
<img src="http://placehold.it/200x200">
</div>

Your images (<img> elements) are not expanding to the full width of the .image containers because you're missing this rule, which you can add to your CSS:
.image img {
width: 100%;
}
Here's your example code updated to show this working:
.image img {
width: 100%;
}
.f_left {
float: left;
}
#media only screen and (min-width: 354px) {
/* Smartphone view: 1 tile */
.image {
width: 100%;
}
}
#media only screen and (min-width: 708px) {
/* Smartphone view: 2 tile */
.image {
width: 50%;
}
}
#media only screen and (min-width: 1062px) {
/* Small desktop / ipad view: 3 tiles */
.image {
width: 33.3%;
}
}
#media only screen and (min-width: 1417px) {
/* Medium desktop: 4 tiles */
.image {
width: 25%;
}
}
<div class="image f_left">
<img src="http://www.devual.nl/project/gmsbase/img/cover.png" />
</div>
<div class="image f_left">
<img src="http://www.devual.nl/project/gmsbase/img/cover.png" />
</div>
<div class="image f_left">
<img src="http://www.devual.nl/project/gmsbase/img/cover.png" />
</div>
<div class="image f_left">
<img src="http://www.devual.nl/project/gmsbase/img/cover.png" />
</div>

Related

align two div in same line while screen size less than 768 px or smaller

I have a footer container. There are some menu items and two paddels(left and right) to scroll left and right the menu. There are one description text and one log link.
Now, if the screen size is more than 768px then all these three divs( menu, description text, log link) are in same line. Which is fine. But, if i choose screen size less than <768px then as per my application design will be like this below.
< Menu >
Description text Log link
Here is the screenshot for less than <768 px.
Now, description text and log link aren't in same line . Because of repair log width, menu inner wrapper is hided behind the screen. How to solve this?
Here is my css style for less than (768 px screen)
#media only screen and (min-width: 414px) and (max-width: 767px) {
.footerContainer {
height: 72px;
flex-direction: column;
.menu_item_outer_wrapper {
width: 390px !important;
height: 100%;
.paddles {
display: block;
.left-paddle {
transform: translate(-1%, -45%);
}
.right-paddle {
right:0;
transform: translate(10%, -45%);
}
}
.menu_item_inner_wrapper {
margin-left: 36px;
}
}
.footer-desc_log-section {
width: 100%;
.footer__description {
width: 60%;
margin-left: 8px;
}
.footer__description,
.footer__audit-log {
line-height: 32px;
}
}
.footer-desc_log-section {
width: 100% !important;
height: 100%;
}
}
}
#media only screen and (max-width: 768px) {
/* For mobile phones: */
div{
display:inline;
}
}
.div2{
float:right;
}
<body>
<div class="div1">Div 1</div>
<div class="div2">Div 2</div>
<body/>
You can check out this code just add display:inline; in the CSS of the div.

I don't want images to resize when I resize the browser

I have some images on my webpage. I originally put their sizes in pixels, e.g.:
<IMG src="image.png" width=700px height=100px>
When I used different machines with different screen resolutions, sometimes the page didn't look like I wanted it to.
I then switched to set the dimensions using percentages rather than pixels, e.g.:
<div class="logo_container">
<IMG src="image.png">
</div>
and
.logo_container img {
padding: 15px;
width: 37%;
position: relative;
}
The page now looks how I want it, but if I start to resize my browser window, the images shrink (whilst maintaining aspect ratio). I don't want this to happen.
I want the web page to look correct when the browser is full screen, but then I don't want images to shrink.
Thank you.
You should change the css based on the screen width:
<div class="logo_container">
<IMG src="image.png">
</div>
<style>
#media screen and (max-width: 540px) {
.logo_container img {
padding: 15px;
width: 100%;
position: relative;
}
}
#media screen and (min-width: 540px) and (max-width: 780px) {
.logo_container img {
padding: 15px;
width: 50%;
position: relative;
}
}
#media screen and (min-width: 780px) {
.logo_container img {
padding: 15px;
width: 30%;
position: relative;
}
}
</style>
Use em.
<img src="" alt="">
CSS:
.logo_container img {
width: 1em;
}
em is constant between all devices - it is always the same size in real life: see https://www.w3schools.com/cssref/css_units.asp for more info.
Just set the width of the image to a fixed amount of pixels:
.logo_container img {
width: 200px;
}

Add URL link in CSS background image - #media only screen

I have a flexible newsletter - 3 steps:
bigger than > 660 px
smaller < 600 px
smaller < 350 px
everything works excluding link on images
I have a CSS entry that looks like this:
http://mantykora.cleoni.com/~newsletter/2017/lak/Lak_EN.htm
#media only screen and (max-width: 660px) {
table.container { width: 600px !important; }
td.logo img { display:none; }
td.logo { background:#fff url(http://mantykora.cleoni.com/~newsletter/2017/lak/images/logo65.jpg) no-repeat 10px 10px; height: 60px;}
td.logo a {??????????????link to site???????????}
is it possible linking image on media screnn?
Use two elements, one to be shown on narrow viewports and one to be shown on wide viewports.
CSS:
.only-narrow { display: block; }
.only-wide { display: none; }
#media screen and (min-width: 600px) {
.only-narrow { display: none; }
.only-wide { display: block; }
}
HTML:
<div class="only-narrow" ><a href="..." ><img src="..." ></a></div>
<div class="only-wide" ><img src="..." ></div>

Using CSS to keep two images together on mobile

I am pretty new to HTML and CSS.
Right now I have a 4 column layout that has 4 images all next to each other on a desktop view and when in mobile, all the icons are stacked on top of one another. Here is an image to explain.
DESKTOP VIEW
I am not allowed to post more than one link, so I will use x's to explain.
This is desktop view using x's:
X X X X
This is the current mobile view using x's"
X
X
X
X
(all the images / icons are stacked on one another)
This is what I am trying to achieve using CSS:
X X
X X
(images are grouped together on one line)
I saw a post using float left and float right attributes targeted for small screen sizes. Not sure if that would work. I would love some help.
/* 1 column: 320px */
.autowide {
margin: 0 auto;
width: 94%;
}
/* 2 columns: 330px */
#media only screen and (min-width: 330px) {
.hot-icon-group {
float: left;
margin-right: 2.564102564102564%;
width: 48.717948717948715%;
}
.hot-icon-group:nth-child(2n+0) {
margin-right: 0;
}
}
/* 3 columns: 768px */
#media only screen and (min-width: 768px) {
.autowide .hot-icon-group {
width: 31.623931623931625%;
}
.autowide .hot-icon-group:nth-child(2n+0) {
margin-right: 2.564102564102564%;
}
.autowide .hot-icon-group:nth-child(3n+0) {
margin-right: 0;
}
}
/* 4 columns: 992px and up */
#media only screen and (min-width: 992px) {
.autowide .hot-icon-group {
width: 23.076923076923077%;
}
.autowide .hot-icon-group:nth-child(3n+0) {
margin-right: 2.564102564102564%;
}
.autowide .hot-icon-group:nth-child(4n+0) {
margin-right: 0;
}
}
<div class="autowide">
<img src="https://beaverbuilder.appletreeprinting.ca/highoctane/wp-content/uploads/2017/05/super-hero-icon.png" alt="" />
<img src="https://beaverbuilder.appletreeprinting.ca/highoctane/wp-content/uploads/2017/05/super-hero-icon.png" alt="" />
<img src="https://beaverbuilder.appletreeprinting.ca/highoctane/wp-content/uploads/2017/05/super-hero-icon.png" alt="" />
<img src="https://beaverbuilder.appletreeprinting.ca/highoctane/wp-content/uploads/2017/05/super-hero-icon.png" alt="" />
</div>
You can use media queries to apply specific CSS based on device or browser dimensions.
Replace the p tag with your divs.
p {
text-align: center;
}
.container {
max-width: 65rem;
margin: 2rem auto;
}
.grid-size {
display: flex;
flex-wrap: wrap;
}
.size1of4 {
width: 25%;
}
.size1of4:nth-of-type(even) {
background-color: green;
}
.size1of4:nth-of-type(odd) {
background-color: yellow;
}
#media all and (max-width: 768px) {
.size1of4{
width: 50%;
}
}
#media all and (max-width: 480px) {
.size1of4{
width: 100%;
}
}
<div class="container">
<div class="grid-size">
<div class="size1of4"><p>Content</p></div>
<div class="size1of4"><p>Content</p></div>
<div class="size1of4"><p>Content</p></div>
<div class="size1of4"><p>Content</p></div>
</div>
</div>

My responsive layout is not responding

I am attempting to implement a responsive layout based on the exmaples and code here: www.responsivegridsystem.com
I have wrapped it a couple of containers as I need a 960px content area centered in a 1000px container.
My intent is that with a width smaller then 960px, both containers just become 100% width. The layout is exactly what I want at full size, but it is not shifting like I want when smaller then 960px.
Current CSS (with some edits based on suggestions, still not working.):
.masterContainer {
position:relative;
margin:0 auto;
margin-top:-10px;
background-color:#FFF;
width:1000px;
overflow: hidden;
}
.pageContainer {
position:relative;
display:table;
margin:0 auto;
width:960px;
overflow:hidden;
}
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after {
content:"";
display:table;
}
.group:after {
clear:both;
}
.group {
zoom:1; /* For IE 6/7 */
}
/* GRID OF THREE */
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 70%;
}
.span_1_of_3 {
width: 30%;
}
#media only screen and (min-width: 481px and max-width: 960px) {
.masterContainer {
width:100%;
}
.pageContainer {
width:100%;
}
}
#media only screen and (max-width: 480px) {
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 100%;
}
.span_1_of_3 {
width: 100%;
}
}
HTML
<div class="masterContainer">
<div class="pageContainer">
<div class="section">
<div class="col span_3_of_3" id="header">Header
</div>
<div class="col span_3_of_3" id="slideshowContainer">Slideshow
</div>
</div>
<div class="section group">
<div class="col span_2_of_3" id="contentArea">
This is column 1
</div>
<div class="col span_1_of_3" id="rightColumn">
This is column 2
</div>
</div>
<div class="col span_3_of_3" id="footer">Footer
</div>
<div class="col span_3_of_3" id="bottom">
</div>
</div>
</div>
Is something wrong with my #media code or did I break it somewhere else?
Your media queries are telling IDs to do something, while your HTML has them as classes. Change it to something like this:
#media only screen and (max-width:960px){
.masterContainer {width: 100%;}
.pageContainer {width: 100%;}
}
Here is a fiddle with your code and the query. I gave them background colors for the example.
JS Fiddle with your code
From what you've posted there is no #media codes... You cannot have a specific width's set if you intened for the page to be responsive ex. masterContainer width 1000px.. youll need to redo that for example:
#media (min-width: 700px), handheld and (orientation: landscape)
{
.masterContainer{
width:60%; // or whatever you may need
}
}
have a look at some examples.
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
You need to specify it via #media queries:
#media screen and (max-width: 959px) {
.masterContainer,
.pageContainer {
width: 100%;
}
}
You dont have media queries in your css.
Create separate files for diffrent screen sizes and put styles in there. Thats the easiest way.
And read this article. It will help you to understand how media queries work.
csstricks media queries
The reason it doesn't work is this:
#media only screen and (min-width: 481px and max-width: 960px) that is a wrong query.
It should be:
#media screen and (min-width:481px) and (max-width:960px)
You can't combine the min and max like you had it.