Why are Those things different with CSS overflow hidden? - css

Everything is okay except "the overflow".
When I put "overflow : hidden" in 'image-container', It s not work like sequential carousel.
But when I put "overflow : hidden" in 'carousel', It s work like sequential carousel.
I don't know what's the different with those things and Why is this happened?
let imgs = document.querySelector('.image-container');
let img = document.querySelectorAll('.image-container img');
let idx = 0;
function slideShow() {
idx++;
if (idx > img.length - 1) {
idx = 0;
}
imgs.style.transform = `translateX(${-idx*300}px)`;
}
setInterval(slideShow, 2000);
.carousel {
/*overflow: hidden;*/
}
.image-container {
overflow: hidden;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
height: 300px;
width: 300px;
display: flex;
}
img {
object-fit: cover;
height: 300px;
width: 300px;
}
<div class="carousel">
<div class="image-container">
<img src="https://images.unsplash.com/photo-1599394022918-6c2776530abb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1458&q=80" alt="" />
<img src="https://images.unsplash.com/photo-1593642632559-0c6d3fc62b89?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80" alt="" />
<img src="https://images.unsplash.com/photo-1599423300746-b62533397364?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80" alt="" />
<img src="https://images.unsplash.com/photo-1599561046251-bfb9465b4c44?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1492&q=80" alt="" />
</div>
</div>

If you set {overflow: hidden} to {image-container} then that means anything that is beyond the specified width of that container will be hidden.
So either you could increase the width of the {image-container}
.image-container {
overflow: hidden;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
height: 300px;
width: 1000px;
display: flex;
}
or you could use
.carousel {
overflow: hidden;
}

Related

how to stop React-responsive-carousel scaling to height of its child elements?

I have set up a carousel with a display flex:1 the idea being to make it take up as much height as available to it which works as intended(can be tested by setting a fixed height for the div(.image-iframeContainer) contained in it). but whenever I try and set this div to be 100% of the carousel height instead of the content scaling to fit the size of the carousel, the carousel will instead scale to the 100% of the size of the content(test this by stretching the aspect ratio). how do I fix/stop this happening?
reactjs
<div className="Cards">
<Carousel
showThumbs={false}
infiniteLoop={true}
swipeable={false}
dynamicHeight={false}
>
<div>
<div className="image-iframeContainer">
<img src={IMG} />
</div>
</div>
<div>
<div className="image-iframeContainer">
<img src={IMG} />
</div>
</div>
<div>
<div className="image-iframeContainer">
<img src={IMG} />
</div>
</div>
</Carousel>
<h1>{Projects.workName}</h1>
{Projects.workTech.map((Tech, index) => {
return <p>Technology used: {Tech}</p>;
})}
<p>{Projects.workDescription}</p>
</div>
Sass
.Cards {
position: absolute;
width: 50%;
height: 80%;
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.1), 0 10px 10px rgba(0, 0, 0, 0.2);
margin-left: auto;
margin-right: auto;
margin-top: 10%;
left: 0;
right: 0;
border-radius: 7px;
overflow: hidden;
background: #7510f7;
display: flex;
flex-direction: column;
.image-iframeContainer {
display: flex;
width: 100%;
//setting a fixed height for this div allows for flex scaling of the carousel
height: 400px;
//height: 100%;
background: greenyellow;
overflow: hidden;
img {
width: auto;
height: auto;
max-width: 100%;
max-height: 100%;
object-fit: cover;
background-repeat: no-repeat;
margin: auto;
}
iframe {
position: absolute;
margin: 0;
top: 0;
left: 0;
width: 100%;
height: 100px;
border: 0;
}
}
.carousel-root{
flex:1;
}
.carousel {
z-index: 0;
}
.carousel, .slider-wrapper, .slider {
height: 100%;
}
.slide{
display: flex;
justify-content: center;
}
.carousel.carousel-slider {
.control-arrow {
padding: 15%;
opacity: 0%;
}
}
}
sandbox link
https://codesandbox.io/s/sleepy-sunset-jqjst?file=/src/styles.scss:478-500
To avoid confusion these are swipe cards layered on top of each other hence the absolute positioning, in my actual project images are injected dynamically I do not want to crop or stretch images this is why I've picked this implementation with borders the containing div will give back colour to the bezels around the picture.

Is it possible to center an image inside a wrapper with an overflow hidden?

