I have tried searching around and what I found was either for a set of divs side by side of equal size, or too complicated to adapt to my scenario.
I have a container div with a main div and images div. The main div contains a large blue box with text, while the images div contains two stacked images of different sizes. I want the distance between the main div, the images divs and the right hand side of the page to remain constant while making sure the main div resizes to not go over the sidebar.
All the code is on this codepen: https://codepen.io/1s2s2p/pen/rdJawE
Shortened down code:
HTML:
<div id="container">
<div id="image4">
<img style="width: 80%; height: 80%;" src="https://achievement-images.teamtreehouse.com/badges_intro_to_html_css_stage-01.png">
</div>
<div id="image5">
<img style="width: 80%; height: 80%;" src="http://wwwcdn.howdesign.com/wp-content/uploads/HTML5-CSS31.jpg">
</div>
<div class="main">
<!--Lot of text here-->
</div>
</div>
CSS:
.main {
padding: 21px 6px 6px;
font-weight: bold;
background-color: #66cccc;
float: right;
clear: both;
display: block;
visibility: visible;
z-index: 0;
width: 58%;
position: relative;
top: 167px;
left: -214px;
}
.images {
margin-right: auto;
margin-left: auto;
right: 8px;
padding-top: 156px;
position: absolute;
}
I have an images2 div which is used in the same way but with different images.
Related
I have a fixed size, scrollable parent div containing two children: The first contains the content, and should determine the size of the scrollable area. The second is small overlay that is moved around dynamically, and should not affect the size of the scrollable area. That is, if the overlay overhangs the bottom edge of the content, and the user scrolls all the way down (assuming the content is larger than the parent div), scrolling should stop once they hit the bottom of the content, even if that means only part of the overlay is visible.
Is this possible to achieve?
E.g., with this HTML:
<div id="parent">
<div id="content">
<img src="640x423_image.jpg">
</div>
<div id="overlay"></div>
</div>
and this CSS:
#parent {
position: relative;
height: 400px;
width: 400px;
overflow: auto;
border: 1px solid red;
}
#overlay {
position: absolute;
height: 20px;
width: 20px;
background-color: lightblue;
top: 413px;
left: 15px;
}
(JSFiddle), the browser lets the user scroll past the bottom of the content until the entire overlay (the blue square) is visible, while I would like it to stop once the bottom of the image is visible, leaving the bottom 50% of the overlay still hidden.
For my use case, I am able to make adjustments to the HTML if necessary.
Put square box and img inside same container (#content in your case), and set overflow: hidden; on it.
#parent {
position: relative;
height: 400px;
width: 400px;
overflow: auto;
border: 1px solid red;
}
#content {
overflow: hidden;
position: relative;
}
#overlay {
position: absolute;
height: 20px;
width: 20px;
background-color: lightblue;
top: 413px;
left: 15px;
}
<div id="parent">
<div id="content">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAFBQUFBVUFpkZFp9h3iHfbmqm5uquf/I18jXyP////////////////////////////////////////////////8BUFBQUFVQWmRkWn2HeId9uaqbm6q5/8jXyNfI///////////////////////////////////////////////////CABEIAacCgAMBIgACEQEDEQH/xAAYAAADAQEAAAAAAAAAAAAAAAAAAQIDBP/aAAgBAQAAAADnG4vowbzG0y3fNV4o16crpU2QkqdZuiWm+eL6JBMZDuJSw0DSiOd2QLTUmZllzchaxH0isptmOmGxSigQN80b6IBA41JM4z2ktXjkO04vSs1FICiL1wg03mqljdYXn0BDqUBc809NyyUMTJRk7RU6c8UrlBoOFQ5LUUZj6kiqAFA9QiqSBVHOutDQIjRCh4bKNAfOm6kqW3Fzcgo6DBGnVlcU3SM0rsSZSQzPF9kAIJLZOeRaWooyWsJ0yGTRtlRC1jMN2a522qrm0y6B5sYItYZ67xQIuHSMpw2I0pnPBrMMdJDTpOsNXgF6jb0G87wudWoZVZhb5J6xUMVZXUqIz3WHSkcobZXAOWFVGjmN8cx9VYWXaQ4J1pKWUkNvjrrhsps59KlHLsTn0xMYl3FPPSHFgJ1n0rlDTdQ9FQ6zx0Ww87TqUqefPr0Z0FO559GSc3ZnnlsljJrNCm7zSGqRXThgPXowudoubrLGq3UjToi2ckb6puabWNjnF65zO6z5x6xoKnlNDeW0xtvwo001lDm1dYwb2ZaSmxbOOJ9cUVJVRnak5d3MFmWZdjBqG87jQhamAb7Z6Z6rOzTKZvcWVIoVWZc3RZaAsyTM4jUeOtnLBprDHJDCo6IyvbkRfU8qNIh3eMTvSloBl0ck9k2CHRjSFhpZXJva409N8khCc3BrC3yyDfpxqNE5VxWL6Es2MB2Z43vNskqjDZZzz9RU4b1HG3rpiO1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ldCLRePkfIssssm8zlrEeuG0iJLsXY8IfbzHvF5f2L6m83lfUnwbyuV4vLYu8T5SehdDIj5Lv6n914v8AoPCy/uYu8Psjmyx5WXwXB/Q+C/418bw3i8L71wf2L7b5X9bf02XjReKKHhfQua/u1/XWHworNDwuvseVl/auNfWs3xvhvi+F8tl5eFyrhZY/tfJZv/hXi+Flll/1N/1LL+topi4ULNYpizrNFFcHmuFfTXFL94f9DT5bwvrrF539eyhrFcXrFor6nimUkXl/Q/o6eUWP7/R6KwiilijYi2PjZrKebwyy89vnZbKbxf2V/QWVzXLvLd5f/priudovlX0W/wCokltiwuV/V0a5rHRa4UihcL4b+my839lcq+yvrby8oVm7ymXfrlZfFGsaLNF4s0NYfF/2lzrksddZvFmsJ2MT5XwVfS8t8KX7/r64P7axeLviimW8Xy0f+PO7GWbLKy8rlf8Abv6VwsvhZYxF6O+V49YYiuK4b+l81/wKZvhZXG+LWGexl42PNZZviy8X/wAOjrFNf1ErKxWNI7zQjRZY+i8XzvNPNcv/xAAUEQEAAAAAAAAAAAAAAAAAAACg/9oACAECAQE/AAcf/8QAFBEBAAAAAAAAAAAAAAAAAAAAoP/aAAgBAwEBPwAHH//Z">
<div id="overlay"></div>
</div>
</div>
I have pure CSS image slider which I want to have positioned (margin:auto) with text underneath. Slider images are absolutely positioned as they are stacked. I can't figure out how to position divs around it all. I have content and wrapper divs with relative position. Image size should be responsive (therefore max-width:100%) but wrapper or content divs can be exact size. Or maybe they don't need to either?
This is what I am after:
And this is what I managed so far: www.jsfiddle.net/1qxxnxbf/1/
If your image slider is a carousel, you can't make it responsive without js. If you give your slider a height in the css, you can adjust it in the js to make it responsive.
The only other thing you can do is maintain an aspect ratio. So in your example you have 350x220 images. so If you get your padding-bottom on your .slider class to 62.857% (roughly 220/350) you get a variable height based on the width. If your width grows/shrinks, the height will grow/shrink as well.
http://jsfiddle.net/1qxxnxbf/2/
Edit: I just noticed that none of your code around the slider is responsive. Why are you trying to make the slider responsive?
Checkout this design
https://jsfiddle.net/jalayoza/zvy87dcv/9/
HTML code
<div class="content">content
<div class="wrapper">wrapper
<div class="slider">
<img src="https://placeimg.com/350/220/any" class="slide" alt="slide1">
<img src="https://placeimg.com/350/220/nature" class="slide" alt="slide2">
<img src="https://placeimg.com/350/220/abstract" class="slide" alt="slide3">
</div>
<!-- text should go underneath the image -->
<div class="text">
<div class="text_left">
left text
</div>
<div class="text_right">
right text
</div>
</div>
</div>
</div>
CSS code
.content {
width: 500px;
background: #fff;
margin: auto;
}
.wrapper {
max-width: 400px;
position: relative;
background: purple;
margin: auto;
padding:10px;
}
.slider {
margin: auto;
left: 0;
right: 0;
max-width: 100%;
position: relative;
padding-bottom: 62.857%;
}
.slide {
max-width: 400px;
margin: auto;
position: absolute;
opacity: 0.5;
width: 100%;
}
.text {
max-width: 100%;
position: absolute;
background: transperant;
opacity: 0.9;
bottom:10px;
width: 95%;
}
.text_left {
max-width: 50%;
background: #fff;
float: left;
text-align: left;
padding:5px;
}
.text_right {
max-width: 50%;
background: #fff;
float: right;
text-align: right;
padding:5px;
}
Hope you will like this design
(Please note current answers provided are unclear)
I've got a web-site header that is in two parts: left and right, with the left 130px high, and the right side 185px high. I laid these out using float.
I've got content underneath the left header side in a div that I want to move up so it is immediately below the left header. When I give this div a border and specify a negative margin, the border moves up as expected. However, the content inside the div is not moving up. It hangs down below the 185px (apparently from the right header). Note I have the padding set to zero on this div. What am I doing wrong?
It doesn't work in recent versions of Chrome or Firefox. Thanks.
Relevant HTML code is:
<body style="margin: 0px">
<div class="page">
<div>
<div class="leftHeader">
<div class="headerMissingEnd">
<!-- img src="images/header.png" Title" width="750px" / -->
</div>
</div>
<div class="rightHeader">
<div style="height:185px;padding:0px">
<canvas margin:"0" width="360px" height="185px" loop="true" fps="30" bgcolor="#ffffff" init="fn_canvas">
</canvas>
</div>
</div>
<br class="clear" />
</div>
<div style="margin-top:-60px; padding:0;border: 1px dashed red">
some text that appears too low, not a top of div as expected
</div>
CSS Code:
.clear {
clear: both;
line-height: 0px;
}
.page {
width: 1005px;
margin: 0px auto;
color: #333;
background-color: #fff;
}
.leftHeader {
float: left;
width: 630px;
margin: 0px auto;
}
.rightHeader {
float: left;
width: 360px;
height: 185px;
margin: 0px auto;
}
.headerMissingEnd {
margin: 0px;
width: 640px;
height: 130px;
background: url('images/header-left.png') no-repeat;
}
Don't use negative margin to change element's relative position. Use position: relative; top: -60px; instead:
<div style="position: relative; top: -60px; padding:0;border: 1px dashed red;">
some text that appears too low, not a top of div as expected some text that appears too low, not a top of div as expected some text that appears too low, not a top of div as expected
</div>
(http://jsfiddle.net/BMpqP/10/) Then you can fix wrapping issues with the width: 600px;.
Old answer text:
So, that's because your last div is 100% in width and is not floated. (The default behavior for div.)
When the div is not floated, the text in it interacts with the floating divs even outside it. If you add more text, you'll see (http://jsfiddle.net/BMpqP/6/) that it's for the text not to clash with the other header that is higher.
My proposed solution is to float the div and set the size to it:
<div style="margin-top:-60px; padding:0;border: 1px dashed red; float: left; width: 630px;">
some text that appears too low, not a top of div as expected
</div>
Then the text will be okay, and the main content of the page would also be fine: http://jsfiddle.net/BMpqP/7/
And if you want real smooth stacking without any hardcoded offsets, what you should really do is use float: right; for the headers. (The header parts will have to be switched places in the markup.)
<div class="leftHeader">
<div class="headerMissingEnd">
<!-- img src="images/header.png" Title" width="750px" / -->
</div>
</div>
<div style="padding:0;border: 1px dashed red;">
some text that appears too low, not a top of div as expected some text that appears too low, not a top of div as expected some text that appears too low, not a top of div as expected
</div>
</div>
And the css:
.clear {
clear: both;
line-height: 0px;
}
.page {
width: 1005px;
margin: 0px auto;
color: #333;
background-color: #fff;
}
.leftHeader {
float: right;
width: 630px;
margin: 0px auto;
background-color: black;
opacity: 0.5;
}
.rightHeader {
float: right;
width: 375px;
height: 185px;
margin: 0px auto;
opacity: 0.5;
background-color: navy;
}
.headerMissingEnd {
margin: 0px;
width: 640px;
height: 130px;
background: url('images/header-left.png') no-repeat;
}
I have text next to a image (red square for now).
When i make the window really small then the text goes under the image, i don't want this ever to happen.
so good:
bad:
How can this be prevended?
<div class="entrie">
<img class="entrieImage" src="images/img01.png"/>
<div class="entrieInfo">
<div class="band">Green</div>
<div class="album">...</div>
<div class="label">ATCO</div>
<div class="year">1966</div>
-
<div class="tags">rousseau, green, woodsy, band photo, 12IN, tree, civilization, Atco, 1960's, Fuzz
</div>
</div>
</div>
-
.entrie {
float: left;
margin-bottom: 40px;
position: relative;
}
.entrieInfo {
width: 200px;
float: left;
margin-left: 10px;
margin-right: -45px;
position: relative;
z-index: 2;
}
.entrieImage {
/* if you only set the width then the height will be set automaticly proportional*/
width: 300px;
height: 300px;
float: left;
position: relative;
z-index: 1;
background: red;
}
here a js fiddle for easy testing:
http://jsfiddle.net/K4RFU/
You could set a min-width on .entrie which is sufficiently large to encompass its content.
I want to align two sidebars and one centered image in height.
Additionally the sidebars (which contain text) should be vertical aligned in the height from the outer container.
I made a fiddle which describes the problem:
http://jsfiddle.net/SW3DT/
When having this example on a fullscreen you see everything correct but when you look into the fiddle html preview (or any smaller view) it doesn't work anymore.
So there are following problems:
Align aside and center-containers horizontal (position: absolute, left, right)
Align the child object from the asides (in this case the p's) vertically (breaks the absolute)
Do this all dynamically so that it can be used on different screen sizes
How you can see all three points together make it hard to code this with css.
Does anyone have a solution?
Furthermore:
How could I define reusable css-classes for such tasks?
Best Regards,
bsus
If I did understand you question correctly, you kinda want a centered wrapper with three columns, having the left and right column occupying 200px of width. If this is the case:
See this Fiddle Example
HTML:
<div class="content">
<aside class="column right">
<p>
text...
</p>
</aside>
<aside class="column left">
<p>
text...
</p>
</aside>
<div class="column center">
<img class="home_image" src="path_to_image.png" />
</div>
</div>
CSS:
/* the main wrapper */
.content {
position: absolute; top: 50%; left: 50%;
width: 800px; height: 500px;
margin-left: -401px; margin-top: -251px;
border: 1px solid #D9D9D9;
}
/* columns */
.column {
position: absolute; top: 0; bottom: 0;
width: 180px;
padding: 10px;
}
.column.left{
left: 0; background-color: #F2F2F2;
}
.column.right {
right: 0; background-color: #F2F2F2;
}
.column.center {
left: 200px; right: 200px;
text-align: center;
width: auto;
}
.column.center img {
border: 1px solid #111; border-radius: 22px;
width: 128px; height: 128px;
margin: 0 auto;
}
Furthermore: How could I define reusable css-classes for such tasks?
You can see the .column class that is applied to the .left, .right and .center elements, thus being reused on all three.