Child Div that extends to the Full Height of the Parent Div - html

I am trying to get my child div section to all the way to the top and bottom of the parent div section. Go to the bottom of this Example URL (where the Canadian Flag Stand Up Paddle Boarders are): https://www.lakeshoresup.com/product/pathfinder/
Basically if I set the width larger than 41% I get a small area that doesn't go to the top and bottom of the section.
Code:
<div class="hero__container container">
<div class="hero__content-wrapper" style="background-color: rgba(0,0,0,0.2); flex: 60% ; max-width: 60%;">
<h1 class="hero__title hero__title--big">
Adrift in the Canadian Rockies</h1>
<p class="hero__content hero__content--medium">
Jake and Lyndsay embark on a Lakeshore adventure with their inflatable paddleboards. </p>
<div class="primary-link">
<a href="https://www.lakeshoresup.com/2015/07/28/adrift-in-the-canadian-rockies-with-jake-lyndsay-part-1/" class="hero__primary-link btn" target="_blank">
Read Their Story </a>
</div>
</div>
</div>
CSS
.hero--right .container {
-webkit-box-pack: end;
-ms-flex-pack: end;
justify-content: flex-end;
}
.hero__content-wrapper {
padding-left: 20px;
padding-right: 20px;
display: table-cell;
vertical-align: top;
}
I have tried to add min-height:760px to the css which worked but isn't dynamic. When the site goes to mobile or if the slider boxes are different sizes it breaks the image.
Is there a dynamic way to make the child box (.hero__content-wrapper) always extend to the top of the parent box (.hero__container)?
Is this something that I can use the CSS below and have it function across all browsers or is there a better way to do it?
height: -moz-available;
height: -webkit-fill-available;
height: fill-available;

I think found a solution to your issue.
.hero__content-wrapper {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 100%;
}
Also to remove the max-width as it will take the width of the parent. You could also add position:relative to the .hero__container class. Does that solve your problem?

