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.
Related
I'm trying converting my Photoshop design into a web site, manually writing HTML and CSS. It's my first time doing this type of exercise, so I'm having a little problem from the get-go with page dimensions.
I did my PS design using a 1920px page width, this is the fullscreen result. Writing CSS, I set header width to 1920px and logo width to 150px (as in the PS file). But I obtain this (don't worry about logo position).
As you can see, the page is very "zoomed in" and the scrollbar appears down below. I want to display the whole page without a scrollbar, just as in PS, keeping the same ratio between elements.
This is my HTML & CSS code for the header:
#logo img {
float: left;
width: 150px;
height: 150px;
}
#header {
position: absolute;
top: 0px;
left: 0px;
width: 1920px;
/* I also tried width: 100% */
height: 100px;
background: #000000;
}
<div id="header">
<div id="logo">
<img src="..\codice\export\logo.png" alt="logo">
</div>
</div>
As shown in the code, I also tried setting the header's width to 100% but this way the logo proportion (150 px / 1920 px) was not respected.
How can I write in CSS: "1920 should be your 100% when visualizing the page with the browser"?
I'm sorry if this is a silly question but it's my first time working with these tools.
I made this jsfiddle
You can check with a fluid width: 100% you should not have this horizontally scrollbar
Then i added a header_content div with a fixed width of 520px (then you can see it is centered and well placed. but you will need to change that value according to your photoshop header width.
Note : css margin:0 auto makes your div centered horizontally.
Some additional HTML and CSS may solve the problem for you! And I'm considering you have to add the menu which you not yet done. Here is my solution. I put some helpful comment that you help you to understand the code properly. You can have same code at my codepen example.
body {
padding-top: 150px;
/* if you don't add this your code will be hidden under the #heade */
}
#logo img {
float: left;
width: 150px;
height: 150px;
}
#header {
position: absolute;
top: 0;
/*No need to add 'px' when the value is 0 */
left: 0;
/* I also tried width: 100% */
right: 0;
/*Thsi will cover the right side. So no need to declear a width*/
/* logo has some space at to so we are adding a padding at top*/
padding-top: 25px;
height: 75px;
/* reduce to 75px so header will be just half of the logo image*/
background: #000000;
}
.container {
width: 1170px;
/* hae to make this responsive for smallar devices*/
box-sizing: border-box;
margin: 0 auto;
}
.navigation {
float: right
}
/*Eacaping the proper code for the navigation so here is some face code */
.navigation {
color: #fff;
}
<div id="header">
<div class="container">
<div id="logo">
<img src="http://www.logospng.com/images/22/itunes-12-logopng-wikimedia-commons-22786.png" alt="logo">
</div>
<nav class="navigation">
Home Link1 link2 ecc
<!-- I escaping the coding of nav here -->
</nav>
</div>
</div>
I currently have a modal which i want to use as overlay over webpage.
HTML:
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="imgCon">
<img class="overlayimg" src="img/trendoverlay.png" />
<img class="overlayimg" src="img/trendtimeline.png" style="display: block"/>
</div>
</div>
CSS:
*{
box-sizing: border-box;
}
body{
width:100%;
}
.imgCon{
position: absolute;
height: 100%;
width: 100%;
padding: 0 51.5px 73px;
text-align: center;
}
.overlayimg{
max-width:100%;
max-height: 100%;
height:auto;
}
However here's the problem. The first image(top one) when only image. It's perfect. It works fine.
The image that goes underneath has to stay inside the same DIV as the other image, be as wide as the upper image. But height is fixed. Is there a way to achieve this so they still scale with the padding of 51.5px left/right and 73px at bottom?
picture with more info:
Example
Fiddle:
https://jsfiddle.net/4n1quv9n/1/#&togetherjs=sT7KVDhPT8
As you can see the top image scales how I want it to scale. That it keeps it's aspect ratio but had a minimum left/right and bottom. The image underneath the one is suppose to have the same width as the top image. But the height has to be fixed at 110px. But the Div which contains the images must keep the padding at those 2 minimum at the sides and bottom.
This is going wrong:
https://imgur.com/a/ILPpO
Here the bottom image must also scale as wide as the top image. And actually they also need to stick together so it looks like 1 image instead of 2 seperate ones.
Give this a Try
CSS
body{
position: relative;
}
.wrapper{
position: relative;
}
div.image-container{
position: absolute;
margin:auto;
height: 100%;
max-width: 100%;
padding: 0 51.5px 73px;
text-align: center;
}
img{
max-width:100%;
}
HTML
<body>
<div class="wrapper">
<div class="image-container">
<img src="http://imgur.com/c7uASdV.png">
<img src="http://imgur.com/60d6BUt.png" style="height: 110px">
</div>
</div>
</body>
Link for reference
You could give a try to display:table properties to draw a cell at middle to hold and resize first image, and absolute positionning for second image :
#modal {
display: table;
height: 100vh;
width: 100vw;
padding-bottom: 73px;/* bottom limits */
box-sizing: border-box;
}
#modal:before,
#modal:after {
content: '';
padding-left: 51px;/* sides limits ... pixel cannot be cut in hlves */
display: table-cell;
}
.modchild {
display: table-cell;
position: relative;
margin-bottom: 100px;/* room for img 2 */
width: 1%; /* will expand to fit image width and will stand at middle */
}
img[src*="x212"] {
height: 100vh;/* size it */
max-height: calc(100vh - 100px - 73px);/* downsize to use */
display: block;/* or reset vertical-align*/
}
img[src*="x100"] {/* size and stretch it */
margin: 0;
position: absolute;
left: 0;
right: 0;
width: 100%;
height: 100px;
bottom: 0;
}
* {margin:0;}
<div id=modal>
<div class=modchild>
<img src="http://dummyimage.com/400x212&text=keep_ration" />
<img src="http://dummyimage.com/400x100/ff0&text=distort" />
</div>
</div>
fiddle example : https://jsfiddle.net/4n1quv9n/4/
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.
I'm having an issue with a fluid sidebar and a content box next to it.
I designed my left #sidebar to my liking, but not I'm having trouble making a content box that fills up the remaining space next to it.
I'd like to have the whole project take up 100% of the page width. The problem is coming from the min/max widths on my sidebar.
Been goin' hard on this all day and still having problems, void space between, overlapping ,ect.
http://jsfiddle.net/DrDavidBowman01/PjLgE/
CSS
#container {
width: 100%;
display: block;
height: 100%;
}
#sidebar {
display: block;
width: 22%;
float:left;
min-width: 236px;
max-width: 332px;
height: 100%;
position: fixed;
border: 2px solid #0C6;
background-color: #000;
}
#content {
width: 88%;
height: 400px;
border: 6px solid #F00;
display: block;
color: #fff;
float: left;
position: relative;
max-width: calc(88% - 236px);
min-width: calc(88% - 332px);
}
HTML
<div id="container">
<div id="sidebar"></div>
<div id="content"></div>
</div>
It's a combination of two things. First, if you want to have divs take up 100% height, then you'll need to set the body and html to that as well.
html, body {
height: 100%;
}
Second, you have set the sidebar as position: fixed. This is just like having position: absolute set on it. If you want the sidebar to remain visible at all times, you can do a margin-left: 22%; (or whatever the width of the sidebar is) on #content. If you want the sidebar to flow with the rest of the page, just remove the fixed position.
This is because your sidebar is position: fixed. The best route would be to relatively position/float the sidebar at 100% height and position a fixed wrapper within it.
basic demo
I'm having a problem with a design I'm coding that I intend to make creative. Right now, I have a header that has 3 separate areas, one div in the middle with 30% width and two on either side with 35%. In these I contain my header elements. The middle one contains my logo, which scales just fine. When I re size the window it scales down and maintains it's positioning inside the div.
The problem arises when I try to add the navigation on either side. I have the navigation text inside the first div currently, and it doesn't behave how I intend it to. I have it relatively positioned and it doesn't maintain that positioning. When the browser is re-sized the text remains fixed, so at some point, as the divs grow smaller, the text is completely outside it's containing div. Also, at some point the text begins to stack instead of maintaining it's in-line style. I have a separate style sheet that has a few font size media queries to remedy this, they simply drop the font size at certain intervals, but this doesn't do anything. The text gets smaller, but still remains fixed on re-size and breaks out as well as begins to stack.
I simply cannot figure out why this is happening. The logo image remains perfectly in it's div and maintains it's position whilst the text doesn't move at all. I guess I'm just not understanding text properties as well as I need to I've included the HTML and CSS below, I left out the media queries as it's pretty self explanatory.
<div id=container>
<div id=header>
<div id=headerone>
<div id=leftnav>
<ul>
<li>Home</li>
<li>Services</li>
</ul>
</div>
</div>
<div id=headertwo>
<img src="images/title.png">
</div>
<div id=headerthree>
</div>
</div>
and the CSS
html, body {
width: 100%;
height: 100%;
margin:0;
font-size: 100%;
padding:0;
}
img {
max-width:100%;
width: 100%;
}
ul {
list-style: none;
}
ul li{
text-decoration: none;
color: white;
display: inline-block;
padding: 20px;
}
#container{
width: 100%;
height: 100%;
}
#header{
background-size: auto 100%;
width: 100%;
height: 19.1%;
background-image: url(images/headerbg2.jpg);
}
#header img{
width: 70%;
position: relative;
left: 15%;
top: 30%;
}
#headerone{
width: 35%;
height: 100%;
float: left;
background-color:black;
}
#leftnav{
word-break:keep-all;
font-size: 1.5em;
position: relative;
left:10%;
top: 40%;
font-family:Rockwell Extra Bold, Georgia, "Times New Roman", Times, serif
}
#headertwo{
width: 30%;
height: 100%;
float: left;
}
#headerthree{
width: 35%;
height: 100%;
float: left;
background-color:green;
}
I appreciate any help.