Resize DIV with a slider inside when screen size changes - html

I am trying to get a 'panel' effect going on this website. Everything remains static apart from the content in the middle. As the site progresses, only the centre content area will scroll down. The navigation menu and the header and (yet to be coded) footer will remain fixed. So far, i have accomplished this. But i want the image/slider in the centre to be the size of the panel. Currently, the slider resizes when you change screen size, which is great and what i want, however, i just need to slider to have the correct height to start with.
On my 13inch screen, the correct height is around 620px for the height. However, if i transfer onto a larger screen, obviously, the 620px is not correct and i cannot work out how to do this.
I have tried introducing height:80%; into the code for the slider, but this does not work.
The site can be found here:
https://mimi-fasi.myshopify.com/
I'm sure this is fairly basic stuff, but i cannot get it to work.
<div id="content">
<div class="flexslider type-header scaled-text-base">
<ul class="slides">
<li class="slide slide-1 flex-active-slide" style="width: 100%; float: left; margin-right: -100%; position: relative; opacity: 1; display: block; z-index: 2;">
<a href="/collections/all">
<img src="//cdn.shopify.com/s/files/1/0727/2709/t/2/assets/slide_1.jpg?155" alt="Slide 1" draggable="false">
<div class="overlay-text posx-left posy-bottom">
<div class="inner">
<h1 class="text-1"><span class="scaled-text" style="font-size: 5.83333333333333%;">Welcome to</span></h1>
<h2 class="text-2"><span class="scaled-text" style="font-size: 5.83333333333333%;">Masonry for Shopify</span></h2>
</div>
</div>
</a>
</li>
</ul>
</div>
So, #content is effectively going to contain all of the products, which needs to be scrollable. The flexslider is what is too long at the moment, and i need it to be the full size of the screen, so that there is no scroll, if that makes sense.
CSS:
#content {
max-width: 940px;
transition: padding 250ms;
overflow: hidden;
position: absolute;
left: 260px;
top: 100px;
}
.flexslider {
position: relative;
zoom: 1;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
.flexslider .slides {
overflow: hidden;
zoom: 1;
margin: 0;
}
.slides, .flex-control-nav, .flex-direction-nav {
margin: 0;
padding: 0;
list-style: none;
}
Just to clarify, the image resizes when the screen size changes, which is exactly what i want. However, i want to set a max height for the div depending on the size of the screen, so that the slider/image fills the panel.
One last thing, this code:
.flexslider .slides img {
max-width: 100%;
display: block;
margin: 0 auto;
width: 100%;
}
Works fine for width, so if i change the max width/the width down, it all changes and work perfect. I am only attempting to do the same thing with the height, however, this does not work.

#content {
max-width: 940px;
transition: padding 250ms;
overflow: hidden;
position: fixed;
left: 260px;
top: 100px;
overflow-y:scroll;
}
I didn't get what the .slider does nor did I see it in action... But this css will make your div scroll-able, and changing the position to fixed will clip it in place, using the bottom:0 positioning will make it have the height desired.

Related

Centering text within a responsive image