Matt -
Let's dilute the example for readability, but essentially create the same thing:
<div class="container">
<div class="box"></div>
</div>
CSS:
.container {
position: relative;
height: 100px;
width: 100px;
border: 1px solid red;
}
.box {
background: blue;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
Here, we just use CSS Position to set the element's reference to the container's dimensions. Then we target the edges of the boundaries with the top:0, etc - That gives us a blue box with unspecified dimensions, filling its parent container.

Related

absolutely positioned div is covering my content

[]
1i am making an introduction to my page by creating a profile picture positioned halfway the container, and the design is for mobile view.
the container that holds the pic and the name is positioned relative, while the pic is positioned absolute, the content which is contained below is positioned static by default(i think) and i made it to be 100% width to be able to center it.
Problem: the pic is covering the name below it, i tried to make a padding to position it below but when the pic grows bigger, it covers it again, i also tried media queries but this way i will make a break points every 100 px,: i don't think it is practical this way
.container {
position: relative;
min-height: 350px;
background-color: black;
}
.pic {
position: absolute;
width: 30%;
top: -30%;
left: 30%;
}
.content {
width: 100%;
padding-top: 8rem;
text-align: center;
}
<div class="container">
<div class="pic">img</div>
<div class="content">name</div>
</div>
You don't need any fancy absolute positioning for this:
.container {
position: relative;
min-height: 350px;
background-color: black;
margin-top: 4rem;
color: white;
text-align: center;
}
.pic {
margin-top: -1.8rem;
}
<div class="container">
<img src="//i.stack.imgur.com/fVW6p.png?s=48&g=1" class="pic">
<div class="content">name</div>
</div>
Yeah, well, the absolute positioning takes the image out of page flow and positions it relative to the nearest relatively-positioned ancestor, not bothering too much about other elements - so that is actually expected behavior. Is there any specific reason why you want your picture to be absolutely positioned? From what you have written, I'd say your best bet would be to go with flexbox as it's easiest to control placement.
Though, to be honest, you could probably go here with just removing absolute positioning, so it's again in the normal flow, and then centering your image div:
.container {
position: relative;
min-height: 350px;
background-color: black;
padding: 1rem;
}
.pic {
width: 30%;
margin: 0 auto;
}
.content {
width: 100%;
padding-top: 3rem;
text-align: center;
color: white;
}
<div class="container">
<div class="pic"><img src="https://picsum.photos/200/150" alt=""></div>
<div class="content">name</div>
</div>
Adding absolute positioning to the .content worked for me.

z-index issues - div not overlaying another

So I have an issue and despite spending on research a while now I still cannot figure out what I am doing wrong.
Consider the following:
/* Main row */
.main-row {
width: 100%;
display: inline-flex;
z-index: -1;
position: relative;
}
.spacer {
width: 100%;
background-color: #0a0826;
height: 250px;
background-image: url("../img/purple-wave.png");
background-position: 0px 17%;
z-index: 10;
position: relative;
}
and HTML
<div class="main-row">
<div class="main-row left-pane">
<h1 class="main-row title">Changing The Way</h1>
<p class="main-row subtitle">We understand <a>intelligent</a>telecommunication</p>
</div>
<div class="main-row right-pane">
<img src="<?php echo base_url("assets/vid/ai_brain.gif");?>" />
</div>
</div>
<div class="spacer"></div>
I am expecting to see the spacer (with some fancy graphics) to overlay the main row but this isn't happening. The position is specified, the z index is set correctly, the two divs are independent of each other. Whatever I do the graphic still is displayed below the main-row div
I think you're confusing background-position and element positioning. Background positioning changes the position of your background relative to wherever the element is on the screen. The background is still contained by the element, and otherwise does not affect the element's size or position on the screen.
Everything will overlap if you adjust the actual position of the spacer, like so:
.spacer {
top: -200px; /* This */
width: 100%;
background-color: #0a0826;
height: 250px;
background-image: url("../img/purple-wave.png");
background-position: 0px 17%;
z-index: 10;
position: relative;
}

Adaptive width layout just with css3?

I am having a lot of trouble figuring this one out, essentially I have 3 columns: navbar (dark gray), main content (dark red) and sidebar (dark green) where navbar can be expanded and shrinked and sidebar can slide out and slide in (so change width from 0 to something and back to 0). And I want to keep all of this responsive. Idea is to shrink main content accordingly when some or both navbar and sidebar are expanded. unfortunately only way I can think to do this is to change width of main content to something like width: calc(100% - navbar width - sidebar width) but this is really verbose when I need to check if sidbar is expanded or navbar, or both are not expanded etc...
Here is an image illustrating how main content shrinks:
I assume flexbox could be used here somehow, but was not able to figure it out.
let example marku be
<nav> </nav>
<main> </main>
<aside> </aside>
note: nav and aside need to be 100% height of the page and are fixed in place.
You can use flex-box for this. A simple approach would be as follows: http://codepen.io/anon/pen/pgVVJb
You can change the classes to see how it changes the layout. NOTE: I am using classes to change the width of the columns but you could use JavaScript or static CSS similarly.
Code dump:
<div class="container">
<div class="small">Nav</div>
<div>Content</div>
<div class="medium">Sidebar</div>
</div>
html, body, div {
height: 100%;
margin: 0;
padding: 0;
}
.container {
display: flex;
}
.container div {
flex: 1;
border: 1px solid #ccc;
background: gray;
}
.small {
max-width: 50px;
}
.medium {
max-width: 150px;
}
One popular solution to this is putting all of these elements in a wrapper with position: relative or even putting setting body's to position: relative, and all the elements inside with position: absolute. Then you can set each element as follows:
.navbar {
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
width: 50px;
}
.main-content {
position: absolute;
top: 0px;
left: 50px;
bottom: 0px;
right: 150px;
}
.sidebar {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
width: 150px;
}
Of course the container element need to have some height for this to work.

Centering div to screen

I can't seem to get the black box to the center of the screen as opposed to the center of the div its inside in.
EDIT: For clarification, I only want the black box in the center of the results panel not the pink box with it. Also I would also like to keep my javascript intact.
EDIT 2: I'm trying to have something like an overlay that popsup in the middle of the screen when a user clicks on the image. Not sure if this is the best way or the best code to achieve that!
Would appreciate if anyone can help.
Here's my attempt: http://jsfiddle.net/BPLcv/1/
HTML
<div class="tooltip">
<div class="description">Here is the big fat description box</div>
</div>
<div class="tooltip">
<div class="description">Poop</div>
</div>
CSS
.tooltip {
position: relative;
border: 1px #333 solid;
width: 200px;
height: 200px;
background-image: url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSkI2PXYOOOHltHwgIz6xwfuN079IAJDLsmOV68rQNNLCE-GFZ1_aQN89U');
}
.overlay {
position: absolute;
display: none;
background-color: rgba(0, 0, 0, 0.7);
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.description {
position: absolute;
width: 300px;
height: 300px;
display: none;
background-color: black;
text-align: center;
z-index: 1;
/* centering???? */
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -75px;
}
Thank you!
If you want the description/overlay in the middle of the screen, your best bet is to use an element outside of your tooltip-elements, as these are fixed width.
If you have a top-element with width: 100%, your centering css wil work for any immidiate children.
Working fiddle: http://jsfiddle.net/BPLcv/4/
Here the overlay is filled with whatever is in the description element of the tooltip you're hovering:
overlay.html($(this).find(".description").html());
The description class is always hidden.
Check this Demo jsFiddle
CSS
body{
margin:auto;
width:50%;
}
Try this. Assign the div of interest id = CenterDiv, then add this css:
z-index:10;//remove left:50%
Now try adding this function via onload or onclick, etc:
function centerDiv() {
document.getElementById("CenterDiv").style.marginLeft = ((screen.availWidth - 300)
/ 2) + 'px';
}
The number 300 can be any number that represents the width of your element of interest.
Substituting the width of your element (here, 300px), this function will center an element with absolute position.

Positioning a button with CSS

I have the following standard markup:
<body>
<header><div class="wrapper">Header</div></header>
<div id="create">create something</div>
<div class="wrapper">Content</div>
<footer><div class="wrapper">footer</div></footer>
</body>
and style:
.wrapper {
width: 920px;
margin: 0 auto;
padding: 0 20px;
text-align: left;
}
The thing I am having difficulty with is positioning the "create something" button, I would like it positioned as shown below...
The important points to note are that the button extends to the right into infinity, and it always takes up a width of "4 squares" of the centralised area, no matter what the browser width.
Any advice would be appreciated, thanks.
One element for the button and another element for the line that goes into the infinity and beyond..
The infinity element is partially hidden under #wrap or #header element's background.
http://jsfiddle.net/lollero/62wcV/1
CSS:
#wrap {
width: 400px;
margin: 0px auto;
background: #ffffff;
position: relative;
z-index: 10;
height: 600px;
}
#button,
#button_line {
position: absolute;
top: 40px;
right: 0px;
height: 20px;
background: #3a99ff;
}
#button {
width: 100px;
}
#button_line {
left: 50%;
z-index: 5;
}
HTML:
<div id="button_line"></div>
<div id="wrap">
<div id="button"></div>
</div>
I'm not going to say this is the best way, but it works for me.
<div style = "background:red;position:relative;left:50%;right:0">
<div style = "background:green;position:relative;left:120px;right:0">
Your button here!
</div>
</div>
The first div just gives you a reference to the centre of the page. The second is the 'button' where the left is offset by however much you want.
When creating buttons with CSS, always calculate the width, height, paddings and margin. it helps to give accurate box size to fit any particular container. check out this post. http://www.phcityonweb.com/tutorial/css-programming-lessons/margin-padding Also check out their positioning tutorials.