Child element overflows parent [closed] - html

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a body consisting of 2 navigation bars(top), top-graphic(middle) flexbox and a content flexbox(bottom).
Within the top-graphic flexbox I want to insert a black box in which I can put text. When I make this box, it doesnt overflow the top of the parent box, however it overflows the bottom and the right side of the parent, continueing into my content box when I resize the page. I want my box to stay inside the boundaries of its parent element and take my parent into respect when I set my width/height, so that it doesnt overlap the content flexbox when I resize the website.
.nav {
display: flex;
flex: 1;
background-color: white;
flex-direction: column;
}
.topnav {
flex: 1;
background-color: white;
border-bottom: ridge 1px;
}
.bottomnav {
flex: 1;
background-color: white;
}
.topgraphic {
overflow: hidden;
position: relative;
flex: 2;
background-color: lightblue;
z-index: -2;
}
.topgraphic img {
background-size: cover;
background-repeat: no-repeat;
position: absolute;
width: 100%;
height: 100%;
-moz-box-shadow: inset 0px 12px 15px -12px #696868;
-webkit-box-shadow: inset 0px 12px 15px -12px #696868;
box-shadow: inset 0px 12px 15px -12px #696868;
z-index: -1;
}
.topgraphic .textbox {
box-sizing: inherit;
position: absolute;
margin-right: 5%;
margin-bottom: 10%;
width: 30%;
height: 80%;
background-color: rgba(0, 0, 0, 0.6);
}
.content {
z-index: -5;
flex: 7;
background-color: white;
min-height: 25%;
}
<div class="nav">
<div class="topnav"></div>
<div class="bottomnav"></div>
</div>
<div class="topgraphic">
<img alt="TopGraphic" class="auto-style1" src="Images/Topgraphic.jpg" />
<asp:Image ID="Image1" runat="server" />
<div class="textbox">
<!-- <div class="topText">
<h1>Demonstration</h1>
</div> -->
</div>
</div>

As it's a little bit difficult to really understand what your a looking for, I here made a guess based on your existing code.
Is this an overall layout you are looking for?
* {
box-sizing: border-box;
}
html, body {
margin: 0;
width: 100%;
height: 100%;
color: gray;
padding: 1%;
}
.outer {
display: flex;
flex-flow: column;
height: 98%;
width: 90%;
margin: 0 auto;
box-shadow: 0px 0px 10px 0px #696868;
}
.top {
display: flex;
flex-flow: column;
background-color: white;
}
.middle {
background-color: lightblue;
background-image: url(http://lorempixel.com/400/100/sports/9/);
background-size: cover;
background-repeat: no-repeat;
clear: right;
}
.middle .textbox {
float: right;
width: 30%;
height: 70px;
background-color: rgba(0,0,0,0.7);
}
.content {
position: relative;
flex: 1 0 auto;
height: 0;
}
.content-inner {
background-color: white;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
<div class="outer">
<div class="top">
<div class="top">top top</div>
<div class="bottom">top bottom</div>
</div>
<div class="middle">
<div class="textbox">
text box
</div>
</div>
<div class="content">
<div class="content-inner">content</div>
</div>
</div>

Related

Custom icon and text in column when I set flex-direction as row?

I am trying to make a clickable section with a play button, some text and the thumbnail of the youtube video to play, all on one line.
I have managed to create my custom play button, I have my thumbnail correctly sized, but I can't seem to get them all on one line for some reason, despite me putting the container as a flex with flex-direction: row.
Am I missing something here?
Note: If I comment out the play button, then the text and the thumbnail do live on the same row.
body {
background: darkgrey;
}
.page-container {
background: lightgrey;
width: 320px;
margin: auto auto;
height: 600px;
}
.section-container {
background: white;
width: 288px;
margin: auto auto;
height: 500px;
}
.video-container {
display: flex;
flex-direction: row;
}
.video-thumbnail {
background-image: url('https://i3.ytimg.com/vi/I-k-iTUMQAY/mqdefault.jpg');
width: 71.63px;
height: 40.14px;
background-size: 71.63px 40.14px;
}
/* Play button */
.play-button-outer {
display: inline-block;
box-sizing: border-box;
border-radius: 50%;
width: 32px;
height: 32px;
background-color: rgba(0, 115, 144, 0.16);
cursor: pointer;
}
.play-button-inner {
margin: 0 auto;
top: calc(50% - 6.645px);
position: relative;
width: 0;
height: 0;
border-style: solid;
border-width: 6.645px 0 6.645px 11.04px;
border-color: transparent transparent transparent #007390;
}
<div class="page-container">
<div class="section-container">
<div class="video-container">
<div class="play-button-outer">
<div class="play-button-inner"/>
</div>
<div class="text">Some text</div>
<div class="video-thumbnail"/>
</div>
</div>
</div>
You closed divs incorrectly
<div class="play-button-inner"/>
<div class="video-thumbnail"/>
should be closed like this
<div class="play-button-inner"></div>
<div class="video-thumbnail"></div>

How do you use background: auto; correctly?

I'm trying to make the background fill the whole page. The only way I figured out how to do it is by setting the height and width of <div id="All"> and putting that div around everything else. I know that if I change the size of the browser, though, it won't auto resize, so it would look weird if I made my browser smaller or bigger.
If I set height and width to auto on #All, it def doesn't fill out the whole webpage. Please advise what I am doing wrong. Plus if I do auto, the sticky #Move doesn't stay at the top of the page.
This code is just stuff I have learned, so not an actual project, but I want to learn how to do it for future projects.
#Move {
position: sticky;
top: 0;
color: red;
}
h1 {
color: red;
}
.Hello {
font-size: 36px;
}
.Hello2 {
font-size: 15px;
}
p {
color: white;
}
.DivClass {
width: 160px;
height: 220px;
padding: 40px;
border: 10px solid black;
border-radius: 60px;
margin: 50px;
background: url("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSqOq9_iT948LTPmS5FuCMlaqlvn2KJQ-0d7Xw5kLMfWz69wwRA&usqp=CAU");
background-repeat: no-repeat;
background-size: cover;
opacity: 80%;
}
.image-whitecat {
width: 500px;
heigth: 500px;
background-color: red;
margin: 50px 50px 90px 250px;
transform: rotate(10deg);
}
.image-cat {
width: 700px;
height: 500px;
border-radius: 300px;
margin-left: 350px;
filter: opacity(70%)
}
.Purple {
color: purple;
}
.PurpleText {
background: teal;
text-align: center;
padding-top: 50px;
width: 150px;
height: 100px;
border: 5px solid red;
border-radius: 100px;
margin: 10px 0 0 1000px;
}
#All {
background-color: lavender;
position: absolute;
top: 10px;
bottom: 10px;
height: 1850px;
width: 1810px;
}
<div id="All">
<div class="DivClass">
<h1>HELLO!!!</h1>
<p class="Hello">Hello</p>
<p class="Hello2">Hello 2</p>
<p>Yes</p>
</div>
<p id="Move">I will stay at the top of the page!</p>
<div>
<img src="https://cdn.pixabay.com/photo/2014/11/30/14/11/kitty-551554__340.jpg" class="image-whitecat" />
</div>
<div>
<img src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" class="image-cat" />
</div>
<div class="PurpleText">
<p class="Purple">Purple</p>
</div>
</div>
I think you will need to give both your html and body tags a css height ...
html, body {
height: 100%;
margin: 0;
}
So,
https://jsfiddle.net/z51crou7/