I am trying to make a showcase section for a web page. It consists of a div with a (responsive) background image and a header that would be centered horizontally and vertically over this image. I've managed to get the image in and have it be responsive, and I've got the header centered, but my problem arises when the window size becomes smaller.
I'm using position: absolute, the top property, and transform to have it be centered, but the top property only works when height is specified in the parent container. However, when the window shrinks to the point where the image begins to shrink to below its original height, the text does not stay vertically centered, only horizontally (since I'm going off of the original height for top (800px)).
I can't just change the height with a media query since the image size is changing constantly and I can't not use height because then the top property would not work at all, so I'm a bit confused with how to get around this.
Here are the relevant sections of my code:
HTML:
<section class="showcase">
<div class="showcase-container">
<h1 class="centered"><span class="highlight">BR</span> Architects</h1>
</div>
</section>
CSS:
.container {
width: 80%;
margin: 0 auto;
padding: 0;
position: relative;
height: auto;
}
.showcase-container {
width: 80%;
margin: 0 auto;
padding: 0;
position: relative;
height: 800px;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
I might just guess because I don't know how does this really look, but I assumed few things and in a result instead of background image I would just use normal image, make it blocky and display div over it, you will have height preserved in any size, take a look:
.showcase-container {
width: 80%;
margin: 0 auto;
padding: 0;
position: relative;
}
.showcase-container img {
display: block;
width: 100%;
height: auto;
margin: 0 auto;
max-width: 1200px;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #fff;
border-radius: 5px;
padding: 10px 20px;
}
<section class="showcase">
<div class="showcase-container">
<img src="https://source.unsplash.com/random/1200x700" alt="">
<h1 class="centered"><span class="highlight">BR</span> Architects</h1>
</div>
</section>
See MDN's <figcaption> documentation.
<figure>
<img src="/media/examples/hamster.jpg" alt="a cute hamster" />
<figcaption>Hamster by Ricky Kharawala on Unsplash</figcaption>
</figure>
If I'm understanding this right, you're saying you don't need to worry about the image always maintaining an 800px height, you just want the h1 to remain centered. In that case, it's really simple.
Just add your image as a background, setting the background-size to cover, then make sure the container is never larger than the window by setting its height to 100vh, but never taller than 800px by setting its max-height.
.showcase-container {
/* your styles here */
background-image: url('yourimage.jpg');
background-size: cover;
height: 100vh;
max-height: 800px;
}
OR if you need it to be vertically centered in the window independently of the container, you can always change top: 50%; to top: 50vh; and position relative to the body.

itHow do I make div/ div images not move when resizing, while also allowing them to have a % from the top

I want to be able to resize the window while my divs keep their position on the page AND resize to a % of width and height I declare.
HTML:
<body>
<div class="view">
<div class="Tree">
<img id="tree" src="img/tree.png">
</div>
<div class="Ground">
<div class="g"></div>
</div>
</div>
</body>
CSS:
.Tree {
position: absolute;
}
.Tree #tree {
position: relative;
height: 75%;
width: 75%;
left: 30%; }
.Ground {
z-index: 2;
width: 100%;
height: 100%; }
.Ground .g {
background-color: green;
opacity: .5;
position: relative;
height: 50%;
width: 100%; }
The tree stays pretty constant, but when the window is the largest it can be on my macbook, it slides over to the left a little. The ground element vertically takes up half the page, I instead want it to only be placed 50% from the top. When I try to apply the 'top' style to either of them nothing happens. I know this is because the #tree is relative to .Tree and I don't declare a height/ width. I don't declare a h/w because it makes my #tree image's w/h off.
Thank you for the help!
Edit, added clarification:
I want the divs to resize according to the window width. I don't want them to change their left position. And I want to be able to set a 'top' % because I currently can't.
Fiddle: https://jsfiddle.net/sqdgzbp6/
Notice on this website: anniwang.com that if you resize your entire window the drawings seem to also resize BUT they don't loose their position on the page. I want to recreate an effect similar to hers.
As the .Tree is an absolute positioned element, it need a height/width set explicit or else no child with percent will have anything to calculate their percent from, so in this sample I gave it a height and now top will work.
.Tree {
position: absolute;
height: 100%;
width: 100%;
}
#tree {
position: relative;
height: auto;
width: 60%;
left: 30%;
top: 20%;
}
.Ground {
z-index: 2;
width: 100%;
height: 100%;
}
.Ground .g {
background-color: green;
opacity: .5;
position: relative;
height: 50%;
width: 100%;
}
<div class="view">
<div class="Tree">
<img id="tree" src="http://www.placehold.it/200/100">
</div>
<div class="Ground">
<div class="g"></div>
</div>
</div>
By the sound of it, you want divs to stop resizing when you've previously set a size of 50%. Remember this is only 50% of the window screen, so no matter how big or small the window, it will always scale to 50% of whatever you're viewing on. If you want it to be fixed, you could use 500px that way it doesn't move because it's set to a fixed 500.
Hope this helps.

Height:100% does not work to resize my div

