I have implemented a carousel with Bootstrap 4. I have two main problems:
the images are somehow zoomed in. I don't want that. It should show the full size of the images.
how can I change the size of the carousel?
Here is my code:
html
<div class="carousel-inner">
<div class="carousel-item active">
<img src="/images/holz_40.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h1>lorem</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam placeat esse dicta eos ex nobis, error, corrupti optio aspernatur debitis iure ut sapiente minima exercitationem inventore maiores explicabo natus vitae..</p>
</div>
</div>
css:
.carousel {
margin-bottom: 4rem;
position: relative;
}
.carousel-caption {
bottom: 3rem;
z-index: 10;
}
.carousel-item {
height: 32rem;
}
.carousel-item > img {
position: absolute;
top: 0;
left: 0;
height: 32rem;
object-fit: cover;
}
Can someone help me on how to show the images in the original size and change the size of the carousel?
I would appreciate your help!
I think it could be due to the property object-fit:cover of your .carousel-item > img rule.
As per MDN documentation:
Cover: The replaced content is sized to maintain its aspect ratio while filling the element’s entire content box. If the object's aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit.
Cover property has many advantages when you are developing for a responsive portal, like you only have use an image that works for the most commons aspect ratios.
You could change the property to contain, so image can be displayed in normal aspect ratio, but then you need to take care at the dimensions of the enclosing carousel div.
.carousel {
margin-bottom: 4rem;
position: relative;
}
.carousel-inner {
background: red;
}
.carousel-caption {
bottom: 3rem;
z-index: 10;
}
.carousel-item {
height: 32rem;
}
.carousel-item > img {
position: absolute;
top: 0;
left: 0;
height: 32rem;
object-fit: contain;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<dic class="carousel">
<div class="carousel-inner" >
<div class="carousel-item active">
<img src="https://interactive-examples.mdn.mozilla.net/media/examples/plumeria.jpg" class="d-block w-100" alt="...">
<div class="carousel-caption d-none d-md-block">
<h1>lorem</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam placeat esse dicta eos ex nobis, error, corrupti optio aspernatur debitis iure ut sapiente minima exercitationem inventore maiores explicabo natus vitae..</p>
</div>
</div>
</div>
Related
I'm trying to replicate a website that claimed it was only made with the basic Html, CSS and JavaScript. Annoyingly I can't seem to make the images responsive and relatively the same
Can someone explain to me what I’m doing wrong? I'm using flexbox to make the site responsive but the alignments are off and I cant get them to sit next to each other with all the correct padding as well
This is my work:
https://codepen.io/Hitmonchan98/pen/PoQLRPy
This is what I want my site to look like:
https://i.stack.imgur.com/jsdxo.jpg
//html
<body>
<div class="main">
<div class="main-img"><img class="firstImage"src="https://www.amazingonly.com/wp-content/uploads/2013/04/images4-1728x1080.jpg" alt=""></div>
<div class="text">
<h2>Discover innovative ways to decorate</h2>
<p class="para">Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quia repudiandae dolore iure laudantium fugiat fuga sunt unde voluptates et, quasi exercitationem eum consectetur. Doloremque, ab?</p>
<div class="shop">Shop Now</div>
</div>
</div>
<div class="lower">
<div class="dark image">
<img class="dark-img" src="https://www.pixelstalk.net/wp-content/uploads/2016/07/Download-Free-Pictures-4k.jpg" alt="">
</div>
<div class="text2">
<h3>About furniture</h3><p class="para">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Natus ipsa, adipisci perspiciatis debitis magni sed possimus pariatur qui exercitationem fugiat iusto error ducimus, quos quis, eius earum tempore quibusdam laboriosam!</p></p></div>
<div class="light image">
<img class="light-img"src="https://www.pixelstalk.net/wp-content/uploads/2016/07/Download-Free-Pictures-4k.jpg" alt="">
</div>
</div>
</body>
//css
body{
margin: 0;
padding: 0;
line-height: 2rem;
}
/*Body*/
.firstImage,.light-img,.dark-img
{
width: 100%;
}
.text2{
padding: 2rem;
}
.text h2
{
font-size:3rem;
}
#media screen and (min-width: 768px) {
.main{
display: flex;
}
.text{
padding: 1rem 3rem 3.5rem 3rem;
}
.lower{
display: flex;
align-content:center;
}
.text2{
padding:0;
width: 40%;
}
.dark, .light
{
width: 30%;
}
.dark-img, .light-img {
width: 100%;
}
}
#media screen and (min-width: 786px) {
}
Add display: block; to your img elements and this should get rid of the white spacing underneath them. Images are weird in HTML since they have properties of both display inline and block, and I usually set them to block to have maximum styling control over them.
Hello I have a parent flex box and 2 childs with 100% width.
<div class="wrapper">
<app-user></app-user>
<div class="text">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Delectus
laboriosam incidunt necessitatibus optio id cumque velit nam deserunt
dolorem. Dolorum asperiores corporis reiciendis veniam, porro temporibus
obcaecati distinctio illo. Nihil.
</div>
</div>
My margin in <app-user> not working , due to the 100% width of parent. I need to fix the 100% width of my .sidebar element to keep the width and also I need a margin to take .text little bit away from my first element
link to code
app-user
<div class="sidebar">
sidebar
<img
src="https://cdn.oneesports.gg/wp-content/uploads/2020/07/Dota2_InvokerHeader-1024x683.jpg"
alt=""
/>
</div>
css
.wrapper {
display: flex;
}
.sidebar {
max-width: 400px;
width: 100%;
margin-right: 32px;
}
.sidebar img {
width: 100%;
height: auto;
}
UPD 1
If I move styles from .sidebar directly to app-user in browser it works perfect , but I dont want to use :host styles in css. As in produciton I have a big project
You can use calc() function documented here :
https://developer.mozilla.org/fr/docs/Web/CSS/calc()
So you can remove the margin from your .sidebar class
and add this css lines to your app.component.css :
.wrapper .text { width: calc(100% - 32px); margin-left: 32px; }
And here is your link code that I modified
I 've got the following code, and when I am viewing on mobile the Slick Carousel is bigger than the parent element and I couldn't fix it with any settings. I am using Boostrap as well.
<nav class="navbar fixed-top">
<div class="container">
<a class="navbar-brand" href="#">
<img src="/assets/Intech Logo.png" alt="INTECH DYNAMICS logo" />
</a>
</div>
</nav>
<div class="wrapper-section-1">
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6 col-xl-6 col-xs-12 col-xm-12 d-flex justify-content-center imagine">
<img class="img img-fluid floating" src="/assets/Header Image.png" alt="Careers banner image" />
</div>
<div class="col-lg-6 col-md-6 col-xl-6 col-xs-12 col-xm-12 d-flex justify-content-center">
<div class="row">
<div class="col-lg-12 title">
<h1 class="text-title">CAREERS</h1>
</div>
<div class="col-lg-12 slide">
<div class="single-item slider slide">
<div>
<div class="font-italic">
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Illo at reiciendis architecto harum nihil culpa accusantium
saepe ut, tempore quibusdam ex odit magnam nemo accusamus
numquam consequatur? Praesentium, voluptates pariatur!</div>
<br>
<span class="font-weight-bold">Darius Opro</span><span class="font-weight-normal"> Full Stack
Programmer</span>
</div>
<div>
<div class="font-italic">
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Illo at reiciendis architecto harum nihil culpa accusantium
saepe ut, tempore quibusdam ex odit magnam nemo accusamus
numquam consequatur? Praesentium, voluptates pariatur!</div>
<br>
<span class="font-weight-bold">Cosmin Mihalache</span><span class="font-weight-normal"> Front End
Developer</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The CSS looks like this:
.wrapper-section-1 {
font-family: IBMPlexSans-Medum;
color: white;
margin-top: 54px;
width: auto;
padding: 8vh;
background-image: linear-gradient(to right, #1c003b, #5216aa);
}
.img {
max-width: 70%;
height: auto;
}
.imagine {
padding: 30px 0 30px 0;
}
.title {
align-items: flex-end;
display: flex;
justify-content: flex-end;
}
.text-title {
margin-bottom: 2rem;
}
/* Slick Carousel */
.slick-prev:before,
.slick-next:before {
color: black;
}
.slick-slide {
transition: all ease-in-out 0.3s;
opacity: 0.2;
}
.slick-active {
opacity: 0.5;
}
.slick-current {
opacity: 1;
}
.slide {
width: 500px;
margin: 0;
text-align: right;
background-color: blue
}
/* Custom Arrows */
.prev-arrow {
position: absolute;
bottom: -50px;
left: 400px;
cursor: pointer;
}
.next-arrow {
right: 3px;
position: absolute;
bottom: -50px;
cursor: pointer;
}
/* Floating Animation */
.floating {
animation-name: floating;
animation-duration: 3s;
animation-iteration-count: infinite;
animation-timing-function: ease-in-out;
margin-left: 30px;
margin-top: 5px;
}
$(document).on("ready", function () {
$(".single-item").slick({
lazyLoad: "ondemand", // ondemand progressive anticipated
infinite: true,
settings: "unslick",
prevArrow:
'<span class="prev-arrow"><i class="fas fa-angle-left"></i></span>',
nextArrow:
'<span class="next-arrow"><i class="fas fa-angle-right"></i></span>',
});
});
I attached a photo to have a better idea of what is happening. I tried to give to the carousel padding, to set width in percentage with parent element but nothing worked.
Update: Pretty sure that JS has nothing to do with it but I attached anyway
I want to make an image slider with thumbnail images to select from, my idea is allign all images horizontally and hide overfolwn than with javascript i will just change the left postion to display the needed thumbnail, but I couldn't figure out how to css images to align hrizontally and hide the part that goes beyond the container of the thumnails, I am using spectre css framework, my HTML looks like this
.img-list {
margin-bottom: 20px;
height: 100px;
width: 100%;
overflow-x: hidden;
}
#media (max-width: 600px) {
.img-list {
height: 50px;
}
}
.img-container {
height: 100%;
position: relative;
overflow: visible;
}
.img-container img {
height: 100%;
display: inline-block;
position: relative;
}
.img-main {
width: 100%;
}
.img-main img {
width: 100%;
}
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre.min.css">
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-exp.min.css">
<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-icons.min.css">
<div class="container">
<div class="columns">
<div class="column col-md-12">
<div class="img-main">
<img src="https://preview.ibb.co/gxVppG/img1.jpg">
</div>
<div class="img-list ">
<div class="img-container">
<img src="https://preview.ibb.co/gxVppG/img1.jpg">
<img src="https://preview.ibb.co/iZ3Lww/img2.jpg">
<img src="https://preview.ibb.co/iQsPOb/img3.jpg">
<img src="https://preview.ibb.co/gFFdib/img4.jpg">
<img src="https://preview.ibb.co/hS5ppG/img5.jpg">
<img src="https://preview.ibb.co/goKtGw/img6.jpg">
<img src="https://preview.ibb.co/bSWjOb/img7.jpg">
<img src="https://preview.ibb.co/i2o9pG/img8.jpg">
</div>
</div>
</div>
<div class="column col-md-12">
<h1>Peugeaut 206</h1>
<input type="number" onchange="showImage(this)" value="1">
<p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Numquam culpa sint recusandae architecto odit tenetur
fugit rerum soluta quidem velit. Eos provident nemo dolores vitae pariatur perspiciatis delectus ex dignissimos!
Quibusdam architecto natus nam ullam cupiditate deserunt voluptatem nulla inventore nesciunt error recusandae
quod ab, harum temporibus laboriosam numquam facilis beatae. Numquam odit dolorem quasi rerum aut cupiditate
distinctio ad! Assumenda aut, repellat nihil, fugit doloremque doloribus harum possimus commodi aliquam recusandae
reiciendis delectus vel modi quia sapiente sit voluptas deleniti. Repellat magni rerum fuga vitae odio ad
ullam tempora.</p>
</div>
</div>
</div>
You can simply use white-space:nowrap
.img-list {
margin-bottom: 20px;
height: 100px;
width: 100%;
overflow: auto; /*Show horizontal scroll*/
}
#media (max-width: 600px) {
.img-list {
height: 50px;
}
}
.img-container {
height: 100%;
position: relative;
white-space:nowrap; /*Added this*/
}
.img-container img {
height: 100%;
display: inline-block;
vertical-align:top; /*to remove unwanted whitespace */
position: relative;
}
.img-main {
width: 100%;
}
.img-main img {
width: 100%;
}
<div class="img-main">
<img src="https://preview.ibb.co/gxVppG/img1.jpg">
</div>
<div class="img-list ">
<div class="img-container">
<img src="https://preview.ibb.co/gxVppG/img1.jpg">
<img src="https://preview.ibb.co/iZ3Lww/img2.jpg">
<img src="https://preview.ibb.co/iQsPOb/img3.jpg">
<img src="https://preview.ibb.co/gFFdib/img4.jpg">
<img src="https://preview.ibb.co/hS5ppG/img5.jpg">
<img src="https://preview.ibb.co/goKtGw/img6.jpg">
<img src="https://preview.ibb.co/bSWjOb/img7.jpg">
<img src="https://preview.ibb.co/i2o9pG/img8.jpg">
</div>
</div>
Flexbox is good option but if you want you can add to div with a list of thumbnail images white-space: nowrap
Here is jsfiddle:
.img-container {
white-space: nowrap;
}
.img-container img {
height: 80px;
width: 80px;
display: inline-block;
}
.img-list {
height: 100px;
width: 100%;
}
.img-main img {
width: 100%;
}
<div class="img-main">
<img src="https://preview.ibb.co/gxVppG/img1.jpg">
</div>
<div class="img-list ">
<div class="img-container">
<img src="https://preview.ibb.co/gxVppG/img1.jpg">
<img src="https://preview.ibb.co/iZ3Lww/img2.jpg">
<img src="https://preview.ibb.co/iQsPOb/img3.jpg">
<img src="https://preview.ibb.co/gFFdib/img4.jpg">
<img src="https://preview.ibb.co/hS5ppG/img5.jpg">
<img src="https://preview.ibb.co/goKtGw/img6.jpg">
<img src="https://preview.ibb.co/bSWjOb/img7.jpg">
<img src="https://preview.ibb.co/i2o9pG/img8.jpg">
</div>
</div>
I have updated CSS removed the unnecessary style.
My solution of choice is Flexbox!
To class .img-container:
add display: flex; - this turns the container into a flex container
add flex-direction: row; - this is default but illustrates the example
add flex-wrap: nowrap; - this is also default but also illustrates the example
finally, change overflow to hidden
jsfiddle demo
I believe this achieves what you desire. Please let me know if I'm mistaken.
The problem arises when there is a variable width image set to max-height: 100%; in a flex-item. When the page loads flex box successfully gets the width for the current size of the flex-item, however if you resize the browser which forces the image to decrease in size (or increase), the outer container does not follow the new width.
If you run the code snippet below in full screen you'll see on initial load the image is fully surrounded by the pink box, but when you resize (make the height smaller) the image shrinks and the flex container stays at the same width.
.flex {
display: inline-flex;
background-color: deeppink;
height: calc(100vh - 20px);
border: 10px solid deeppink;
}
.flex-left {
width: 250px;
}
.flex-right img {
width: auto;
min-width: 0;
max-height: 100%;
}
<div class="flex">
<div class="flex-left">
<h2>Testing headline</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus quia nemo qui ipsam? Temporibus sint necessitatibus expedita, eum quae tempora voluptas dolore facere voluptate! Possimus molestias non commodi. Officiis, iste?</p>
</div>
<div class="flex-right">
<img src="http://unsplash.it/1000/650" alt="">
</div>
</div>
Try adding a percentage height to the image container.
The image is already flexible, because its dimensions are set in percentages. With a percentage height on the container, it becomes flexible, as well.
jsfiddle demo
.flex {
display: inline-flex;
background-color: deeppink;
height: calc(100vh - 20px);
border: 10px solid deeppink;
}
.flex-left {
width: 250px;
}
.flex-right {
height: 100%;
}
img {
max-width: 100%;
max-height: 100%;
}
<div class="flex">
<div class="flex-left">
<h2>Testing headline</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Necessitatibus quia nemo qui ipsam? Temporibus sint necessitatibus expedita, eum quae tempora voluptas dolore facere voluptate! Possimus molestias non commodi. Officiis, iste?</p>
</div>
<div class="flex-right">
<img src="http://unsplash.it/1000/650" alt="">
</div>
</div>