How to place 'Background Image over another div'?

This question maybe not cool but want to know proper way to solve this task. Of course using HTML,CSS,Bootstrap.
Something like this:
Use CSS transform:
.cover {
background: blue;
height: 100px
}
.block {
transform: translate(0, -65px);
padding: 0 20px;
}
.text {
background: red;
height: 150px;
}
<div class="cover"></div>
<div class="block">
<div class="text">Hello, "Background Image over another div"</div>
</div>
Quick example, use negative margin top to place section over other section, replace styles with background image if you wish.
<section style="background:red;width:100%;height:300px">
</section>
<section style="width:100%;margin-top:-150px">
<div class="container">
<div style="width:100%;height:300px; background: white;"></div>
</div>
</section>
This should do what you want. https://codepen.io/anon/pen/KevYXE
Basically I created a DIV overlay and a background DIV. The background DIV is split into two sections. The top section uses a background image and the bottom section is a solid color. I used a relative position for the overlay and used percentages to make sure everything stays center.
HTML
<div id="wrap">
<div id="bg-overlay"></div>
<div id="bg-wrap">
<div id="bg-top"></div>
<div id="bg-bottom"></div>
</div>
</div>
CSS
body {
margin: 0;
padding: 0;
}
#wrap {
width: 100%;
height: 600px;
background: #ccc;
margin: 0 auto;
position: relative;
left: 0;
right: 0;
}
#bg-overlay {
position: absolute;
height: 70%;
max-width: 800px;
width: 80%;
top: 15%;
background: #fff;
left: 0;
right: 0;
margin: 0 auto;
-webkit-box-shadow: 0 6px 6px -6px #666;
-moz-box-shadow: 0 6px 6px -6px #666;
box-shadow: 0 6px 6px -6px #666;
}
#bg-wrap {
width: 100%;
height: 100%;
}
#bg-top {
height: 50%;
width: 100%;
float: left;
background: url("https://picsum.photos/2200/300") no-repeat;
background-position: center center;
}
#bg-bottom {
height: 50%;
width: 100%;
float: left;
background: #cccccc;
}