I need my thumbnail to fill in the space of the container which is 100x100px. But I have some landscape images that I would like to have centered inside so they get cropped of left and right side. Is it possible to achieve this without using a background image.
Here is what I have so far:
HTML
<div class="outer">
<div class="thumbnail">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="" />
</div>
</div>
CSS
.outer {
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid grey
}
.thumbnail {
overflow: hidden
}
img {
width: auto;
height: 100px;
}
http://codepen.io/ingvi/pen/JYjBNP?editors=110
If you don't mind about IE support, you can use object-fit: cover; property.
css:
.outer {
margin: 0 auto;
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid grey;
}
.thumbnail {
overflow: hidden;
}
img {
width: 100%;
height: 100px;
object-fit: cover;
}
html:
<div class="outer">
<div class="thumbnail">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="" />
</div>
</div>
demo: https://jsfiddle.net/d0wvvdf8/1/
Are your portrait images always going to be the same size, or will they be variable widths? If they're the same size, you can do this:
http://codepen.io/tinyglowstudio/pen/ojNVGj?editors=110
HTML:
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=300%C3%97100&w=300&h=100" alt="" />
I changed it to 300 and 100 for my own math. You can do the algebra yourself :)
CSS:
img
position: absolute;
width: auto;
height: 100px;
z-index: 0;
clip: rect(0px 200px auto 100px);
transform: translate(-100px);
This works in IE
If you adjust the width from width: auto to width: 100px the image gets resized to fit inside the thumbnail. If that's what you want.
Okay, here's a new answer using JS to set our clipping amounts:
http://codepen.io/tinyglowstudio/pen/ojNVGj?editors=111
HTML:
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=450%C3%97250&w=450&h=250" alt="" />
CSS:
img
position: absolute;
width: auto;
height: 100px;
z-index: 0;
JS
$(".thumbnail img").each(function() {
var Height = 100 / $(this).height();
var Width = $(this).width() * (100 / $(this).height());
var trimAmount = (Width - 100) / 2;
$(this).css({
'transform' : 'translate(-' + trimAmount + 'px, 0)',
'clip' : 'rect(0 ' + (100 + trimAmount) + 'px 100px ' + trimAmount + 'px)'});
});

CSS3 Horizontal div alignment

So what I'm trying to do is
|-------------------------------------------------------------|
|-------|leftdiv-250px|centerdiv-1000px|rightdiv-250px|-------|
|-------------------------------------------------------------|
So here's the HTML
<div id="header">
<div id="header-top">
<div id="header-top-main">
</div>
</div>
<div id="header-main">
<div id="header-main-inner">
<div id="header-main-left">
</div>
<div id="header-main-center">
</div>
<div id="header-main-right">
</div>
</div>
</div>
</div>
And here's the CSS
#header {
height: 190px;
width: 100%;
background: #e5e5e5;
margin: auto;
}
#header-top {
height: 50px;
width: 100%;
background: #e9e9e9;
background-image: url(../img/header-top-bg.png);
-webkit-box-shadow: 0px 0px 10px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px 0px 10px rgba(50, 50, 50, 0.75);
box-shadow: 0px 0px 10px rgba(50, 50, 50, 0.75);
margin: auto;
z-index: 999;
position: relative;
}
#header-top-main {
height: 50px;
width: 1000px;
margin: auto;
}
#header-main {
margin: auto;
width: 100%;
}
#header-main-inner {
margin: auto;
width: auto;
}
#header-main-left {
width: 250px;
height: 140px;
background: url(../img/header-main-left-bg.png);
float: left;
}
#header-main-center {
width: 1000px;
height: 140px;
background: #f7f7f7;
display: inline;
}
#header-main-right {
width: 250px;
height: 140px;
background: url(../img/header-main-right-bg.png);
float: right;
}
So I'm not sure what the problem is, I've tried to float them all left in a wrapper that has an auto margin but hadn't seemed to work. Another issue that came up was it all displayed in 1 line, but it stacks up on the left of the page, continuing all the way to right, giving the page a scroll.
What I want is, for the 'header-main' area to be centered with the 3 divs. And if the 'header-main' area goes off page, I would want it to continue off page without a scroll. If a screenshot of what I'm trying to do is needed, then I can provide it.
here would be another example
--------------------|------[ header-top ]------|-------------------
space beyond screen |------[leftdiv][centerdiv][rightdiv]------| spce beyond screen
--------------------|------[ navigation ]------|-------------------
I would add floats to the elements, height to the elements, and a min-width to the parent.
#header-main-left,
#header-main-center,
#header-main-right {
float: left;
height: 140px;
}
#header-main-inner {
min-width: 1500px;
}
And then to stop the scrolling, I would say to add an overflow: hidden;:
#header-main {
overflow: hidden;
}
Fiddle
This will fix your problem with div positioning, here's a FIDDLE
#header-main-left,
#header-main-center,
#header-main-right {
float: left;
height: 140px;
}
#header-main-left {
width: 25%;
background: url(../img/header-main-left-bg.png);
}
#header-main-center {
width: 50%;
background: #f7f7f7;
}
#header-main-right {
width: 25%;
background: url(../img/header-main-right-bg.png);
}
Second part I don't understand well
"And if the 'header-main' area goes off page, I would want it to continue off page without a scroll."

