When hovering a div, I want to display a full-page div with a background image and text on top. The hovered div should then stay on top of everything. This works so far, with the only exception that I can’t figure out how to make the overflow text scrollable.
Any ideas how to make this work?
JSFiddle
html:
<div class="container">
<div class="title">Show content</div>
<div class="content">
<div class="background"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg/800px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg"></div>
<div class="infocontainer">
<div class="info">
Lorem Ipsum...
</div>
</div>
</div>
</div>
css:
.container {
position: fixed;
left: 50%;
top: 10%;
}
.content {
display: none;
}
.title:hover + .content {
display: block;
width: 100%;
height: 100%;
}
.title:hover {
position: relative;
z-index: 3;
}
.background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.infocontainer {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
z-index: 2;
overflow: scroll;
}
.info {
height: 100%;
padding-right: 70%;
}
UPDATE: When I put .info on top with z-index, it becomes scrollable but I get a flickering effect because .title:hover gets over overridden. See: jsfiddle.net/dm41eo5z
You can't hover to make something appear over the whole page, because as soon as it is over the whole page you are no longer hovering the original thing (that's why your example above flickers) and it will disappear. If you use a JavaScript Event listener (such as onMouseOver) you could make it appear by adding a class with a "display: absolute" or "block" or whatever you want it to do. Then it would stay open until you use some other event listener (such as "Click" on an X) to close the element.
The .content div disappears as soon as you stop hovering the .title. To prevent that, continue showing .content while you hover it:
.title:hover + .content, .content:hover {
display: block;
width: 100%;
height: 100%;
}
Note: to hide .content, the user will have to move the cursor out of the screen.
Demo:
.container {
position: fixed;
left: 50%;
top: 10%;
}
.content {
display: none;
}
.title:hover + .content, .content:hover {
display: block;
width: 100%;
height: 100%;
}
.title:hover {
position: relative;
z-index: 3;
}
.background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.infocontainer {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
z-index: 2;
overflow: scroll;
}
.info {
height: 100%;
padding-right: 70%;
}
<div class="container">
<div class="title">Show content</div>
<div class="content">
<div class="background"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg/800px-Mount_Everest_as_seen_from_Drukair2_PLW_edit.jpg"></div>
<div class="infocontainer">
<div class="info">
Pellentesque venenatis tempor ultrices. Nunc maximus erat vel tellus vestibulum, id auctor justo tristique. Ut volutpat eu tellus ut vulputate. Cras id finibus massa. Quisque neque lacus, pretium sed luctus in, semper ut quam. Donec elementum volutpat elementum. Morbi nibh nunc, scelerisque congue turpis nec, lacinia venenatis tortor.
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi quis magna urna. Etiam tincidunt velit lacus, ac blandit ex pretium nec. Nulla semper erat ut tortor luctus, sit amet suscipit felis ullamcorper. Etiam laoreet, mauris ut volutpat pellentesque, velit neque euismod sem, in condimentum mauris orci nec nibh. Vivamus ac sem et turpis pellentesque volutpat ac ac ligula. Phasellus feugiat dapibus maximus. Donec eros felis, suscipit eu neque quis, sagittis faucibus ipsum. Nam auctor molestie quam nec tristique. Aliquam dolor velit, condimentum in vehicula ut, pretium sed leo. Proin sit amet quam nunc.
Integer eu orci quam. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sed felis vitae justo faucibus blandit at a dolor. Curabitur id nisi nec elit aliquam convallis nec eu est. Aenean viverra id diam ac accumsan. Praesent tempor, magna eget molestie sodales, neque libero pretium magna, id euismod justo erat at est. Phasellus ultrices metus et massa varius, at rutrum augue pretium. Mauris ultrices felis et magna luctus sodales. Curabitur sodales pellentesque ante auctor molestie. Donec sed massa scelerisque elit auctor lacinia ac vel risus. In eleifend vulputate sapien a tristique. Nam eleifend rutrum metus.
</div>
</div>
</div>
</div>
Thank you for your replies so far but they don't exactly achieve what I'm looking for. Is there maybe a way to keep .title on top but specifically target .info for scrolling?
Related
I created an element with an image to the left and text to the right.
On screen resize I want to maintain the image ratio while having it extend vertically in the element. Instead the image reduces in size like so:
How can I always keep the image extended in height but maintain its aspect ratio?
I am using flex in my code
Codepen: https://codepen.io/anon/pen/pYmjMK
.container {
width: 100%;
max-width: 860px;
}
.item {
display: flex;
background-color: #ddd;
}
.image {
width: 30%;
position: relative;
}
.image:before {
content: "";
display: block;
padding-bottom: 65%;
}
img {
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
object-fit: cover;
}
.text {
width: 70%;
padding: 15px;
}
.image a {
display: block;
width: 100%;
}
On screen resize I want to maintain the image ratio while having it extend vertically in the element. Instead the image reduces in size like so:
Most images can't fit in the container top-bottom and left-right while maintaining aspect ratio across all screen sizes. One thing you could do on smaller screen sizes is to have the image take 100% of the screen's width and overlay the text or position it below. Even then, on smaller screen sizes, the image won't take 100% of the height and maintain aspect ratio. Also if you have too much text, it will bleed off the image.
Here's an example with text overlaid. :
.container {
width: 100%;
max-width: 860px;
}
.item {
display: flex;
background-color: #ddd;
}
.image {
width: 30%;
position: relative;
}
.image img {
height: 100%;
}
.image:before {
content: "";
display: block;
padding-bottom: 65%;
}
img {
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
object-fit: cover;
}
.text {
width: 70%;
padding: 15px;
}
.image a {
display: block;
width: 100%;
}
#media (max-width: 1024px) {
.image {
width: 100vw;
}
.text {
position: absolute;
color: white;
font-weight: bold;
background-image: linear-gradient(rgb(192,192,192), rgb(0,0,0)); /*Fallback*/
background-image: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.6));
}
}
<div class="container">
<div class="item">
<div class="image">
<a href="#">
<img src="https://images.unsplash.com/photo-1441986380878-c4248f5b8b5b?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80" />
</a>
</div>
<div class="text">
<h3>Lorem Ipsum Dolor</h3>
Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio. Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio.Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio.Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio.
</div>
</div>
</div>
If you want to maintain aspect ratio and basically zoom in on a portion of the image:
.image img {
height: 100%
}
.container {
width: 100%;
max-width: 860px;
}
.item {
display: flex;
background-color: #ddd;
}
.image {
width: 30%;
position: relative;
}
.image img {
height: 100%;
}
.image:before {
content: "";
display: block;
padding-bottom: 65%;
}
img {
width: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
object-fit: cover;
}
.text {
width: 70%;
padding: 15px;
}
.image a {
display: block;
width: 100%;
}
<div class="container">
<div class="item">
<div class="image">
<a href="#">
<img src="https://images.unsplash.com/photo-1441986380878-c4248f5b8b5b?ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80" />
</a>
</div>
<div class="text">
<h3>Lorem Ipsum Dolor</h3>
Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio. Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio.Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio.Sed hendrerit. Praesent ut ligula non mi varius sagittis. Suspendisse non nisl sit amet velit hendrerit rutrum. Ut a nisl id ante tempus hendrerit. Integer tincidunt. Nullam vel sem. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Phasellus blandit leo ut odio.
</div>
</div>
</div>
Add this css to your img tag:
width: auto;
height: 100%;
And put this on your div.image:
overflow: hidden;
Then you might want to play around with the positioning so that the image is centered instead of left / top aligned.
CSS fit image to element height and maintain ratio on resize, you css height img:
.image img {height: 100%;}
https://codepen.io/anon/pen/xBNPzm
I'm wondering if there is a way to fix an element inside a visible area of the div as I've described in the image below.
Here is an example of my problem (jsfiddle):
HTML:
<div id="header" ></div>
<div id="menu">
<a id="menu-collapse">collapse</a>
<div id="some-block"></div>
</div>
<div id="content"></div>
CSS:
#menu {
position: fixed;
top: 70px;
bottom: 0px;
left: 0;
width: 200px;
background-color: rgb(100, 134, 27);
overflow-x: auto;
}
#header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: rgb(27, 48, 0);
min-width: 540px;
}
#menu-collapse{
}
#content {
position: fixed;
top: 70px;
right: 0px;
bottom: 0px;
left: 200px;
background-color: rgb(27, 118, 0);
}
#some-block{
position:absolute;
display:inline;
background-color: yellow;
width: 200px;
height: 2500px;
}
I need to have #menu-collapse in the middle of the visible area of #menu, while scrolling #menu.
Use position: fixed; in your CSS class definition. This will position the div relative to the browser window instead of the document itself, allowing it to maintain its position as you scroll.
There is now way to fix the element inside a div area if you use position:fixed; property then it will automatically fix it relatively to the browser.
Its a default feature.
On #menu-collapse, you need to add position: fixed; to get it to stay in the same position. And, you need top: 50%; in order to have it in the middle of #menu, and z-index: 1; in order for it to display on top of #some-block.
JSFiddle
HTML:
<div id="header" ></div>
<div id="menu">
<a id="menu-collapse">collapse</a>
<div id="some-block">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vitae tortor fermentum, pellentesque lorem vitae, ullamcorper urna. Sed in imperdiet nisl, porta porta sem. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum euismod sapien a imperdiet placerat. Ut a maximus felis. Mauris porta purus id mi feugiat ultrices. Etiam mattis leo id hendrerit sagittis. Vivamus dapibus blandit ligula varius semper.</p>
<p>Ut nisl neque, efficitur non risus vitae, luctus cursus dui. Pellentesque aliquam varius cursus. Fusce lobortis, sapien at dictum porta, erat eros rhoncus metus, sit amet finibus libero quam nec nisl. Phasellus tempus ante vitae rutrum ultricies. Fusce sit amet hendrerit quam, egestas gravida risus. Donec eget tristique enim, ac lacinia nunc. Nam pulvinar, nunc et scelerisque ornare, est augue mollis sem, vel vulputate arcu mi et eros. Proin varius arcu vitae nisi porttitor, sit amet finibus eros congue. In dapibus tincidunt tortor. Sed at sem id tortor molestie finibus eget ut sem. In semper feugiat elementum. Morbi enim mauris, venenatis non felis ac, interdum euismod sapien. Praesent semper ante vel mauris auctor, ut commodo ipsum malesuada. Morbi hendrerit tortor sapien. Nulla in hendrerit dui, eu accumsan est</p>
</div>
</div>
<div id="content">
</div>
CSS:
#menu {
position: fixed;
top: 70px;
bottom: 0px;
left: 0;
width: 200px;
background-color: rgb(100, 134, 27);
overflow-x: auto;
}
#header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 70px;
background-color: rgb(27, 48, 0);
min-width: 540px;
}
#menu-collapse{
position: fixed;
top: 50%;
z-index: 1;
background: red;
}
#content {
position: fixed;
top: 70px;
right: 0px;
bottom: 0px;
left: 200px;
background-color: rgb(27, 118, 0);
}
#some-block{
position:absolute;
display:inline;
background-color: yellow;
width: 200px;
height: 2500px;
}
I am trying to get my main content and menu divs to stretch to the top of the footer div. My HTML is:
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
min-height: 100%;
position: relative;
}
#header {
padding: 10px;
background: #3095C7;
}
#main {
padding-bottom: 80px;
bull
}
#content {
padding-left: 310px;
background: #FFEFC4;
}
#menu {
background: #67b5d1;
width: 300px;
position: absolute;
float: left;
}
#footer {
text-align: center;
padding: 30px 0;
width: 100%;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
background: #3095C7;
}
<div id="wrapper">
<div id="header"></div>
<div id="main">
<div id="menu">
menu here
</div>
<div id="content">
content here
</div>
</div>
<div id="footer">footer content</div>
</div>
I have set the main, content, and menu height to 100%, but that of course just is to the very bottom of the wrapper div, which is beyond footer. What I am trying for is for menu and content to stretch from the header all the way down to the top of footer, so it fills the whole page. I have played around with vh but isn't spot on constantly when re-sizing the window.
Are there any tricks that will make the divs fill all the blank space and not overlap the footer?
Very simple with flexbox (browser support is IE10+ and everything else that's remotely modern)
Set up #wrapper to be display: flex; flex-flow: column nowrap
Set up #main to be flex: 1 1 auto and display: flex so 1) that it grows to the necessary height and 2) so that it's children will also grow to the height of #main.
Set flex: 0 1 300px on #menu (and remove floats/position: absolute) and set #content to be flex: 1 1 auto.
EDIT
Forgot to remove position: absolute (and associated bottom/left rules) from the footer. I also added a ton of content (and modified the left menu to not shrink flex: 0 0 300px instead of flex: 0 1 300px so that a bunch of content doesn't collapse it into nothing-ness
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
min-height: 100%;
display:flex;
flex-flow: column nowrap
}
#header {
padding: 10px;
background: #3095C7;
}
#main {
display: flex;
flex: 1 1 auto;
}
#content {
flex: 1 1 auto;
background: #FFEFC4;
}
#menu {
background: #67b5d1;
flex: 0 0 300px;
}
#footer {
text-align: center;
padding: 30px 0;
width: 100%;
height: 50px;
background: #3095C7;
}
<div id="wrapper">
<div id="header"></div>
<div id="main">
<div id="menu">
menu here
</div>
<div id="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu tristique ex, at rhoncus sem. Interdum et malesuada fames ac ante ipsum primis in faucibus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec non ipsum ut nulla volutpat gravida. Donec euismod nibh venenatis fermentum dignissim. Nulla sagittis tristique felis vitae fermentum. Phasellus at viverra sem. In scelerisque mi ac dolor convallis, vitae convallis felis condimentum. Donec porta leo nec semper luctus. In dignissim bibendum viverra. Maecenas molestie, dui eget finibus hendrerit, arcu turpis dapibus arcu, laoreet aliquam lectus justo a lorem. In et enim ac elit tincidunt imperdiet. Phasellus eget erat sed nulla placerat venenatis et in ligula. Mauris volutpat feugiat diam sit amet bibendum. Donec vulputate tristique augue vel pharetra. Mauris orci quam, pharetra lacinia commodo eu, tristique at est.
Morbi metus sapien, venenatis a pulvinar eget, accumsan et nisi. Phasellus vitae blandit augue. Proin quis mollis orci. Ut consequat tempor nulla id dignissim. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce in euismod nibh, pharetra laoreet eros. Donec feugiat neque est, ac pharetra quam sollicitudin a.
Donec hendrerit ac magna at tincidunt. Pellentesque eget eros vel mauris porttitor aliquam ac vel tortor. Vestibulum vitae porttitor enim, eu scelerisque quam. Suspendisse tincidunt nisi non eros condimentum, quis faucibus arcu pellentesque. Morbi aliquet, est at pretium molestie, est arcu volutpat lectus, et condimentum leo risus sed velit. Maecenas at fermentum magna. Duis sit amet pretium ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum diam est, facilisis eu tellus vel, sagittis pretium metus. Aenean fermentum sem eu finibus dignissim. Fusce lacinia purus at libero ornare ultricies. Etiam pellentesque erat nisi, a ullamcorper arcu varius eu. Quisque lacinia bibendum ipsum vitae bibendum.
Maecenas non consequat augue, id euismod magna. Vestibulum ut maximus eros, ut efficitur neque. Aenean feugiat nunc et viverra pulvinar. Praesent vitae lobortis mi. Duis eu lorem a velit consequat fringilla at eu lacus. Ut mi mauris, cursus et lectus non, auctor iaculis eros. Sed sit amet efficitur arcu. Maecenas in enim quis massa vestibulum imperdiet ac quis dui. Curabitur malesuada, neque eu scelerisque sagittis, erat nisl condimentum sapien, vitae volutpat felis nisi ac lectus. Fusce iaculis mollis enim, vitae consectetur metus egestas sed. Proin lacus lorem, finibus ut tincidunt quis, tincidunt a urna. Donec fringilla risus augue, et bibendum diam cursus vitae. Aenean mattis sapien eget volutpat ornare.
</div>
</div>
<div id="footer">footer content</div>
</div>
I think your code is a bit messed.
If I understood correctly your question you have a header and footer with fixed height and you want the content of the web to fill the height of the (vertical) window.
When using height:100% remember all parents need to have same height 100% but then you may have a problem as height 100% plus the fixed height of footer and header will create a scroll bar.
you can use css calc to substract px's to 100% height. I calculate the pixels you need to subtract in your example and the height for your content shoudl be:
height:calc(100% - 110px);
AND the height of your main:
height:calc(100% - 20px);
The rest is your css's with many changes to achieve what I think you were looking for. corrent me if I am wrong: FIDDLE
(you can see I also used calc to set the width to your content since your menu also had fixed width)
Note: carefull with the use of this technique if you NOT using border-boxfor your containers as all the paddings you are using add width (or height) to your elements. I recomend you to get use to add
* {
box-sizing: border-box;
}
in your css sheets. Once you get use to your live will be easier (just my humble opinion, some may disagree)
Assuming your footer has a fixed height, you can automatically set the height of #menu and #content using position: absolute:
position: absolute;
top: 0;
bottom: 110px; /* #footer height */
Most of the time, absolutely positioned elements have auto values of height and width computed to fit the contents of the element. However, non-replaced absolutely positioned elements can be made to fill the available space by specifying (as other than auto) both top and bottom and leaving height unspecified (that is, auto). Likewise for left, right, and width.
See: https://developer.mozilla.org/en-US/docs/Web/CSS/position#Notes
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#wrapper {
min-height: 100%;
position: relative;
}
#header {
padding: 10px;
background: #3095C7;
}
#main {
position: absolute;
top: 20px;
bottom: 0;
width: 100%;
}
#content {
position: absolute;
left: 310px;
right: 0;
top: 0;
bottom: 50px;
background: #FFEFC4;
}
#menu {
background: #67b5d1;
top: 0;
bottom: 50px;
width: 300px;
position: absolute;
}
#footer {
text-align: center;
padding: 30px 0;
width: 100%;
height: 50px;
position: absolute;
bottom: 0;
left: 0;
background: #3095C7;
}
<div id="wrapper">
<div id="header"></div>
<div id="main">
<div id="menu">
menu here
</div>
<div id="content">
content here
</div>
</div>
<div id="footer">footer content</div>
</div>
Add a specified height into your CSS, e.g. height: 100px and then set overflow to hidden.
So basically, just add:
height: 100px;
overflow: hidden;
to your menu and content.
I'd like to achieve something similar to the picture below (2 icons, mail and phone outside my Article DIV (in white on the image), aligned to the top of the DIV and under each other (with 1 or 2 pixels space). I tried to set a class with a negative margin for the images but without success. What would be the best way to achieve this?
Many thanks
.article {
clear: right;
float: right;
text-align:justify;
width: 450px;
min-height:420px;
height: 60%;
padding: 50px 32px 49px 62px;
margin-right:75px;
position: relative;
z-index: 15;
margin-top: 90px;
background: #fff;
/* max-width: 25%; */
overflow-y: scroll!important;
}
I would use position: relative on the article and position: absolute positioning on the icon set (I used a ul for simplicity):
JSFiddle: http://jsfiddle.net/szLsH/
HTML code:
<article>
<div id="icons">
<ul>
<li></li>
<li></li>
</ul>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ac libero velit. Proin euismod erat non diam malesuada ac semper purus dapibus. Donec id suscipit metus. Ut eu auctor mauris. Proin sed felis dui. Maecenas congue dapibus dolor, sodales feugiat nisi feugiat ac. Nulla nec massa in mi pharetra sollicitudin. Aliquam eu dui quis odio porttitor viverra ut cursus dui. Nullam quis tristique magna. Aliquam erat volutpat. Suspendisse potenti. Pellentesque rhoncus commodo odio vitae tincidunt. Praesent rutrum, nibh vitae porta luctus, felis quam dignissim risus, non tempus lectus magna non odio. Donec commodo laoreet dolor ut volutpat. Ut lobortis lobortis augue, in placerat arcu dapibus et. Maecenas vitae lectus quis enim suscipit euismod.
</p>
</article>
CSS:
article {
width: 200px;
margin: 0 auto;
position: relative;
padding: 10px;
border: 1px solid #AAA;
}
#icons {
position: absolute;
right: 100%;
top: 0;
}
#icons ul {
margin: 0;
padding: 0;
list-style-type: none;
}
#icons li {
width: 50px;
height: 50px;
background: blue;
margin: 0 5px 5px;
}
I have created a page with a static image positioned to the ride side of the browser at full height (with a gradient over it) and a block of text to the left. I want the image to resize with the browser window, however I do not want the image to go behind the text or to get smaller than the text. When I set a min-width and min-height on the body, for example 1024x768, this doesn't solve the problem. Am I doing something wrong? How should I go about doing this?
Thanks in advance!
Here's my code:
<style type="text/css">
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
min-width: 1024px;
min-height: 768px;
}
#background-image {
position: absolute;
right: 0;
top: 0;
height: 100%;
background-image: url('image.jpg');
z-index: -1;
}
#background-gradient {
position: absolute;
right: 0;
top: 0;
z-index: 0;
height: 100%;
}
#content {
position: absolute;
left: 15%;
top: 15%;
width: 500px;
font-family: Georgia;
font-size: 16px;
}
p.dropcap:first-letter {
float: left;
font-size: 50px;
line-height: 30px;
padding-top: 2px;
padding-right: 4px;
font-family: Georgia;
}
h1 {
font-size: 55px;
}
</style>
</head>
<body>
<img id="background-image" src="image.jpg" />
<img id="background-gradient" src="gradient.png" />
<div id="content">
<h1>[TITLE]</h1>
<p class="dropcap">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nibh lectus, vehicula quis elementum nec, pellentesque vitae est. In in libero pulvinar felis ultrices varius vel at augue. Suspendisse sollicitudin risus eu mauris ultrices nec auctor neque facilisis. Pellentesque commodo tellus quam. Praesent dictum sodales nisi, id tempor neque hendrerit id. Ut non mi a ante pulvinar tempor. Morbi scelerisque metus eu sem iaculis hendrerit. Integer pulvinar ipsum quis ante tincidunt gravida.</p>
<p>Nullam vel tellus sed mauris sagittis egestas at sed lacus. Pellentesque sit amet justo felis. Donec sit amet est in urna consectetur convallis vitae id justo. Sed adipiscing accumsan augue, at cursus lorem bibendum nec. Etiam diam odio, sagittis ut tempor fermentum, elementum eu erat. Vivamus pharetra, nibh vel elementum pulvinar, risus leo ornare felis, eget tincidunt velit odio non turpis. Proin semper metus eget nisi varius varius elementum nisl eleifend. Nulla facilisi. Suspendisse urna sapien, pulvinar non porttitor pellentesque, laoreet id leo. Praesent sed tortor quis tellus eleifend ultricies et eu eros. Sed massa eros, hendrerit eu facilisis sed, fermentum sit amet purus. Nulla aliquam eleifend ante, tincidunt pulvinar dolor elementum eu. Proin quis justo in arcu sollicitudin faucibus ac tincidunt ligula.</p>
</div>
</body>
Put all your HTML code inside a container div which is directly inside body. You can then move the CSS code from body to #container, like this:
#container {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
min-width: 1024px;
min-height: 768px;
}
IIRC you can't set min-width on body. You'll want to be careful though, because the earlier versions of IE don't support min-width.
Just float:right and float:left
And add a margin to give it the previous look
Demo