This is a result of my previous question. I know that i need to set a specific percentage for the image in the centre of my page so that when the screen size increases/decreases, the image stays in proportion to this. Essentially, i need the image in the centre of my website to be the size of the 'panel', and fit entirely in that panel so that there is no scroll.
The site can be found here:
https://mimi-fasi.myshopify.com/
I'm sure this is fairly basic stuff, but i cannot get it to work.
<div id="content">
<div class="flexslider type-header scaled-text-base">
<ul class="slides">
<li class="slide slide-1 flex-active-slide" style="width: 100%; float: left; margin-right: -100%; position: relative; opacity: 1; display: block; z-index: 2;">
<a href="/collections/all">
<img src="//cdn.shopify.com/s/files/1/0727/2709/t/2/assets/slide_1.jpg?155" alt="Slide 1" draggable="false">
<div class="overlay-text posx-left posy-bottom">
<div class="inner">
<h1 class="text-1"><span class="scaled-text" style="font-size: 5.83333333333333%;">Welcome to</span></h1>
<h2 class="text-2"><span class="scaled-text" style="font-size: 5.83333333333333%;">Masonry for Shopify</span></h2>
</div>
</div>
</a>
</li>
</ul>
</div>
So, #content is effectively going to contain all of the products (on the catalog screen), which needs to be scrollable, hence why #content cannot be fixed.
CSS:
#content {
max-width: 940px;
transition: padding 250ms;
overflow: hidden;
position: absolute;
left: 260px;
top: 100px;
}
.flexslider {
position: relative;
zoom: 1;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
.flexslider .slides {
overflow: hidden;
zoom: 1;
margin: 0;
}
.slides, .flex-control-nav, .flex-direction-nav {
margin: 0;
padding: 0;
list-style: none;
}
Just to clarify, the image resizes when the screen size changes, which is exactly what i want. However, i want to set a max height for the div depending on the size of the screen, so that the slider/image fills the panel.
One last thing, this code:
.flexslider .slides img {
max-width: 100%;
display: block;
margin: 0 auto;
width: 100%;
}
Works fine for width, so if i change the max width/the width down, it all changes and work perfect. I am only attempting to do the same thing with the height, however, this does not work.
Use this in your CSS:
html, body {
height: 100%
}
You have to set the height of each container of the <div> as well.

Responsive CSS; image moves to next line rather than shrink

I'm trying to make a responsive page for mobiles that will respond when the view-port is extremely small (i.e. small screen in portrait). I have three elements in the header, a 'hamburger' for the menu, the logo/home link and a basket icon. It's important that the user be able to use the menu and basket buttons and I'm trying to get the logo to shrink when the view-port width is too small to accommodate all the content.
At the moment, when the width shrinks the images drop onto the next line, rather than shrink to scale.
Markup:
<header>
<div class="btn-menu">
<a href="" id="menubutton">
<img src="/images/theme/mobile/v3/en/buttons/btn-menu3.png">
</a>
</div>
<div class="btn-home">
<a href="/" class="logo">
<img alt="Home" src="/images/theme/mobile/v3/en/layout/logo-new.png">
</a>
</div>
<div class="btn-basket">
<a href="/basket" id="basketbutton" class="header-button">
<img alt="Basket" src="/images/theme/mobile/v3/en/buttons/btn-basket2.png">
</a>
</div>
</header>
CSS:
header {
position: relative;
text-align: center;
z-index: 10001;
background-color: #fff;
border-bottom: 8px solid #cc0033;
height: 48px;
overflow: hidden;
width: 100%;
}
header div.btn-home > a, img {
height: auto;
max-width: 100%;
}
div.btn-menu {
display: inline-block;
float: left;
width: 48px;
}
div.btn-home {
display: inline-block;
max-width: 199px;
}
div.btn-basket {
width: 60px;
display: inline-block;
float: right;
position:
}
The fixed width on btn-menu and btn-basket are intentional, I don't want them to change, only btn-home needs to respond to the view-port size.
Here's a fiddle to the example. I have added a button with a CSS width transition to simulate the view-port shrinking. In production it should just render to the appropriate size and change when switching between landscape and portrait. The overflow: hidden is disabled to show where the images end up.
I took your code and modified a little. Here is the solution on JSFiddle: http://jsfiddle.net/rmdymm55/
Description:
I added a max height to the header but that's not essential, I just did it out of practice.
I completely removed this:
header div.btn-home > a, img {
height: auto;
max-width: 100%;
}
because I chose to declare it this way:
div.btn-home img {
max-width: 40%;
margin-left: -50px;
}
Both should work but mine is a bit more selective on where its' applied. Only images inside of <div class="btn-home">. Notice how I did margin-left: -50px. That is so when it shrinks, the logo is still centered. The real bag of tricks though is where the Home button is. You have to do the following on .btn-home img:
display: inline; /* This will keep it in one line */
width: auto; /* for resizing */
height: auto; /* for resizing */
position: relative; /* to keep it in place */
For the div.btn-basket you must add:
position: absolute;
and on div.btn-menu you have to add:
position: relative;
This will position the images properly so they don't overlap, move seamlessly and wont go onto the next line.

background image overflow not working

I'm having a little trouble getting this image to be displayed correctly.
I have my site setup with a width of 940px and I want to keep this width but have a div within this that is wider and overflows so that you can still see this on larger displays.
<div id="cinema-wrapper">
<div id="cinema-displays"></div>
</div>
#cinema-wrapper {
width:940px;
height:764px;
}
#cinema-displays {
background-image: url(../mackbyte_files/img/cinema-bg.png);
height: 764px;
width: 3109px;
background-repeat: no-repeat;
position: absolute;
left:50%;
margin-left:-1554.5px;
overflow:visible !important;
}
This works (kinda) but I'm left with two problems.
It doesn't work in safari (chrome/firefox are fine)
It leaves a scroll option only to the right. (e.g. I can scroll further to the right to see the overflowed image).
For 2, I only want the user to see the amount of image depending on their screen resolution.
PS. I know 3109px is huge for web and screen res but im working on a fix before I continue with the image to make it smaller; however, when I do I will still have this issue.
what controls if the inner div is visible or not outside the cinema-wrapper is the overflow of the parent, that you are not setting. so, you should do
#cinema-wrapper {
width:940px;
height:764px;
overflow:visible;
}
I've also experienced that kind of problem so here's my approach.
for the HTML:
<div id="cinema-wrapper">
<div id="cinema-subwrapper">
<div id="cinema-displays"></div>
</div>
</div>
for the CSS:
#cinema-wrapper {
width: 940px;
height: 764px;
overflow: visible;
position: relative;
}
#cinema-subwrapper {
display: inline-block;
position: relative;
right: -50%;
}
#cinema-displays {
background: url(../mackbyte_files/img/cinema-bg.png) center top no-repeat;
height: 764px;
width: 3109px;
position: absolute;
left: -50%;
}
Hope this helps. :)