I'm working on my first website. I've created a big image banner and it's working but I have a problem with setting his height. When I try to do this with % height my banner disappears. I would like to make it responsive and make it shorter when the window is small. Here is my code and CSS styles for container div:
#slides-container
{
width: 100%;
height: 400px;
margin: 0 auto;
position: relative;
}
#slides-container>img
{
width: 100%;
height: 100%;
position: absolute;
max-width: 100%
}
#slides-container>.arrow-button
{
position: absolute;
width: 50px;
height: 50px;
border: none;
border-radius: 25px;
top: 200px;
background: none;
color: white;
font-size: 20px;
}
#slides-container>#button-next:hover
{
box-shadow: 10px 0px 20px 0px black;
}
#slides-container>#button-previous:hover
{
box-shadow: -10px 0px 20px 0px black;
}
#slides-container>#button-previous
{
position: relative;
float: right;
}
.slide-fade
{
animation-name: fade;
animation-duration: 0.2s;
}
#keyframes fade
{
from{opacity: 0.4}
to{opacity: 1}
}
<div id="slides-container">
<img class="slides slide-fade img-responsive" src="img/1.jpg"/>
<img class="slides slide-fade img-responsive" src="img/2.jpg"/>
<img class="slides slide-fade img-responsive" src="img/3.jpg"/>
<img class="slides slide-fade img-responsive" src="img/4.jpg"/>
<img class="slides slide-fade img-responsive" src="img/5.jpg"/>
<button class="arrow-button" onclick="plusIndex(-1)" id="button-next">❮</button>
<button class="arrow-button" onclick="plusIndex(1)" id="button-previous">❯</button>
</div>
You can use vh instead of %. It is the other way to make the height responsive in every view height. Relative to 1% of the height of the viewport*
Related
attached a js fiddle to show my issue. I want the orange image to take all the top area of the card and not have padding on the top and sides. the image should show from the very top and takes all the sides with no space
link to fiddle
.pricing-card {
color: black;
width: 100%;
max-width: 330px;
max-height: 463px;
flex-flow: column;
background: #ffffff 0% 0% no-repeat padding-box;
box-shadow: 0px 10px 70px #2e231d1a;
border-radius: 50px;
opacity: 1;
min-height: 550px;
margin: auto;
}
#logo {
top: 50px;
position: absolute;
left: 50px;
}
#rectangle {
max-width: 330px;
}
<div class="price-container">
<div v-if="checkDomainTrial" class="price-text">
Get your entire first month free on us!
</div>
<div class="header">
<div id="wait">Wait! Don't go yet!</div>
</div>
<div class="pricing-card">
<div class="pricing-card-header">
<img id="rectangle" src="https://i.ibb.co/FVkvCv5/Rectangle-cancellation.png" alt="" />
img1
img2
When you click on the modal it opens the image like lightbox but the problem is that it's scrollable as well as images don't fit the screen. Here is the code:
HTML
<div class='row'>
<div class='col-md-3 img-content' *ngFor="let image of images let i = index">
<img (click)="openModal();currentSlide(i+1)" class="hover-shadow cursor img-responsive"
src="http://res.cloudinary.com/dfg5p1pww/image/upload/v{{image.imgVersion}}/{{image.imgId}}">
</div>
</div>
<div id="myModal" class="slide-modal">
<span class="close cursor" (click)="closeModal()">×</span>
<div class="slide-modal-content">
<div class="mySlides" *ngFor="let image of images let i = index">
<img class="img-responsive1" src="http://res.cloudinary.com/code/image/upload/v{{image.imgVersion}}/{{image.imgId}}" style="width:100%">
</div>
<a class="prev" (click)="plusSlides(-1)">❮</a>
<a class="next" (click)="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption"></p>
</div>
<div class="slide-column" *ngFor="let image of images let i = index">
<img (click)="currentSlide(i+1)"
class="img-responsive" src="http://res.cloudinary.com/code/image/upload/v{{image.imgVersion}}/{{image.imgId}}" style="width:100%">
</div>
</div>
</div>
CSS
.slide-column {
float: left;
width: 25%;
}
.slide-modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 10px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
}
.slide-modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 1200px;
}
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.mySlides {
display: none;
}
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
.next
{
right: 0;
border-radius: 3px 0 0 3px;
color:#ffffff !important
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
color:#ffffff !important
}
img {
margin-bottom: -4px;
max-width:100%;
}
.img-responsive {
width: auto;
height: 250px;
}
.img-responsive1
{
height:100%;
width:auto;
vertical-align: top;
}
The problem is inside those classes slide-modal, slide-modal-content, img-responsive1
Also in the above images, you can see how does it look like? We use Bootstrap 4 in this project with Angular. How to fix the size of the modal and make it to fit the full screen and at the same time allow images to fit to the screen (without scrolling and if image is long then change the width for showing it correctly instead of changing just height in such a way as it's shown in the image)?
I would consider using Bootstrap's built-in CSS classes for responsiveness as opposed to rolling your own CSS selectors. Responsiveness, in Bootstrap, is based on screen width not height since Bootstrap utilizes width-based CSS Media Queries. This will solve the issue with the horizontal scroll for your images since images will automatically scale to their parent container's width. To make your images responsive in Bootstrap simply apply the .img-fluid class to them:
<img src="..." class="img-fluid" alt="Responsive image">
This .img-fluid class is a good default for your images moving forward so they never overflow your parent container's width.
Directly from Bootstrap's documentation:
"Images in Bootstrap are made responsive with .img-fluid. max-width: 100%; and height: auto; are applied to the image so that it scales with the parent element."
Hopefully that helps!
I have been trying to make a photo fill a div that is the container for a slideshow. I cannot seem to make it happen and I am sure that I am missing some small detail.
I have tried changing the width and height settings for the image as well as the container itself.
CSS
img {width: 100%;
height: 50%;}
.slideshow-container {
max-width: 1000px;
margin: auto;
}
.slideshow-container div {
margin: 0px auto;
width: 100%;
text-align: center;}
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -22px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
#-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
HTML
<div class="slideshow container">
<div class="mySlides">
<img src="images/education.jpg" alt="children doing classwork">
<div class="text">Education</div>
</div>
<div class="mySlides">
<img src="images/family.jpg" alt="a mother father and son at the beach">
<div class="text">Family</div>
</div>
<div class="mySlides">
<img src="images/community.jpg" alt="community standing together">
<div class="text">Community</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<div style="text-align: center;">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
Whenever I change the width to 100%, the entire image grows larger than the size of the screen. What i want is for the image to take up 100% of the width but only about 50% height of the entire screen. I am think maybe the container needs to be resized but I tried that too to no avail. The other thing that happens is if I do not leave the width at 100%, the image stops responding to different screen sizes. That's just something to keep in mind while provide with assistance.
U can use a object-fit for this.
Your code should look like:
.slideshow-container img
{
object-fit: cover;
}
Link to docs MDN
you have 2 small issues to fix:
first thing is to fit mySlides class height to make it 50% of screen.
something like this:
.slideshow-container .mySlides img {
width: 100%;
height: 100%
object-fit: cover;
}
.slideshow-container {
max-width: 1000px;
margin: auto;
}
.slideshow-container .mySlides {
margin: 0px auto;
width: 100%;
text-align: center;
height: 50vh;
}
in img: i used 100% for width and height, and cover fit to make it cover its container.
for mySlides div: i used height of 50vh to make it fit half of screen height.
you can simply change it and make its height static:
something like:
height: 500px;
I am a complete newbie to HTML & CSS3.
I am learning as I go along and try to build a new webpage. My image gallery works in all browsers except Opera and the width of a portrait image is distorted only in Opera, but works fine with a landscape image.
HTML
<!-- Gallery Image 1 -->
<div class="thumbox">
<a href="#openphoto1">
<img src="http://www.ghyllfarm.co.uk/_fiddle/image_1_thumb.jpg" width="110" height="110" alt=" ">
</a>
<div id="openphoto1" class="modalDialog">
<div id="landscapephoto">
<a href="#close" title="Close" class="close">X
</a>
<img src="http://www.ghyllfarm.co.uk/_fiddle/image_1.jpg" width="780" height="520" alt=" ">
<div class="photolabel">Landscape Image
</div>
</div>
</div>
</div>
<div class="thumblabel">Click to open
</div>
<!-- Gallery Image 2 -->
<div class="thumbox">
<a href="#openphoto2">
<img src="http://www.ghyllfarm.co.uk/_fiddle/image_2_thumb.jpg" width="110" height="110" alt=" ">
</a>
<div id="openphoto2" class="modalDialog">
<div id="portraitphoto">
<a href="#close" title="Close" class="close">X
</a>
<img src="http://www.ghyllfarm.co.uk/_fiddle/image_2.jpg" height="780" width="520" alt=" ">
<div class="photolabel">Portrait Image
</div>
</div>
</div>
</div>
<div class="thumblabel">Click to open
</div>
CSS
img {
width: 100%;
height: 100%;
width: auto\9; /* ie8 */
}
.thumbox {
width: 110px;
height: 110px;
Margin: 0px auto 0px auto;
}
.thumblabel {
width: 110px;
height: 20px;
Margin: 10px auto 10px auto;
font-family:Tahoma, Geneva, sans-serif;
font-size: 12px;
text-align: center;
color:#060;
}
.modalDialog {
position: fixed;
font-family: Arial, Helvetica, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.6);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: auto;
}
.modalDialog > div {
position: fixed;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
padding: 15px 15px 5px 15px;
border-radius: 10px;
background: #fff;
}
#landscapephoto {
width: 50%;
height: auto;
}
#portraitphoto {
width: auto;
height: 70%;
padding-bottom: 40px;
}
.close {
background: #606061;
color: #FFFFFF;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
-moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000;
}
.close:hover { background: #00d9ff; }
.photolabel {
width: 300px;
height: 20px;
Margin: 10px auto 10px auto;
font-family:Tahoma, Geneva, sans-serif;
font-size: 14px;
text-align: center;
color:#060;
}
If I understand you correctly, you're basically trying to maintain the aspect ratio of your portrait and landscape images when the window gets resized. Adapting this answer to a very similar question for your case, what you need to do is use viewport units, something like this:
#landscapephoto {
width: 50vw; /* 50% of viewport width */
height: 37.5vw; /* = 50 * (3/4), i.e. three-quarters of viewport width */
}
#portraitphoto {
width: 46.67vh; /* = 70 * (2/3), i.e. two-thirds of viewport height */
height: 70vh; /* 70% of viewport height */
padding-bottom: 40px;
}
Here's the forked fiddle:
https://jsfiddle.net/7cb24j8d/
I've kept your initial percentages of landscape width (50%) and portrait height (70%) and set the other width and height to be relative to those, but obviously you'll be able to adjust these numbers to your liking. You'll also have to adjust the div.photolabel, as it's currently moving off-centre relative to the image when you resize (but that's a different question...). You should also check caniuse to make sure your target browsers all support viewport units.
I have a carousel with images/descriptions in it and my height:auto does not work properly. Height computed is too big
JSBin: JSBin
I can only guess that this is because my .shadow class which is relative with height 150px.
Please take a look on it.
Edit: code as requested
This is result of one item from carousel
<div class="carousel2">
<div class="carousel">
<div class="owl-carousel owl-theme" id="owl-example" style=
"opacity: 1; display: block;">
<div class="owl-wrapper-outer">
<div class="owl-wrapper" style=
"width: 4092px; left: 0px; display: block; -webkit-transform: translate3d(0px, 0px, 0px); -webkit-transition: all 200ms ease; transition: all 200ms ease;">
<div class="owl-item" style="width: 341px;">
<div class="pc">
<div class="c">
<img alt="image" src=
"http://www.ramp-alberta.org/_system/ThumbnailCache/UserFilesImageAug~16~Site~1_004jpg.300.-1.-1108757834.jpg">
<div class="shadow">
<div class="description">
Event1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is my css
.carousel2
{
overflow: hidden;
/* height:400px; */
background-color: #344754;
}
.carousel
{
width: 1364px;
float: left;
height: auto;
}
.shadow
{
position: relative;
bottom: 150px;
left: 0;
right: 0;
background: rgba(222,103,21,0.7);
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#B2344855', endColorstr='#B2344855');
height: 150px;
vertical-align: middle;
z-index: 1;
width: 100%;
text-align: center;
}
.pc{
/* border: blue 1px solid; */
width: 1%;
display: table;
margin: auto;
height: auto;
overflow: hidden;
}
.c
{
overflow: hidden;
}
.description
{
padding-top: 15px;
font-family: "FSRufus";
font-size: 30px;
font-weight: bold;
color: white;
}
.owl-item
{
overflow: hidden;
}
You should give class carousel2 a min-height so that CSS will know till what it needs to scale image. Try to use exact size images to save processing time. Also remove height from class Shadow. This should help.