How to make header like that in css?

My site code is very usual
<div class="header"></div>
<div class="site-inner"></div>
<div class="footer"></div>
How can I make header background like on the image?
Is the whole site content have to be position absolute and margin-top:-500px ?
Is that only case to do it?
I assume you mean the overlap.
Negative margin is one way.
.header {
height: 50px;
background: lightblue;
}
.site-inner {
width: 80%;
margin: auto;
height: 50px;
background: lightgrey;
margin-top: -30px;
box-shadow: 0 -2px 2px black;
}
<div class="header"></div>
<div class="site-inner"></div>
You can use:
.header{
width: 80%;
height: 75px;
margin: 0 auto;
margin-top: -20px;
background:#3A3A3A;
}
Take a look at positioning: Positioning, also z-index might be relevant: Z-index, notice in my example the negative index on .header-bg
A quick example:
.header-bg {
width: 100%;
height: 200px;
z-index: -1;
background: lightblue;
position: absolute;
top: 0;
left: 0;
}
.header {
margin-top: 50px;
height: 50px;
background: grey;
z-index
}
.menu {
height: 80px;
}
.site-inner {
height: 400px;
width: 100%;
background: red;
}
<div class="header-bg"></div>
<div class="header"></div>
<div class="menu">menu</div>
<div class="site-inner">Site inner</div>
<div class="footer"></div>
A negative z-index lets you put elements behind others. The answer is simple enough then.
<div class="color"></div>
<div class="fixed">
<div class="header">
</div>
<div class="nav">
Text
</div>
<div class="body">
</div>
</div>
html, body
{
height: 100;
margin: 0;
}
div.color
{
position: absolute; /*Take out of the flow*/
top: 0; /*Move to top left*/
left: 0;
z-index: -1; /*Place below normal elements in the flow*/
width: 100%; /*Fill whole width*/
height: 300px; /*300px tall*/
background: #c7edfb; /*Color specified*/
}
div.fixed
{
margin: 50px auto 0; /*push whole document down 50px and center*/
width: 600px; /*document is 600px wide*/
}
div.header
{
height: 150px; /*top gray block is 150px tall*/
background: #222; /*dark gray*/
}
div.nav
{
padding: 25px 0; /*Gap between blocks above and below*/
}
div.body
{
min-height: 300px; /*Force a height*/
background: #777; /*Light gray*/
box-shadow: 0 0 8px black; /*Drop shadow*/
}
JSFiddle

Issue with content scrolling over banner and under header

So I have this fixed header which has z-index:10, below that a fixed banner and then below that a relative content container. What I want is that the content scrolls over the banner but under the header. However, when I try to scroll it doesn't work. The strange part to me is that whenever I add box-shadow: 0px 0px 2px rgb(100,100,125); to the content container it does do what I want. I'm using the following code:
* {
padding: 0;
margin: 0 auto;
}
body {
background: rgb(223,227,238);
text-align: center;
}
#body_container {
padding-top: 80px;
}
#banner_container {
position: fixed;
left: 0;
right: 0;
}
#banner {
width: 1024px;
height: 300px;
}
#content_container {
background: rgb(243,247,248);
max-width: 1024px;
height: 100%;
position: relative;
top: 300px;
box-shadow: 0px 0px 2px rgb(100,100,125);
}
header {
min-width: 100%;
background: rgb(50,50,50);
height: 80px;
position: fixed;
z-index: 10;
}
/* Header styling, not relevant */
#header_container {
max-width: 1024px;
height: 100%;
}
#header_container div {
float: left;
display: inline-block;
width: 25%;
}
#logo {
width: 50%;
height: auto;
}
.menuItem {
padding-top: 29px;
height: calc(100% - 29px);
border: 0;
text-align: center;
font-family: Signika;
font-size: 25px;
color: rgb(203,207,218);
}
.menuItem:hover {
border-bottom: 4px solid rgb(59,89,202);
height: calc(100% - 33px);
color: rgb(160,170,218);
}
.menuLogo {
padding-top: 14.5px;
height: calc(100% - 14.5px);
border: 0;
text-align: center;
}
#mobile_menu_button {
display: none;
}
<header>
<div id="header_container">
<div class="menuLogo">
<img id="logo" src="img/desygn%20logo%20website.png">
</div>
<div class="menuItem">Home</div>
<div class="menuItem">Over</div>
<div class="menuItem">Contact</div>
<div id="mobile_menu_button">
</div>
</div>
</header>
<div id="body_container">
<div id="banner_container">
<img id="banner" src="img/banner_website.png">
</div>
<div id="content_container">
</div>
</div>
In your code you've not added any content under content_container. I don't see any issue with your code. It is working fine. Check here with content