I'm trying to make a div that contains 3 div, and each div contain an img.
But I want to make the first div (top) have a height of 10% of the screen size, the second (middle) 60%, and third (bottom) 30%. And actually, they don't resize, and they have their full size.
My code is actually :
#droite
{
display:block;
float:left;
margin-left:81%;
width:19%;
height:100%;
}
.logo
{
top-margin:0%;
height:10%;
width:100%;
}
.DroiteMilieu
{
top-margin:10%;
width:100%;
max-height:60%;
height:100%;
}
.basDePage
{
top-margin:80%;
height:30%;
width:100%;
}
img
{
position:absolute;
}
(#droite is actually the big division, in which logo is the first div, droiteMilieu the second and basDePage the third one. (I will rename them soon, but I want it to work first /:) )
And the html :
<div id="droite">
<div class="logo">
<img src="logo.png" style="max-width:100%; max-height:100%; position:relative;"</img>
</div>
<div class="DroiteMilieu">
<img src="droite.PNG" style="max-width:100%; max-height:100%; position:relative;"</img>
</div>
<div class="basDePage">
<img src="minimap.png" style="max-width:100%; max-height:100%; position:relative;" </img>
</div>
</div>
I'm actually still bad with html/css, and I don't understand where my error is located. :/
Can someone help me?
EDIT [Problem Solve] :
A way to make it works is :
CSS :
html, body {
margin: 0;
height: 100%;
width:100%;
}
#droite {
display:block;
float:left;
margin-left:81%;
width:19%;
height:100%;
}
.logo {
height: 10%;
background: red;
}
.DroiteMilieu {
height: 60%;
background: blue;
}
.basDePage {
height: 30%;
background: green;
}
#droite img {
max-width: 100%;
max-height: 100%;
position: relative;
}
And HTML :
<div id="droite">
<div class="logo">
<img src="logo.png" style="width:100%; height:100%;">
</div>
<div class="DroiteMilieu">
<img src="droite.PNG" style="width:100%; height:100%;">
</div>
<div class="basDePage">
<img src="minimap.png" style="width:100%; height:100%;">
</div>
</div>
Here is a solution for you.
You don't need margin top and width, as they default to 100% width and stack on top.
To make the floated div to have 100% height, the body needs too, so I added that.
html, body {
margin: 0;
height: 100%;
}
#droite {
display:block;
float:left;
margin-left:81%;
width:19%;
height:100%;
}
.logo {
height: 10%;
background: red;
}
.DroiteMilieu {
height: 60%;
background: blue;
}
.basDePage {
height: 30%;
background: green;
}
#droite img {
max-width: 100%;
max-height: 100%;
position: relative;
}
<div id="droite">
<div class="logo">
<img src="logo.png">
</div>
<div class="DroiteMilieu">
<img src="droite.PNG">
</div>
<div class="basDePage">
<img src="minimap.png">
</div>
</div>
You made a few mistake, first of all, top-margin is not a valid property. You have to use margin-top.
Secondly, If you add height: 100%; you're asking your div to take 100% of the space of its parent (in this case, is your div taking 100% of the screen height?).
To answer your question, the way to do it, if your project only have to support CSS3, i'd suggest you to use the property: vh or viewport height.
Here is a little tutorial on it:
https://web-design-weekly.com/2014/11/18/viewport-units-vw-vh-vmin-vmax/
You can use it this way:
.droite{
height: 10vh; /* If you need 10% of the viewport height, then you write it this way */
}
In other words, 1vh = 1% of the viewport height.
You are setting height: 100% on .DroiteMilieu which inherits from droite and makes it 100%. That might push the others out.
Remove the max-height: 60% on .DroiteMilieu and set height: 60%; see what you get.
plus top-margin: is not a valid css attribute
.DroiteMilieu
{
top-margin:10%; <---- bad css
width:100%;
height: 60%; <----
}
Related
first of all I am trying to programming a website...
Now my question:
I want to have on the left side of my website a div which has a height of 100% and a width of 250px
On the right side of my website I want a div which has a height of 100% and a width of 100% too...
BUT
If I do this then my right div is to big for my Monitor but I want to have it perfectly fit so that i dont need to scroll to the right..
PS: I want that the left div is fixt on 250px width!
Hopefully anyone know what I mean
The white one is the left div | The black one is the right div
You can try flex: for more visit HERE
html, body {
height: 100vh;
}
#parent{
display: flex;
height: 100%;
}
#child1{
width:250px;
background-color:green;
}
#child2{
flex-grow: 1;
background-color:red;
}
<div id='parent'>
<div id='child1'>child1</div>
<div id='child2'>child2</div>
</div>
you want two divs? this should work
<body style="margin: 0px; padding: 0px;">
<div id="contairofthemall" style="width: 100%;">
<div id="divone" style="height:100%; width:250px; position: absolute;"></div>
<div id="divtwo" style="height:100%; width:100%; "></div>
</div>
</body>
html, body {}
#parent{
display: flex;
height: 100%;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
}
#child1{
width:250px;
background-color:green;
}
#child2{
flex-grow: 1;
background-color:red;
}
<div id='parent'>
<div id='child1'>child1</div>
<div id='child2'>child2</div>
</div>
I'm working on a project and I got to a place where I decided to realized a collage.
I have done the collage already and it is here: Fiddle
But I would like to do the same thing without using the property float on the elements of div1.
If possible, I would like to use only the properties right and left on the element of div1 without reducing the size of the elements of that div.
Sorry I'm not a native English speaker, I'm trying my best.
Hopefully, you would like to see something like this:
body {
width: 380px;
margin: 0 auto;
}
.div1{
text-align:justify;
}
.div1:after {
content: "";
display: inline-block;
width: 100%;
}
.div1 span img{
width:45%;
}
<div class="div1">
<span><img src="https://picsum.photos/189/324?random=1" alt="rd1"/></span>
<span><img src="https://picsum.photos/189/324?random=2" alt="rd2"/></span>
</div>
<div class="div2">
<img src="https://picsum.photos/380/325?random=3" alt="rd3"/>
</div>
My comment: I have set an 'img' width value to 45%, but you could set it to any value which will be equal or less than 50%. By the way, I suggest you to use tag 'span' instead of 'p' because 'span' ,in my opinion, is more suitable for this purpose. If you will use my approach you will be able to add any number of images to parent 'div' tag. For example, if you will add any number of images and their total width will be equal or less than 100%, these images are will be placed evenly on row.
This is what you asked for. But I recommend not to go with this approach. Extending it will be a nightmare. If image sizes change then it will be impossible to fix with with just CSS.
body {
width: 380px;
margin: 0 auto;
}
.div1{
position:relative;
height:324px;
}
.div1 p {
margin-bottom: 0;
margin-top: 0;
width:50%;
position:absolute;
}
.div1 p:first-child {
left:0px;
}
.div1 p:last-child {
left:50%;
}
<div class="div1">
<p><img src="http://lorempixel.com/189/324/" alt=""/></p>
<p><img src="http://lorempixel.com/189/324/" alt=""/></p>
</div>
<div class="div2">
<img src="http://lorempixel.com/380/325/" alt=""/>
</div>
you can use display: flex; like that you dont have to use float
body {
/* width: 520px;*/
margin: 0 auto;
}
/*.div1 p {
margin-bottom: 0;
margin-top: 0;
}*/
.div1 {
display:flex;
justify-content:center;
}
.div2{
display:flex;
justify-content:center;
}
<div class="div1">
<img src="http://lorempixel.com/189/324/" alt=""/>
<img src="http://lorempixel.com/189/324/" alt=""/>
</div>
<div class="div2">
<img src="http://lorempixel.com/380/325/" alt=""/>
</div>
you mean something like this?
.div1 {
left: 0;
right: 0;
text-align: center;
margin: auto;
}
.div2 {
left: 0;
right: 0;
text-align: center;
margin: auto;
}
<div class="div1">
<img src="http://lorempixel.com/189/324/" alt=""/>
<img src="http://lorempixel.com/189/324/" alt=""/>
</div>
<div class="div2">
<img src="http://lorempixel.com/380/325/" alt=""/>
</div>
Learning my way through this...
I'm working toward setting up rows of divs - I don't want any space between them and am not sure what properties to look for to adjust as the width changes.
I'm getting either a 1px gap appearing/disappearing as the images scale, or getting one of the divs bumped down to the next line.
The odd thing is that both rows are basically the same, so I'm lost here.
Here's the current page:
http://www.turnerdesign.com/brackets/
thanks
Andrew
To lose the gaps:
Remove the height: auto; and set a height.
#media screen and (max-width: 959px)
#column700 {
width: 73%;
height: 50px;
float: left;
}
/* Do the same for the other column */
}
For gaps:
(I wrote this first, then re-read the question and was like, OMG I did a whole answer for another question as I didn't understand it at first, but just incase someone needs gaps, here's how)
HTML:
<div class="column700">
<div id="firstProject">
</div>
</div>
CSS:
#firstProject {
width: 100%;
padding: 10px;
background: blue;
}
You have multiple elements with the same id on your page. If you want to add the same style to many elements, use class.
Add style="clear: left;" to the div containing image with a canyon.
Please use this code
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<style>
#image {
display: block
}
#container{
width: 960px;
margin: 0px auto;
}
#header{
width:100%;
height:auto;
margin-bottom: 0px;
float: left;
line-height: 0;
}
#name{
height:50px;
background:none;
width:300px;
float: left;
line-height: 0;
vertical-align: top;
}
#contact{
height:30px;
background:none;
width:auto;
float: right;
line-height: 0;
}
.image-container{
vertical-align: top;
width: auto;
height:auto;
background:#296db1;
background-size: cover;
line-height:0;
}
.div-left{
float: left;
}
#media screen and (max-width:959px){
.image-container{
float:left;
}
#container{
width: 100%
}
#column700{
width: 73%;
}
#column260{
width: 27%;
}
img {
width: 100%;
height:auto;
}
}
#media screen and (max-width:640px){
.image-container{
float:left;
}
#container{
width: 100%
}
#column700{
width: 73%;
}
#column260{
width: 27%;
}
img {
width: 100%;
height:auto;
}
}
#media screen and (max-width:320px){
.image-container{
float:left;
}
#container{
width: 100%
}
.image-container{
width: 320px;
}
img {
width: 100%;
height:auto;
}
}
.row2{
clear:both;
}
</style>
</head>
<body>
<div id="container">
<div id="name">
<p style="font-family:Arial; color:#d1d1d1; font-size:1.5em">Title | Description</p>
</div>
<div id="contact">
<p style="font-family:Arial; color:#d1d1d1; font-size:1.5em">Menu</p>
</div>
<div id="header">
<img src="http://www.turnerdesign.com/brackets/images/banner.jpg" block;="" style="display:">
</div>
<div class="row-container">
<!--row 1-->
<div class="row row1">
<div class="image-container div-left" id="column700">
<img src="http://www.turnerdesign.com/brackets/images/blake.jpg">
</div>
<div class="image-container" id="column260">
<img src="http://www.turnerdesign.com/brackets/images/canyonmap.jpg">
</div>
</div>
<!--row 2-->
<div class="row row2">
<div class="image-container div-left" id="column260" style="">
<img src="http://www.turnerdesign.com/brackets/images/canyon.jpg">
</div>
<div class="image-container" id="column700">
<img src="http://www.turnerdesign.com/brackets/images/warrior.jpg">
</div>
</div>
</div>
</div>
</body>
</html>
You can also see the - jsfiddle.net demo link.
You can always think about optimizing the code further:
Optimize / minimize the number of css lines in each media-query.
Manage img parameters more smartly for all media queries.
Restructure the HTML so it becomes more manageable.
Your problem doesn't actually come from the widths applied to your divs, but because of the heights of images.
what is happening here is that in your second row, you have one 700x100 image followed by a 260x100 image. Their ratios aren't the same, so you can understand that commanding their widths will have different effects on their respective heights.
In the end, at some window width, you end up with 1px difference between your images' heights (most often the first one being higher). That causes the 3rd row to actually be pushed to the right, since it has a 1px height to fill first. However, there is only enough room for the smaller image, so the browser breaks a new line for the bigger one.
Solutions:
put a clear: left; on every image at the start of a new line. It will solve this problem, but the 1px height difference will still be there and a white line between your smaller image and the next line will appear.
PS: i'll edit this post if i find better solutions.
I've been trying to get this image centered in the page for a while, and for some reason margin-left: auto; margin-right: auto; weren't doing anything. So in the spirit of wildly trying everything in sight, I stumbled on the following surprisingly correct result. My question is, why on earth does setting the width to 25% work? I would have expected 100%, or 50% at least.
This fiddle shows some other widths, which apparently behave in a nonlinear fashion: http://jsfiddle.net/mo85kkvv/
(Bonus question: is there a super-obvious way to use the margin-left/right properties instead that I'm missing?)
HTML:
<body>
<div id="bcontainer">
<img src="banner.png" alt="banner" />
</div>
</body>
CSS:
body {
margin: 0;
}
#bcontainer {
width: 25%; /* why 25%?? */
height: 50px;
display: table-cell;
text-align: center;
}
I don't know a lot about HTML but I think that the proper way to define the class container is:
.container {
height: auto;
display: block;
margin:auto;
}
This is more generic. You can use the element inspector, and see how the layers change.
Is what your after ? http://jsfiddle.net/mo85kkvv/4/
HTML
<body>
<div class="container" id="one">
<img src="http://www.clker.com/cliparts/6/J/D/n/z/V/gold-scroll-banner.svg" alt="banner" />
</div><br>
<div class="container" id="two">
<img src="http://www.clker.com/cliparts/6/J/D/n/z/V/gold-scroll-banner.svg" alt="banner" />
</div><br>
<div class="container" id="three">
<img src="http://www.clker.com/cliparts/6/J/D/n/z/V/gold-scroll-banner.svg" alt="banner" />
</div><br>
<div class="container" id="four">
<img src="http://www.clker.com/cliparts/6/J/D/n/z/V/gold-scroll-banner.svg" alt="banner" />
</div>
</body>
CSS
body {
}
.container img{
width:100%;
display: inline;
text-align: center;
margin: 0 auto;
}
#one {
width: 25%;
margin: 0 auto;
}
#two {
width: 50%;
margin: 0 auto;
}
#three {
width: 75%;
margin: 0 auto;
}
#four {
width: 100%;
margin: 0 auto;
}
It all depends what you want. Do you want the wrapper to be centered with the image floating in the center, or do you want the wrapper (in this case .container) to shrink around the image and be the one that floats in the center? I have updated your fiddle with simple examples of a few options.
http://jsfiddle.net/mo85kkvv/6/
I want to make for my marketing site a 3 column layout that has images in the top banner.
I want to have a liquid left/right side with a fixed center. The html would ideally look like this:
<div id="pixelLeft"> </div>
<div id="bannerCenter">
<img src="images/mybanner.png" />
</div>
<div id="pixelRight"> </div>
<style>
#pixelLeft { background: url(../../images/pixel_left_fixed.png) 0 0 repeat-x; }
#pixelRight { background: url(../../images/pixel_right_fixed.png) 0 0 repeat-x; }
#bannerCenter { /* something here to make fixed width of 1550px */ }
</style>
The images in the left/right pixel sides are 1px x 460px.
The image mybanner.png is 1550px x 460px.
Thanks in advance! (Especially if it will work in ALL browsers!)
Is this helpful?
CSS Only Demo
jQuery Demo(Cross Browser Compatible)
<div class="wrap">
<div id="pixelLeft"> </div>
<div id="bannerCenter">
<img src="images/mybanner.png" />
</div>
<div id="pixelRight"> </div>
</div>
<div style="clear:both;"></div>
*{
margin:0;
padding:0;
}
#bannerCenter{
background:#ddd;
width: 500px;
float:left;
}
#pixelLeft{
background:#999;
width: calc(50% - 250px);
float:left;
}
#pixelRight{
background:#999;
width: calc(50% - 250px);
float:right;
}
#bannerCenter,#pixelLeft,#pixelRight{
height: 400px;
}
You can use jQuery instead of using calc(50% - 250px); to make it compatible for older browsers.
$(document).ready(function() {
$(window).on('resize', function() {
$('#pixelLeft, #pixelRight').css('width',($('body').width()-$('#bannerCenter').width())/2);
}).trigger('resize');
});
Update: June 2018
Added flexbox solution for same problem.
*{
margin:0;
padding:0;
}
.wrap {
display: flex;
}
#pixelLeft, #pixelRight{
display: flex;
flex:1;
}
#bannerCenter{
background:#ddd;
min-width: 500px;
display: flex;
flex: 1;
}
#pixelLeft{
background:#999;
}
#pixelRight{
background:#999;
}
#bannerCenter,#pixelLeft,#pixelRight{
height: 400px;
}
<div class="wrap">
<div id="pixelLeft"> </div>
<div id="bannerCenter">
<img src="images/mybanner.png" />
</div>
<div id="pixelRight"> </div>
</div>
Here's a good solution, in my opinion the easiest one. It looks clean and it doesn't need wrapper div.
Demo
HTML
<body>
<div id="left_container">
<div id="left">
left content
</div>
</div>
<div id="center">
center content
</div>
<div id="right_container">
<div id="right">
right content
</div>
</div>
</body>
CSS
#left_container {
width:50%;
float:left;
margin-right:-480px; /* minus half of the center container width */
/* not important */
height: 200px;
}
#left {
margin-right:480px; /* half of the center container width */
/* not important */
background: #888;
height: 600px;
}
#center {
width:960px; /* size of the fixed width */
float:left;
/* not important */
color: #FFF;
background: #333;
height: 500px;
}
#right_container {
width:50%;
float:right;
margin-left:-480px; /* minus half of the center container width */
/* not important */
height: 300px;
}
#right {
margin-left:480px; /* half of the center container width */
/* not important */
height: 300px;
background-color: #888;
}
enjoy!
There are several solutions to this, probably the post popular of which is the Holy Grail method. It's a little above my head, but these links explain it pretty well.
http://alistapart.com/article/holygrail
http://matthewjamestaylor.com/blog/perfect-3-column.htm
I would start with A List Apart's article. Good luck.
After re-reading it, I think this is what I would do:
HTML
<div id="header">
</div><div id="container">
<div id="center" class="column"></div>
<div id="left" class="column"></div>
<div id="right" class="column"></div>
</div><div id="footer"></div>
CSS
body {
min-width: 550px; /* 2x LC width + RC width */
}
#container {
padding-left: 200px; /* LC width */
padding-right: 150px; /* RC width */
}
#container .column {
position: relative;
float: left;
}
#center {
width: 100%;
}
#left {
width: 200px; /* LC width */
right: 200px; /* LC width */
margin-left: -100%;
}
#right {
width: 150px; /* RC width */
margin-right: -150px; /* RC width */
}
#footer {
clear: both;
}
/*** IE6 Fix ***/
* html #left {
left: 150px; /* RC width */
}
You'll need to adjust some of the dimensions, but the inline comments should help with that. So there you have it. The Holy Grail Layout.
<body>
<div style=" width: 200px; float: left; background: red; height: 100px;">Left</div>
<div style=" float: right; width: 200px; background: red; height: 100px;">Right</div>
<div style=" background: blue; margin:0 auto; height:100px;">Center content goes here</div>
</body>
Here is simple trick through html and css only to do such a layered structure and it will keep middle layer in center even if you will resize browser.