i am creating a responsive web design containing images....i want to know if there is any way i can crop images when they overlap i.e if i have two images in one line image 1 and image 2
image 1 is at the left and image 2 is at right and i start lessening width of my browser, and when image 2 reaches image 1, image 2 starts cropping or hiding or whatever....how m i going to do that?
here is my code for what i am trying:
#logo{
float:right;
margin:88px 0 0 70px;
position:absolute;
}
#header-add{
float:right;
margin:35px -10% 0 0;
cursor:pointer;
}
Logo is image 1 and header-add is image 2
Rather than crop the image, I'd suggest simply setting your CSS to set the width of the images appropriately when the browser width is decreased. This way you don't have to worry about cropping.
For example (values arbitrary, but percentage-based, which I find best for responsive design):
#media screen and (max-width: 768px) {
#header-add {
width: 40%;
}
}
#media screen and (max-width: 480px) {
#header-add {
width: 25%;
}
}
If you don't want to set the width of the images via CSS, you can essentially "crop" the images if you enclose each of them in a div and you can set overflow:hidden on the div, and then set the width of the div in the CSS (like the aforementioned image width example).
Hope it helps!
Addition:
In answer to your comment about cropping from the left, here's how I would recommend doing it. The downside is that you have to add an explicit height on the div that crops the image, but it should work for you.
The HTML:
<div id="crop_div">
<img src="foo.jpg" alt="bar" />
</div>
The CSS:
#crop_div {
float: right;
height: 100px; /* Needed since contents use absolute position */
overflow: hidden; /* To crop the img inside of it */
position: relative; /* Set for img position below */
width: 400px;
}
#crop_div img {
position: absolute; /* To anchor it on the right */
right: 0;
}
#media screen and (max-width: 768px) {
#crop_div {
width: 40%;
}
}
clip() and overflow: hidden for masking for sure your content.
min-width and/or max-width to manage the width of each div when the sum of both would be too large for the width of the container.
Related
I have a site here: http://ideedev.co.uk/newseed/design/ and the banner at the top works great and just how I want it to - the banner image it 100% width of the site and the text floats in the middle and centre at all sizes.
However, for smaller mobile devices, I want to adjust the height of the image, so it scales down and keeps the ratio of the image in tact with the text still sticking in the middle. Can anyone help?
My HTML is here:
<div id="absolute1111" style=" background: url(<?php echo $feat_image; ?>);">
<div class="centerd1111">
<h1><?php the_title(); ?></h1>
</div>
</div>
My CSS is here:
#absolute1111 {
position:relative;
width:100%;
height:50%;
display:table;
color: #fff;
background-size: cover !important;
background-repeat: no-repeat !important;
background-position: 50% !important;
}
.centerd1111 {
display:table-cell;
vertical-align:middle;
text-align:center;
height:500px;
padding: 0 50px 0 50px;
}
Many thanks :)
Using image as a background image won't allow you to scale down image with screen size as you have to adjust the height manually to scale down the image which is not a good practice.
Using the image in HTML browser will be able to scale down the image, keeping the aspect ratio intact.
In your case, you can use media query for mobile to adjust the image height so the whole image scales down and the full image is shown.
Here is the code for the same:
#media only screen and (max-width: 500px){
.centerd1111 { height: 180px; }
}
Let me know if this works for you.
Thanks.
instead of background css attribute, you can put the image as element, in this way, you can manipulate it more easier. this if my fiddle. but for this fiddle, I only make it for mobile, so you need to apply this to #media query for mobile display.
https://jsfiddle.net/bdv2L0a0/
this fiddle, I made it that, the image's height will follow its proportion when the display becoming smaller
.background img {
width: 100%;
height: auto; //default value, no need to declare this
}
If you know the ratio of the image (proportion between height and width), you can do this:
.your-container {
overflow: hidden;
height: 0;
padding-bottom: 46.406570842%; /* image height / image width */
}
This is the trick used to embed iframes that maintain ratio in different viewport sizes. It's based on the fact that when you give a percentage value to padding property, it applies this percentage to the element width.
Also, you don't need to give display: table to center the text. You can just do this:
.your-container {
text-align: center;
position: relative;
}
.your-centered-text {
position: absolute;
left: 0;
right: 0;
top: 50%;
transform: translateY(-50%);
}
See this jsfiddle.
I have two boxes, each with width: 50%;, placed next to each other with float. One has a white background, the other a grey background.
As the page width shrinks the boxes stay beside each other. At some minimum size I don't want the boxes to get any smaller. Here they should jump down under each other.
They do this fine. But the white and grey boxes keep their 50% width - at this point they should rather fill the whole width 100%.
The issue is seen here just below the video.
(The min-width does not do any difference here at the moment, and is just set to some arbitrary value (100px) on the page.)
What is the proper way for this responsive effect, so the products are full-sized on small screen but can stand beside each other on large screens?
I find it easier to approach this from a mobile-first setup. Set the boxes to 100% width until the breakpoint where you want them to start forming columns. For example,if you wanted them to start forming columns at 600px device-width and greater:
.column_selector {
box-sizing: border-box;
width: 100%;
}
#media all and (min-device-width: 600px) {
.column_selector {
width: 50%;
}
}
Also, if you're going to use percentages for widths, I'd recommend using box-sizing: border-box to account for the padding in your width calculations.
Use #media to set some special rules for different window dimensions. Something like:
.div1 {
float: left;
width: 50%;
}
.div2 {
float: left;
width: 50%;
}
#media (max-width: 600px) {
.div1 {
width: 100%;
}
.div2 {
width: 100%;
}
}
Here's a fiddle.
What is the best way to keep the <img /> ratio while it is responsive and gets a min-height?
What I want is to set a min-height when screen-size is lower than 620px and the picture has to be horizontally centered while not loosing the ratio.
See my code and fiddle: http://jsfiddle.net/M2Qkh/
<img src="http://farm4.staticflickr.com/3484/3718426345_6d4a540840_b.jpg" />
<style type="text/css">
img {
width:100%;
}
#media only screen and (max-width: 620px) {
img {
display:block;
min-height:150px;
}
}
</style>
try to make it a background image, then apply the css to the container div or span:
.carousel-img {
background-image:url(http://farm4.staticflickr.com/3484/3718426345_6d4a540840_b.jpg);
background-repeat:no-repeat;
max-width:100%;
height: 300px;
overflow: hidden;
background-position: center 20%;
background-repeat: no-repeat;
background-size:cover;
display: block;
}
Note the background-position is in the center and 20% more to the top.
Also note the important background-size to be 'cover'.
The cover effect will some what cover the hole width space, and some how reserve its ratio (off course you will lose some of the left and right edges of the width, but thats the trade-off maintaining the ratio).
Edit:
a fiddle created by the OP to illustrate both effects:
http://jsfiddle.net/M2Qkh/4/
At media-query min-width 620px, you are now essentially setting both the height and the width of the image which is going to cause it to change 'ratio'.
Once the min-height: 150px takes effect then the image will start to squash as you have the width set to 100%.
If you don't want this to happen you need to change the image width in the media-query to width: auto; this will tell it to maintain the correct aspect ration whilst having a height set to 150px. As a result the image will start to be cropped (overflowing the container) rather than squashed. If this is the effect you want you will need a couple of other changes as well. You will also need to set an overflow: hidden; on a container for the image, otherwise you will get a horizontal scrollbar.
#media only screen and (max-width: 620px) {
img {
display:block;
height:150px; /* use height not min-height */
width: auto;
}
.img-wrapper {overflow: hidden;}
}
I need the following:
emtpy div with no content
background image set to the div the
background image to be fluid/responsive on re-size I cannot set fixed
dimensions on the div
Everything I try fails to force the div open to support the size of the background image. Any help is greatly appreciated...
http://www.everymountain.us/
<header id="header">
<div class="wrapper">
<div class="inner">
<div class="top_banner"></div>
</div>
<div class="clear"></div>
</div>
</header>
.front #header .top_banner { background: url('images/bg_front.jpg') no-repeat; background-size: cover; }
The way to lock a height's aspect ratio to it's fluid width is to use padding-top or padding-bottom percentage. This is because all padding percentages are of the the element container's width. Your background image is 960 x 520, so the height is 54.166666666667%.
html
<div class="top_banner"></div>
css
.top_banner {
background-image: url('images/bg_front.jpg');
background-size: 100%;
width: 100%;
padding-top: 54.166666666667%;
height: 0;
}
Example: http://jsfiddle.net/SsTZe/156/
Essentially the same question: CSS fluid image replacement?
You can handle it after applying CSS
#DivName{
background-size: auto auto;
}
here first auto is for width and second is for height
Since this is a top google result for creating fluid-height divs in general (not just empty ones like the question specifies), I wanted to leave a CSS Calc solution that lets you put content into the div (the padding trick forces it to be empty):
.my-div {
background: #ccc url(https://link-to-image/img.jpg) no-repeat 50% 0;
background-size: 100% auto;
width: calc(100vw - 350px);
height: calc((100vw - 350px) * 0.468795); /* replace the decimal with your height / width aspect ratio */
}
Try to use medie queries in your CSS for different screen sizes to handle different fixed heights.
For example:
#media (min-width: 1200px) {
div { height: 3em; }
}
#media (min-width: 768px) and (max-width: 979px) {
div { height: 2em; }
}
#media (max-width: 767px) {
div { height: 1.2em; }
}
#media (max-width: 480px) {
div { height: 1em; }
}
etc. what you need to customize. You can leave the div width 100% to fit for all screen and the background-size:cover. You can also make different size backgrounds (diff. files) for each screen sizes to give less size to your website for mobile or tablet devices.
For my personal site http://stevengeorgeharris.com I have created a single page design with several divs stacked on top of each other. The divs are width: 100% and height: 100% so they scale with the browser, within each div I am using flexslider to create a fullscreen slideshow.
My problem is when the browser gets narrower the images within the flexslider container scale down leaving whitespace below.
This is the CSS for the flexslider image.
.flexslider .slides img {width: 100%; height:auto; display: block;}
Is there anyway to make the images act like this http://css-tricks.com/examples/FullPageBackgroundImage/css-1.php
For this you should use media query. You can read more about media query here : https://developer.mozilla.org/en-US/docs/CSS/Media_queries
I did what you wanted to do; with another picture and you can see the final result here: http://jsbin.com/olakit/2
Here is the code (the original picture is 1024 x 683 px ):
img {
width: 100%;
height : 100%;
}
#media (min-width: 2000px) {
img{
height: auto;
}
}
Notice that the "min-width" should be more than the picture's width.