Positioning a "wrapper" div underneath a fixed navigation bar?

I've started work on a brand new site and i've been playing around with designs for a while, however one problem I seem to be having is regarding positioning a navigation bar with a full screen width that is fixed to scroll. Underneath i have created a div called "wrapper" which is set to centre at a width of 980px. Below is code example;
<style>
#navBar {
background: RGB(0, 0, 0);
height: 30px;
position: fixed;
width: 100%;
}
#wrapper {
margin: 0 auto;
width: 980px;
}
</style>
<div id="navBar">
</div>
<div id="wrapper">
<div style="border: 1px solid RGB(0, 0, 0); float: left; height: 500px; margin: 5px; width: 400px;"></div>
</div>
The box i created within "wrapper" SHOULD (obviously isn't because i'm doing something wrong - somewhere) sit 5px below the navBar, however because I have used position: fixed it sits underneath it instead. Could anybody lead me to how I solve this issue and have it so that the wrapper sits directly below rather than underneath the navbar whilst maintaining it's centering?
set top:0 on your navbar and add 30px margin-top on your wrapper div
#navBar {
background: RGB(0, 0, 0);
height: 30px;
position: fixed;
width: 100%;
top:0
}
#wrapper {
margin: 30px auto 0;
width: 980px;
}
http://jsfiddle.net/duncan/NkRxQ/
Complete solution to solve your problem.
<!DOCTYPE html>
<html>
<head>
<style>
*{
margin:0;
padding:0;
}
#navBar {
background: RGB(0, 0, 0);
height: 30px;
position: fixed;
width: 100%;
top: 0;
}
#wrapper {
margin: 30px auto;
width: 980px;
background: #ccc;
}
.clear {
clear: both;
}
</style>
</head>
<body>
<div id="navBar">
</div>
<div id="wrapper">
<div style="border: 1px solid RGB(0, 0, 0); float: left; min-height: 500px; margin: 5px; width: 400px;">
<!-- You can create left side elements here (without any float specification in CSS) -->
</div>
<div style="border: 1px solid RGB(0, 0, 0); float: left; min-height: 500px; margin: 5px; width: 556px;">
<!-- You can create right side elements here (without any float specification in CSS) -->
</div>
<div class="clear"></div>
</div>
</body>
</html>
Starting brand new site should contain DOCTYPE and 0 margin for all tags. (Very helpful thing).

Padding causes div to expand beyond parent

Any idea why the .story-text expands beyond the bounds of the container? I don't want to set overflow: hidden because it doesn't solve the issue that the padding is causing it to expand beyond the bounds (and the text would be flush up against the right edge of the container). Why isn't .story-text staying within the bounds of its parent and how do I get it to behave properly?
Fiddle: http://jsfiddle.net/csaltyj/yFpMH/
HTML:
<div id="story-container">
<div class="story">
<img src="http://www.westernjournalism.com/wp-content/uploads/2011/04/Barack-Obama-There-Might-Be-Chances-of-Further-Offshore-Drilling-Campaigns.jpg" />
<div class="story-text">
<h4>Obama is pointing at you!</h4>
<p>It is this very gaze, and this very pointed finger, that actually killed Osama bin Laden.</p>
</div>
</div>
<div class="story">
<img src="http://reason.com/assets/mc/jtaylor/rahm.jpg" />
</div>
</div>
CSS:
#story-container {
margin-top: 2em;
width: 300px;
height: 200px;
border: 1px solid #999;
position: relative;
}
.story {
position: absolute;
}
.story img {
width: 100%;
height: 100%;
}
.story-text {
background: rgba(0, 0, 0, 0.7);
color: #fff;
position: absolute;
/*top: 130px;*/
bottom: 0;
height: 45px;
width: 100%;
padding: 10px;
}
.story p {
font-size: 0.7em;
}
If you take out the width declaration for .story-text that should fix it.
Set the width of story text to 280px or just the container width - padding left - padding right. Demo here http://jsfiddle.net/yFpMH/6/

Resources