I want my bootstrap carousel to take up the whole page of the user entering my site. However, with aspect ratios and resolution differences between monitors, I was wondering what is the best way to go about this?
I think I should first choose images of relatively the same size to start off. This is what I have so far.
css:
img {
background-size: cover;
background-position: center center;
background-repeat:no-repeat;
width: 100%;
height: 100%;
object-fit: cover;
}
What if the images I am using have a super high resolution. Will this not fit on the user's page?
I believe this will work , but I can't be sure .
but you can see it here :
http://jsfiddle.net/heyallanmoreno/7tdvu/4/
<section class="block">
<div id="myCarousel" class="carousel slide">
<div class="carousel-inner">
<div class="active item">
<img src="http://lorempixel.com/1024/750" alt="Slide1" />
</div>
<div class="item">
<img src="http://lorempixel.com/1024/750" alt="Slide2" />
</div>
<div class="item">
<img src="http://lorempixel.com/1024/750" alt="Slide3" />
</div>
</div>
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
</section>
and ,
.carousel .item {
width: 100%; /*slider width*/
max-height: 600px; /*slider height*/
}
.carousel .item img {
width: 100%; /*img width*/
}
/*add some makeup*/
.carousel .carousel-control {
background: none;
border: none;
top: 50%;
}
/*full width container*/
#media (max-width: 767px) {
.block {
margin-left: -20px;
margin-right: -20px;
}
}
Hope this will help you.
Related
I created a carousel with images inside. But one of the images appear to be very big while the other is blur but fits well. I tried resizing with CSS but it's not working. What should I do?
Here is what I mean
This First screenshot shows the image fits wellshows image fits well
while in this screenshot, the image is big and it is cut off from the carousel
shows image is cut off from carousel
Here is what I tried
<style type="text/css">
.wrapper{
font-family: Nunito;
background-repeat: no-repeat;
height: 100%;
background-position: center;
background-size: cover;
overflow: hidden;
position: relative;
}
#carouselExampleIndicators{
max-width: 100%;
position: relative;
margin: auto;
margin-top: 0%;
}
.carousel-item {
padding: 10px;
max-width: 100%; /* Maximum width */
margin: 0 auto;
}
.carousel-inner {
width: auto;
height: 370px;
max-height: 370px !important;
position: relative;
}
.carousel img {
position: relative;
top: 0;
min-width: 100%;
height: auto;
max-width: 100%;
}
</style>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" style="background-color: #eeeeee;">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row" style="width: 100%;margin: 0 auto;">
<div class="col-md-6">
<div class="desc1">
<h4 style="color: #081139;">LET'S GO!</h4>
<p style="color: #081139;">Everyone needs to be on their toes in order to fight and stamp out bad eggs in the world</p>
</div>
</div>
<div class="col-md-6">
<div class="img1" style="margin: 0 auto; padding: 10px;">
<img id="img1" src="Image/Carousel/singlestc.png" alt="First slide" height="30" />
</div>
</div>
</div>
</div>
<div class="carousel-item">
<div class="row" style="width: 100%;margin: 0 auto;">
<div class="col-md-6">
<div class="desc2">
<h4 style="color: #081139;">WE CARE</h4>
<p style="color: #081139;">We are the world, lets make it a better place for the younger generations</p>
</div>
</div>
<div class="col-md-6">
<div class="img2">
<img id="img2" src="Image/Carousel/SNC.png" height="30" alt="Second slide"/>
</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
You are setting the width of 2 images to be 100% of the parent, and the reason it is being cut off is .wrapper class has a style of overflow: hidden, so your images are sizing properly but the overflow is hidden.
See example: https://imgur.com/a/D5Pfw0S
If you want to retain this fixed height, add styling for the .img1 and .img2 classes (Or create 1 img wrapper class which I world recommend more) and define the height on those, that way you can give the img elements a height of 100%, and set the width to be the variable (auto).
.img1, .img2 {
height: 370px;
max-height: 370px !important;
}
/* Or do this and add the class in place of img1 and img2 */
.img-wrapper {
height: 370px;
max-height: 370px !important;
}
.carousel img {
position: relative;
top: 0;
width: auto;
height: 100%;
}
I would however recommend editing your images to be a uniform size. That way there is no major disparities in the design.
I'm new in HTML, CSS, and Bootstrap and I'm trying to create a carousel for my page.
The carousel is working, but the images are not fitting to the page. The size is too big (height and width) and I'm trying to fit but it's not working properly.
My codes are:
.carousel-inner img{
width:100%;
height: 40%;
}
.carousel-caption {
position: absolute;
top: 60%;
transform: translateY(-60%);
}
.carousel-caption h1{
font-size:470%;
text-transform: uppercase;
text-shadow:3px 3px 15px #000;
}
.carousel-caption h3{
color: #ffc107;
font-size: 200%;
font-weight: 500;
text-shadow: 3px 3px 10px #000;
padding-botton: 1rem;
}
<!-- Image slider -->
<div id="slides" class="carousel slide" data-ride="carousel">
<ul class= "carousel-indicators">
<li data-target= "#slides" data-slide-to= "0" class="active"></li>
<li data-target= "#slides" data-slide-to= "1"></li>
<li data-target= "#slides" data-slide-to= "2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="/home/susy/Desktop/GIT/vegan-/imagens/feijuca6.jpg">
<div class="carousel-caption">
<h1 class="display-2"> Have you ever tried?</h1>
<h3> Discover the authentic flavour</h3>
<br>
<button type="button" class= "btn btn-outline-light btn-lg"> Click Here</button>
</div>
</div>
<div class="carousel-item">
<img src="/home/susy/Desktop/GIT/vegan-/imagens/pudim.jpg">
</div>
<div class="carousel-item">
<img src="/home/susy/Desktop/GIT/vegan-/imagens/meal.jpg">
</div>
</div>
The first is the CSS (I'm using CSS 3) and the second is the HTML. I'm also using Bootstrap 4.
Does anyone know what am I missing or doing wrong? Or how can I change the sizes to fit the carousel? Please.
As per my knowledge use
.carousel-inner img{
max-width:100%;
height: auto;
display: block;
}
instead of using
.carousel-inner img{
width:100%;
height: 40%;
}
if you want absolute height you can specify height : 300px
.carousel-inner img{
max-width:100%;
height: 300px;
object-fit: cover;
object-position: center;
}
What I think you are searching for is adding class="d-block w-100" in your image tag.
I have a div for slick slider, product card to be exact.
It should be displayed inline, and picture should be the whole size of the card-info.
.product-card__item {
display: flex;
width: 100%;
min-height: 450px;
}
.product-card__item-preview {
flex-basis: 48.5%;
height: 100% width:100%
}
.product-card__img {
width: 100%;
height: 100%;
object-fit: cover;
}
.product-card__item-info {
width: 51.5%;
background-color: #fff;
padding: 1.2em;
}
}
```
<article class="product-card">
<div class="product-card__preview">
<img class="product-card__img" src="https://via.placeholder.com/150" alt="">
</div>
<div class="product-card__info">
<div class="product-card__info-top">
<a class="product-card__title" href="#">
One Page Resume Template
</a>
<div class="product-card__author">
<img class="product-card__avatar" src="https://via.placeholder.com/50" alt="user avatar">
<a class="product-card__top-name" href="#">
AazzTech
</a>
</div>
</div>
</div>
</article>
but with even slightly resizing the window for adaptation, picture starts doing this:
I know it could be fixed easily if I make amg as a bg for preview div, but how is it possible with img tag?
I dont have your code, but you can try this:
.container{
display:flex;
height:500px;
}
.container > div{
flex: 1 1 0;
overflow:hidden;
}
.second img{
height:100%;
}
.first{
background-color:red;
<div class="container">
<div class="first"></div>
<div class="second">
<img src="https://upload.wikimedia.org/wikipedia/commons/4/42/Shaqi_jrvej.jpg" alt="">
</div>
</div>
I try to build a webpage, with a screen-filling image. It should be horizontally scrollable and contain other, ~30% wide, images.
I came up with the code down below. Now my first image (bg_full.jpg) is oddly stretched.
Thank you in advance!
If any occur, I am sorry for mistakes in spelling or grammar.
<body>
<img class="big" src="./bg_full.jpg" alt="Reference image one">
<img class="small" src="./images/references/reference_1.jpeg" alt="Reference image two">
<img class="small" src="./images/references/reference_2.jpeg" alt="Reference image three">
<img class="small" src="./images/references/reference_3.jpeg" alt="Reference image four">
<!--
<div class="container">
<div class="row">
<div class="col-5">
<img class="grow big" src="./images/references/reference_1.jpeg" alt="Reference image one">
</div>
<div class="col-5">
<img class="grow small" src="./images/references/reference_2.jpeg" alt="Reference image two">
<img class="grow small" src="./images/references/reference_3.jpeg" alt="Reference image three">
</div>
</div>
<div class="row">
<div class="col-5">
<img class="grow small" src="./images/references/reference_4.jpeg" alt="Reference image one"><br>
<img class="grow small" src="./images/references/reference_5.jpeg" alt="Reference image two">
</div>
<div class="col-5">
<img class="grow big" src="./images/references/reference_6.jpeg" alt="Reference image three">
</div>
</div>
</div>
</div>
-->
</body>
and
body {
width: 500%;
margin: 0 0 0 0;
}
.big {
width: 100vw;
height: 100vh;
float: left;
max-height: 100%;
}
.small{
height: 100vh;
object-fit: cover;
white-space: nowrap;
display: inline-block;}
.row {
width: 100%;
}
If you want to remove the stretch effekt on your image, you should set either height, or width to auto. This means the picture does not stretch but has its fixed height or width, and its corresponding width or height.
So if you want your width to be 100vw:
.style{
width: 100vw;
height: auto;
}
or if you want your width to be 100vh:
.style{
height: 100vh;
width: auto;
}
Overlaying other images on the big image can be done by using position: absolute;
body {
width: 100%;
margin: 0 0 0 0;
}
.big {
width: 100vw;
height: auto;
max-height: 100%;
}
.small{
position: absolute;
top: 50%;
left: 50%;
height: 50px;
}
<body>
<img class="big" src="https://dummyimage.com/200x200" alt="Reference image one">
<img class="small" src="https://dummyimage.com/50x50/e4000f" alt="Reference image two">
</body>
So according to your Comment, i hope this will help you:
If you do not want to stretch the image, you need to set width: 100vw; and height: auto; this will make sure the picture will resize both axis equally. (or height: 100vh; width: auto; respectively)
Making a Image fill the full screen at all times is a lot easier when using the css property background-image, and not an actual image tag inside your html.
by setting background-size: cover you are making sure, that the aspect ratio of the picture stays as is. It will try to make the picture as small as possible, while trying to fully fill the background positioning area.
by setting background-position: 50% 50% you make sure, that the middle of the picture will always be in the middle of your container div.
body {
width: 100%;
margin: 0 0 0 0;
}
.wrapper{
width: 100vw;
height: 100vh;
max-height: 100vh;
background-position: 50% 50%;
background-image: url("https://dummyimage.com/200x200");
background-size: cover;
}
.big {
width: 100vw;
height: auto;
}
.small{
position: absolute;
top: 50%;
left: 50%;
height: 50px;
}
<body>
<div class="wrapper">
<img class="small" src="https://dummyimage.com/50x50/e4000f" alt="Reference image two">
</div>
</body>
I have two div’s that are sitting side by side and contain images in them. When the webpage is the size of my Macbook 13 inch screen the photos sit side by side perfectly. However when I start to increase the screen width the photos start to spread apart leaving a huge gap in between.
How do I get both photos to stay side by side even when the browser page increases or decreases? `
.pic {
max-width: 100%;
}
#pic2 {
max-width: 100%;
}
.photosection {
background-color: black;
max-width:1400;
height:363px;
}
#photosection1 {
float:left;
max-width: 110vw;
}
#photosection2 {
max-width:50%;
float:right;
}
<div class="photosection">
<div id="photosection1">
<a href="#" class="">
<span class="text">
Treat Yourself
Intuitive Language Coaching
(Intuitive Life-Coaching + Communication Training)
</span>
<img class="pic" src="images/oneonone.jpg" alt="inspiremug">
</a>
</div>
<div id="photosection2">
<a href="" class="">
<span class="text">
Treat Your Group, Business or Organization
I'll bring the sweets!
</span>
<img id="pic2" src="images/groupsession.jpg" alt="necklace">
</a>
</div>
</div>
#photosection1 {
width: 50%;
float: left
}
#photosection2 {
width: 50%;
float: right
}
add width="100%" to your image tag
<img class="pic" src="images/oneonone.jpg" alt="inspiremug" width="100%">
<img id="pic2" src="images/groupsession.jpg" alt="necklace" width="100%">
Just use the display: inline-block property for the divs and size the images to width: 100%.
.pic {
width: 100%;
}
#pic2 {
width: 100%;
}
.photosection {
background-color: black;
max-width:1400;
height:363px;
}
#photosection1 {
display: inline-block;
float:left;
max-width: 50%;
}
#photosection2 {
display: inline-block;
max-width:50%;
float:right;
}
Does this help?
are you looking for this..?
.pic {
max-width: 100%;
}
#pic2 {
max-width: 100%;
}
.photosection {
background-color: black;
max-width:1400;
height:363px;
}
#photosection1 {
float:left;
max-width: 50%;
}
#photosection2 {
max-width:50%;
float:right;
}
<div class="photosection">
<div id="photosection1">
<a href="#" class="" >
<span class="text">
Treat Yourself
Intuitive Language Coaching
(Intuitive Life-Coaching + Communication Training)
</span>
<img class="pic" src="http://ias.kgisl.com/wp-content/uploads/2016/01/APJ-Abdul-Kalam.jpg" alt="inspiremug">
</a>
</div>
<div id="photosection2">
<a href="" class="" >
<span class="text">
Treat Your Group, Business or Organization
I'll bring the sweets!
</span>
<img id="pic2" src="http://ias.kgisl.com/wp-content/uploads/2016/01/APJ-Abdul-Kalam.jpg" alt="necklace">
</a>
</div>
</div>