I'm seasoned webdesigner, so I don't know much about this art.
I got three elements placed horizontally (left/center/right) which have fixed size:
.banner-box {
position: relative;
display: inline-block;
width: 300px;
height: 400px;
margin: 0 auto;
}
and inside every div there are few images, that are centered horizontally and general style for img is:
img {
max-width: 100%;
}
to make them fluid.
But since divs are not flexible, images inside them also won't change their size when resizing browser window.
Is it possible to set fixed size on any html element and still somehow make it fluid?
I know I could use percentages instead pixels, but I've got also problems with setting proper height for .banner-box using percents - box doesn't stretches to desired 400px, only to 281px.
Here's html:
<div id="footer">
<img src="footer-line.png" alt="Footer.png" />
<p><span>some span</span> blah</p>
<p>mail: <span>mail#domain.com</span></p>
</div>
And whole css for my simple webpage:
html {
background: url('mu-media-background-1920.png') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: 100% 100%;
}
img {
max-width: 100%;
}
#container {
width: 1200px;
margin: 5% auto;
text-align: center;
}
#header {
display: block;
clear: both;
position: relative;
width: 100%;
margin: 0 auto;
}
#content {
display: block;
width: 95%;
height: auto;
margin: 10% auto 5% auto;
}
.banner-box {
position: relative;
display: inline-block;
width: 300px;
height: 400px;
margin: 0 auto;
}
.banner-text {
position: relative;
display: block;
top: 7%;
margin: 0 auto;
}
.see-more-button {
position: absolute;
display: block;
margin: 0 auto;
left: 0; right: 0; bottom: 0;
}
#virtual-studio {
float: left;
}
#mu-animation {
float: right;
}
#shadows {
display: block;
clear: both;
position: relative;
width: 100%;
}
#shadows img {
display: block;
clear: both;
position: relative;
margin: 0 auto;
}
#footer {
display: block;
clear: both;
width: 95%;
margin: 0 auto;
font: 15px Arial, Helvetica, sans-serif;
}
#footer p {
display: table;
clear: both;
position: relative;
margin: 0 auto;
color: #AFBEA5;
text-align: center;
width: auto;
}
#footer span {
font-weight: bold;
color: #BDC9AF;
}
I'm preparing responsive layout, so it would be best (afaik) to use only percentages.
Here is a good hybrid approach that has worked well for me in the past.
As you've already mentioned you could use percentage widths to build a fluid layout, and then restrict/fix specific div sizes with max and min values. So for example:
#container {
width: 100%;
max-width: 1200px;
}
Here is a working example with the banner boxes restricted to max 300px width and min 400px height (I added some padding and borders so you can see what is going on): jsfiddle
In the end you'd still have to adjust your responsive media queries to deal with your fixed elements, but this way you'd only have to change a few min and max values.
You will need to use media queries and define fixed widths/heights for .banner-box for each screen break point that you choose.
You'll have to play with the sizing and see which sizes fit best for which break points.
Related
I am new to web development and so to Stackoverflow.
I am stuck at changing width to make it responsive.
Below, I have got this example that's meant to be explaining the property background-blend-mode. After I finished with it I wanted to use it as a refresher to previous lessons. I wanted to style it to make it responsive in terms of changing the max and min width properties.
div {
width: 280px;
height: 140px;
padding: 30px;
margin: 10px;
display: inline-block;
background: green url(https://mdn.mozillademos.org/files/13090/colorful-heart.png) no-repeat center 0;
background-size: contain;
}
.multiply {
background-blend-mode: multiply;
}
<html>
<div>
</div>
<div class="multiply">
</div>
</html>
What happens is when the viewport's width (at Chrome) changes to less than 740px the divs display as block element. When I got to use thebox-sizingproperty to set its value to border-boxit changed the break point to 620px instead of 740px which means that any width under 620px makes the divs still display as block elements.
What I am stuck at is set a responsive viewport for these divs so they are always displayed as inline elements, no matter what viewport's width is.
Thank you
Check this one
div {
width: 280px;
height: 140px;
padding: 30px;
margin: 10px;
display: inline-block;
background: green url(https://mdn.mozillademos.org/files/13090/colorful-heart.png) no-repeat center 0;
background-size: contain;
}
.multiply {
background-blend-mode: multiply;
}
#media only screen and (max-width: 767px) {
body {
text-align: center;
}
div {
width: 48%;
height: auto;
margin: 15px 0;
padding: 13% 0;
}
}
<div></div>
<div class="multiply"></div>
What kind of responsive do you want? Responsive really just means responds to -- the screen size. So the behavior is really up to you. From exactly what I'm seeing you have two options.
Responsive in just the width. This means that as you scale down to smaller than the two block size they'll scale down width wise only. To achieve this you set you max-width to 280px then because you have two objects you want to set the width to 50%. The problem with this is at some point you'll end up with very narrow blocks.
div {
max-width: 280px;
height: 140px;
padding: 30px;
margin: 10px;
display: inline-block;
background: green url(https://mdn.mozillademos.org/files/13090/colorful-heart.png) no-repeat center 0;
background-size: contain;
width: 50%;
}
.multiply {
background-blend-mode: multiply;
}
https://jsfiddle.net/6fjcoxmt/4/
Responsive in aspect radio. The other option is keeping the aspect ratio where you need to use a technique with an pseudo element that holds the parent's aspect ratio. You still need to use the technique from 1. but it gets a bit more complicated. Your element's wrapper will need to control the aspect ratio.
<div>
<div class="inner"></div>
</div>
<div class="multiply">
<div class="inner"></div>
</div>
Notice now .inner was your previous element's visual and the parent div will focus on controlling the height to width ratio:
div {
display: inline-block;
margin: 10px;
max-width: 280px;
position: relative;
width: 50%;
}
div:after {
content: "";
display: block;
padding-bottom: 58.8%;
}
.multiply .inner {
background-blend-mode: multiply;
}
.inner {
background: green url(https://mdn.mozillademos.org/files/13090/colorful-heart.png) no-repeat center center;
background-size: contain;
bottom: 0px;
height: 100%;
margin: 0;
position: absolute;
top: 0px;
width: 100%;
}
https://jsfiddle.net/6fjcoxmt/16/
Try it. I have added some css and media query for responsive.
* {
padding:0;
margin:0;
list-style:none;
}
html {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
*, *:before, *:after {
-moz-box-sizing: inherit;
-webkit-box-sizing: inherit;
box-sizing: inherit;
}
.common {
width: 340px;
height: 200px;
padding: 30px;
margin: 10px;
display: inline-block;
background: green url(https://mdn.mozillademos.org/files/13090/colorful-heart.png) no-repeat center 0;
background-size: contain;
}
.multiply {
background-blend-mode: multiply;
}
#media screen and (max-width:767px){
.common{
width:45%;
height:auto;
margin: 10px auto 10px;
padding: 14%;
}
.wrap{
text-align:center;
}
}
<html>
<div class="wrap">
<div class="common"></div>
<div class="common multiply"></div>
</div>
</html>
RE this on eBay: http://www.ebay.com/itm/281670060888
On my own site (at http://sallymilo.com/template-din.html) and when running on my own computer, the right side div aligns to the top of the left side div, but when I put it on eBay, the right side div is below the left - even if I make the tabbed section 200 pixels narrower.
A bit of the main CSS:
.row1 {
width: 100%;
position: relative;
float: left;
background: url(https://myimagefiles.com/dinnerman/tbg.png);
}
.row1l {
width: 26%;
position: relative;
margin-left: 2em;
float: left;
}
.row1r {
width: 64%;
position: relative;
margin-left: 2em;
margin-right: 2em;
float: left;
}
And a bit of the tabbed section CSS:
.tabholder {
width: 100%;
height: 14em;
font-size: 16px;
}
/* base font size for em-scaling */
.tabholder div.tabtops {
width: 100%;
max-width: 550px;
}
The issue is that in ebay the width of the container is lower than 1000px.
The because of the fact that your inner sections with hardcoded widths they break.
I suggest you to use width with %, in that way not matter what will be the with of the container the inner sections will take the number of the percentage that you gave.
.container {
margin: 20px;
background-color: rgba(0,0,0,0.2);
overflow: hidden;
}
.col-1 {
width: 20%;
background-color: rgba(0,0,0,0.2);
float: left;
}
.col-2{
width: 80%;
background-color: rgba(0,0,0,0.5);
float: left
}
<div class="container">
<div class="col-1">col-1</div>
<div class="col-2">col-2</div>
</div>
Page is here
I am using a sticky footer, which works fine everywhere but my portfolio page. The gallery is relatively positioned, and is overflowing from it's parent div. The footer is sticking to the bottom of the parent, rather than the page.
Help? Preferably in a way where I don't have to rewrite all my code?
Please try this one i hope it will helpful to you.
html, body {
height: 100%;
}
header {
background: #fff;
position: relative;
z-index: 100;
}
.content2 {
clear: both;
margin: 0 auto;
padding: 0;
text-align: center;
width: 70%;
}
.gallery {
display: table;
height: 100%;
margin-left: auto;
margin-right: auto;
margin-top: auto;
position: relative;
width: 100%;
}
#footer-block {
bottom: 0;
position: fixed;
width: 100%;
}
Thanks
Fixed it by coding body and html to 110% height, footer wrapper to 100% height, and adding page wrapper with 100% height.
I'm trying to layout a screen using div's and CSS. It's a simple layout at this point but I can't seem to get the div's to line up. I want one wrapper div with two div's within it: one aligned to the left and one aligned to the right. However, they end up on top of each other.
I know this question is simple. What am I missing here?
If I reduce the width of the right div to 60% it lines up right but shouldn't I be able to use 100% of the width of the parent div?
#product_wrapper {
display: inline-block;
height: 75%;
width: 75%;
background-color: white;
text-align: top;
margin: 0 auto;
}
#images_wrapper {
background-color: red;
display: inline-block;
height: 100%;
width: 30%;
margin: 0;
padding: 0;
}
#content_wrapper {
background-color: blue;
display: inline-block;
height: 100%;
width: 70%;
margin: 0;
padding: 0;
}
<div id="product_wrapper">
<div id="images_wrapper">Foo</div>
<div id="content_wrapper">Bar</div>
</div>
Float left your children elements:
jsBin demo
#product_wrapper > *{float:left;}
Note that inline-block causes the inner elements to actually act like inline elements
where white spaces count!
SO another way would be to modify your HTML removing the NewLine separator:
jsBin demo
<div id="images_wrapper">
Foo content
</div><div id="content_wrapper">
^^-------------------------------------- no space here
Bar content
</div>
The third way (the worst one) is to set font-size to 0 for the parent (will remove logically the child's white-space gap since is now '0'); >> and than reset the font-size for children elements to px (cause em will not work since parent has 0).
But that's a good way to loose track of dynamic and responsive font sizes expecially if you use em and size inheritances.
The problem is the whitespace in the html, which occupies some space between the elements.
One way of fixing it is
#product_wrapper {
font-size: 0; /* Hide whitespace in the html */
}
#images_wrapper, #content_wrapper {
font-size: 16px; /* Reset to whatever vaue */
}
#product_wrapper {
display: inline-block;
height: 75%;
width: 75%;
background-color: white;
text-align: top;
margin: 0 auto;
font-size: 0;
}
#images_wrapper, #content_wrapper {
font-size: 16px;
}
#images_wrapper {
background-color: red;
display: inline-block;
height: 100%;
width: 30%;
margin: 0;
padding: 0;
}
#content_wrapper {
background-color: blue;
display: inline-block;
height: 100%;
width: 70%;
margin: 0;
padding: 0;
}
<div id="product_wrapper">
<div id="images_wrapper">Foo</div>
<div id="content_wrapper">Bar</div>
</div>
Use float:left instead of display:inline-block
#product_wrapper {
display: inline-block;
height: 75%;
width: 75%;
background-color: white;
text-align: top;
margin: 0 auto;
}
#images_wrapper {
background-color: red;
float:left;
height: 100%;
width: 30%;
margin: 0;
padding: 0;
}
#content_wrapper {
background-color: blue;
float:left;
height: 100%;
width: 70%;
margin: 0;
padding: 0;
}
<div id="product_wrapper">
<div id="images_wrapper">Foo</div>
<div id="content_wrapper">Bar</div>
</div>
Id like to make a horizontal list, with image contents. The image size should follow the height of the ul, which reacts to the height of the container.
here is the fiddle: http://jsfiddle.net/nLcrW/
#container{
display: block;
position: absolute;
top: 15%;
height: 70%;
background: cyan;
}
.HList{
list-style: none;
padding: 0;
margin: 0;
white-space: nowrap;
}
.HList-Item{
display: inline-block;
height: 100%;
}
.HList img{
height: 100%;
}
Try to scale the container window in the fiddle. The images will overlapp when scaled up, and stretch when scaled down in Chrome and Firefox. It works perfectly in Safari.
Is there an other way to make this working, or a workaround for these browsers?
Here's an update of your FIDDLE.
Just adjust the size of the HList-Item, make the image 100% of that.
You can now play with the styling, add whitespace, remove it, embed the images in an anchor, etc.
CSS
#container{
top: 15%;
height: 70%;
background: cyan;
}
.HList{
list-style: none;
}
.HList-Item{
display: inline-block;
height: 5%;
width: 18%;
}
.HList img{
height: 100%;
width: 100%;
}