I have the following html:
<div id="thumbs">
...8 image tags width and height of images 100 x 100px
</div>
The related CSS is:
#thumbs
{
overflow:hidden;
float:left;
position:relative;
background-color:white;
height:100px;
width:100%;
}
#thumbs img
{
padding:5px;
}
When I turn my resolution down to the lowest setting -800 x 600, the last image -img8 jumps over to the next line. I would like all the images to show in one line. Is this possible?
You have 8 images equaling 100px wide each. The width of the window is 800px. You also have 5px padding on each image which then makes the whole structure 880px wide. Reduce each image size to 90px and you should be good. Also take into account the scrollbar if there will be scrolling that is another 20-30px.
have you tried setting a min-width on the container
#thumbs {min-width: 880px;}
width derived from 8 x 100px wide images with 10px padding (5px left + 5px right) each.
Have a look at responsive web design techniques that may help.
The problem you have is you're trying to put 880px into a space of 800px, this is 800px for the images then padding of 10px for each image you have in the div giving the additional 80.
The basic solution I would use is to put in a media query like
#media screen and (max-width: 810px) {
#thumbs img {
padding: 3;
height:80px;
width:80px
}
}
What this saying is if the width of the window is under 810px then apply this styling to the elements. Why 810px? To be safe basically.
To keep the consistency of the design we do need to reduce the image sizes and the padding, you will need to play with these variables depending on how they actually look on the screen.
Related
<body>
<div>
</div>
</body>
div {
width:10vw;
height:10vh;
}
Is there any way to set this div that will be 10% of the full available window ? (When the window browser cover all the screen).
Last time I did it with script in JS but I believe nobody does this and only use css.
Instead I can use px but even with media queries I won't know how it will looks like in other screens.
Anoher option: Using max/min-height/width, but still I don't know what value I need to set from avoiding from the div shrinking (every screen is different px) or just let the div shink to some point - but either at this way I don't know how it will look on other screens.
Thanks.
By specifying the min-height and max-width, you'll be able to control its size.
div {
max-width: 10vw;
min-height: 10vh;
}
Empty div elements have a height of 0 by default so the min-height keeps it from shrinking to nothing.
div elements are also display: block; by default, which means the width is 100% of the containing element. Defining the max-width will restrict that dimension of the div.
You should use max-height/min-height/width in percentages.
div {
width:10%;
max-height:10%;
min-height:10%;
position: fixed;
border:1px solid blue;
}
I need assistance finding the line of CSS I need to modify to increase the width of the main content container at smaller screen sizes. The problem I'm having is that in smaller screen widths the content does not extend to the width of the screen. Instead there is a pretty wide right hand margin. I would like to extend the content from the left side of the screen to the right to make better use of the screen space. Can someone tell me what line of code I need to change to fix this? Thank you!
The site is - https://www.shiftins.com
In styles.css, line 2982:
.content,
.content-sidebar-sidebar .content,
.content-sidebar-sidebar .content-sidebar-wrap,
.sidebar-content-sidebar .content,
.sidebar-content-sidebar .content-sidebar-wrap,
.sidebar-primary,
.sidebar-secondary,
.sidebar-sidebar-content .content,
.sidebar-sidebar-content .content-sidebar-wrap {
width: 100%;
}
On line 1552:
.page.sidebar-content .entry {
padding: 40px 40px 40px 0;
}
Combined, these produce the effect you're seeing.
Changing the second rule to padding: 40px 0 40px 0; removes that large right padding but the form is still clipped. The form is contained in an iframe and is fixed at 500px wide. Based on the structure, I'm guessing the form is out of your control. Adding min-width:500px; to the second rule makes the page width wider than the screen, but prevents the clipping of the form.
I have a gif to use in a header and have been able to place it with html however, I cannot center it and would like to take advantage of the max width 100% to account for smaller screen sizes. Img src makes the GIF too large on small screens making a scroll bar. I am fairly new to CSS and have not found the answers so far. It is for code injection in squarespace.
Use margin:auto on your gif to make it centered horizontally. You can also use div instead of img tag and use background-image property.
See here, this is a full out demo:
h1{text-align:center;
background-image:url('http://www.liveside.net/wp- content/images/archive/2008/01/hackspacesblogbkground_2.jpg');
background-repeat:no-repeat;
background-size:cover;
box-shadow:3px 4px 2px #000;
max-width:850px;
width:100%;
margin:0 auto;
}
click on the pic and see what happens.
http://codepen.io/damianocel/pen/dYKxgW
You will just have to set your max-width on the relevant meia queries.
I have a div containing an image (img) element, which extends for 100% width inside it. I would like to specify a maximum height for the div, and hide the parts of the image exceeding this height. But I also want to keep this image centered vertically inside the div to show only its central part.
For example, if browser width is 1200px and image aspect ratio is 4:3, image should display (1200x900)px. But if we want to crop height to 300px only and center vertically, image should position at -300px inside the div (and the div should hide 0-300 and 600-900 of the image height). Similar thoughts can be done for other widhts.
I'm pretty sure this can be easily done with javascript, but I would like to know if there is a way to do it with CSS too. Thanks in advance!
My take on this: http://codepen.io/vsync/pen/DpmnK
HTML
<div class='box'>
<img src="http://www.biztalk360.com/Events/BizTalk-Innovation-day-2014-Norway/images/banner.jpg">
</div>
SCSS
.box{
// this is the image container distentions
width:100%;
height:100px;
// The magic
> img{
position:absolute;
z-index:-1;
top:50%;
left:50%;
width:100%;
transform:translate(-50%, -50%);
&.max{ width:auto; height:100%; }
}
}
javascript (this is only for responsiveness)
var photo = document.images[0],
container = document.querySelector('.box');
$(window).on('resize.coverPhoto', function(){
requestAnimationFrame(checkRatio);
});
function checkRatio(){
var state = photo.clientHeight <= container.clientHeight &&
photo.clientWidth >= container.clientWidth;
photo.classList[state ? 'add' : 'remove']('max');
}
You may want to look at this question : Resizeing an oversized image using overflow:hidden and keep the aspect ratio
http://codepen.io/gcyrillus/pen/Grbxg
.grid_3 { width:260px; margin:0 20px; float:left; text-align:center;
overflow:hidden;background:rgba(255,255,255,0.02);}
.grid_3 a {
display:block;
height:171px; border:solid 2px #FFFFFF;
line-height:168px;
overflow:hidden;
margin-bottom:10px;
}
.max-img-border { width:100%; margin:-100% 0;vertical-align:middle;
}
here is another pen , exploring this , vertical-align:middle and an image with virtually no height in the flux.http://codepen.io/gc-nomade/pen/DxCgv
Of course , image set in background center is easy if it has no meaning in your content.
So you want the div to function as a viewing window for your image? This sounds like image sprites (a large pic of icons put together where each icon is displayed individually) but with a larger image:
http://www.w3schools.com/css/css_image_sprites.asp
If you provide a JSFiddle, I can give you something more specific.
I have two css columns for my website they fit inside a main container, with a width of 75% that is centered. I want the right container to be at least 300px wide but to expand if there is room in the browser (my advertisement is 300px wide) and the left one to fill the rest of the space plus some space between them. This is the CSS I have so far,
#body_container{
margin: 200px auto 0 auto;
width:75%;
}
#left_container{
float: left;
width: 63%;
padding:5px;
margin-right:15px;
}
#right_container{
float:left;
width: 32%;
padding:5px;
margin-right:15px;
}
It is kind of working, but on smaller browsers (mine is quite wide so I just noticed this when viewing it on a smaller monitor) the right column is pushed down below the left one :/ anyone have any ideas? thanks in advance. also if you need to see more source code it is at http://sunnahspace.com but here is a forewarning, it is not viewable in IE at all.
It's expected behavior - you're using fixed-size margins and paddings, which means that at a certain point, the total 50px of padding and margin from your two columns will be greater than the 5% of width that your columns don't take up, and will bump into each other. Unfortunately, there's not much that can be done besides specifying a min-width, or using CSS media queries.