I have my heights set up properly so that it will stretch to the bottom, but it will not stretch passed the bottom, it simply stops and other content stretches beyond it.
If you take my code and put it in, you will see what I mean.
HTML:
http://pastebin.com/ScvdB4zs
CSS:
http://pastebin.com/mxrZ6Gd9
If I were you I would simply just take out the min heights and change the heights of both the .nav and the .dashboard to whatever you want. It is much more customizable. And just a suggestion: I would make the dashboard a certain percent, just so then people with a different size screen can have the same aesthetic pleasure.
Try adding an overflow to your nav div to extend the contents
.nav {
overflow:scroll;
background-color:#153E7E;
height:500px;
min-height:100%;
width:250px;
border-right:5px solid #151B54;
float:left;
}
Related
I am trying to fit an image to its full width of the browser. Please let me know CSS code for that. I am using px for container. So let me know according to that. I don't want scroll bars to full screen of the browser. I am trying width:100%, width in px. But nothing works I see scroll bar.
Images have their own display type in CSS, so when you say something like width:100%, it fills to 100% of the original image's dimensions rather than acting like a block and expanding to fill 100% of the parent element.
You can fix that by changing the display type, though only for that one image:
<style type="text/css">
img.big-img {
display:block;
width:100%;
}
</style>
…
<img src="my_image.jpg" class="big-img">
If you want it to depend on browser's viewport add this to your element's css and it will stretch automatically
background-size: 100% 100%;
img{
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
}
I have some fixed pixel divs on the top and bottom and a responsive one in the middle. How can I prevent it from going into the top div when the screen is adjusted small?
Here is a working example to illustrate the problem. I want to be able to make the browser small and not have the black box go into the red. While maintaining the responsiveness.
<div style="position:relative; height:100px; width:100%; background:red;"/>
http://jsfiddle.net/RHZLr
I would forget absolute positioning in this case. Make all the boxes relatively positioned, and use margins to position the black box as you please. This way responsiveness works as desired.
Working Fiddle
#blackBox{
margin: 0 auto;
height: 200px;
width: 400px;
background: black;
}
Instead of using width:100% try using a fixed width. Fixed widths don't move so you won't have to worry about them invading other divs.
Also!
It might behoove you to use CSS media queries to give the divs a fixed (non moving) position once the screen gets to a certain size.
e.x.
#div1{
position:relative;
left:25%;
width:50%;
}
#media screen and (max-width:600px){
#div1{
width:500px;
height:500px;
}
}
Working Pen!(codepen.io example)
I have an article styled like with this class:
.stretchedToMargin {
display: block;
position:absolute;
height:100%;
bottom:0;
top:0;
left:0;
right:0;
}
This is fine: the article takes always at least the whole vertical space. For articles longer than the screen, a scrollbar is shown.
But, for articles extending further than the screen, when I need to scroll to view the content, the background is not set. The article is split between a part with the right background and a part with the wrong background.
How can I force my article to be actually as high as the content, but at least as high as the viewport?
EDIT
Adding an example: http://jsbin.com/UvasEBik/1/
An the corresponding screenshot:
You could use min-height: 100vh which is 100% of the viewport height. So the article would be at least 100% of the viewport height.
So I know this is another centering question but I've been roaming around Google and SO for a couple days now without a solution so I'll ask now.
What I'm trying to do is horizontally center a fluid section element with a max width that has absolutely positioned elements inside it. The problem is, as you can see in my jsFiddle, the margins take up 50% of the available space with the other 50% used by the section. What I would like to do is keep the section perfectly centered but make the margins get smaller as the browser window closes in while keeping the section from re-sizing until the edges of the window gets to it.
I'd like to keep from using any table, table-cell solution because I read on CSS-Tricks that absolutely positioning elements inside table cells can be a real pain.
Edit Basically, the goal is to have the content take up as much space as possible without resizing until the view port width forces the content to be responsive.
Thank you for any bump in the right direction.
HTML:
<section id="wrapper">
<section id="content">
<p>Absolutely positioned imgs, btns, etc. go in here</p>
</section>
</section>
CSS:
#wrapper {
position:absolute;
width:50%;
height:300px;
margin-left:25%;
margin-right:25%;
outline:1px solid red;
}
#content {
position:absolute;
width:100%;
height:100%;
max-width:500px;
background:rgb(225, 112, 75);
}
You can use
#content {
display:inline-block;
text-align:center;
}
to center your elements that will have a display:inline-block; property too.
EDIT: Now that I've better read your question, you can also use
#content {
margin:0 25%;
}
to center your second section.
here's your fiddle updated. As you can see by this fiddle everything is centered AND responsive now.
EDIT-2: Maybe you want to add some media query to reach your goal. Just add something like this at the end of your CSS file:
#media screen and (max-width:720px){
#content{width:100%; margin:0px;}
}
this says that when screen reaches the width of 720 and under, #content (and every ID/CLASS you put in there) will behave as declared.
NOTE that #media queries are not crossbrowser, you may want to add a script to make them work on every browser, I find respond.js a nice tool to do this job.
Also note that the #media queries must be placed at least under the default properties that you are about to change on screen resizing, that is why is suggested to add them at the bottom of your css file.
HERE is another fiddle with media applied (just try to resize the box to see the effect)
I wonder if this is what you were looking for: jsfiddle
I changed your wrapper to this:
#wrapper {
position: fixed;
top: 50%;
left: 50%;
margin-top: -150px;
margin-left: -200px;
width:400px;
height:300px;
outline:1px solid red;
}
So that your div now sits in the middle of the screen
I want to create a layout where I want to display an image to the left and content on the right. The image should stay constant when the content scrolls.
The css I'm using:
<style type="text/css">
#page-container
{
margin:auto;
width:900px;
background-color:Black;
}
#header
{
height:150px;
width:650px;
}
#main-image
{
float:left;
width:250px;
height:500px;
background-image:url('../images/main-image.png');
position:fixed;
}
#content
{
margin-left:250px;
padding:10px;
height:250px;
width:630px;
background-color:Teal;
}
</style>
The HTML:
<div id="page-container">
<div id="header"><img src="someimagelink" alt="" /></div>
<div id="main-image"></div>
<div id="content"></div>
</div>
Alot of time on this site and I have understood that background-attachment:fixed positions the image in the entire viewport and not the element it is applied to.
My question is how do I go about creating that kind of layout?
I do not want to give that image as a background image, as if the window is resized, it might get hidden. I want scrollbars to appear if the window size is less than 900px( my page width) so that the image can be viewed at all times.
That happens with this code, however I would like the image to start at my element instead.
How do I go about doing this??
Thanks in Advance :)
Edited:
I took the advice and added a position:fixed property to #main-image. Using the HTML and CSS as shown above.
Now, I also want to fix the header so that it does not move. Basically, only my content section should scroll.
However, if I add a position:fixed to the header, my #main-image and #content now sit on top of my header.
If I add a margin-top:150px (since my header height is 150px) to the #main-image, it works fine and moves down appropriately.
However if I add a margin-top:150px to the #content, my header moves down by 150px and still sits on top of my #content.
Can someone please explain why this is happening?
Thanks in Advance :)
Take a look at this link:
http://www.barelyfitz.com/screencast/html-training/css/positioning/
You can learn how to position Div's with it.
This will solve your problem:
#main-image {position:fixed;}
EDIT:
I'm not sure of what caused your problem but here is the solution:
#content{
position:relative;
top:150px;
}
My Guess:
I think that happened because when using position:fixed those 2 div's were positioned relative to the the browser window, while the other one was relative to the document itself.
In this link you will see more about positioning and you can test some of these features related to the position property:
http://www.w3schools.com/cssref/pr_class_position.asp
About the fact that one div was positioned over another, you should search for the 'z-index' property. Firefox has a 3D mode so you can see this more clearly:
http://www.addictivetips.com/internet-tips/browse-internet-in-3d-using-mozilla-firefox-11-tip/
Set a min-width on html and body.
Have you tried setting your #page-container to relative and your #main-image container to absolute and setting the position using top, bottom, etc. Then you should also be able to float your #content container to the right.