#external
{
background-color: #585858;
width: 200px;
height: 200px;
}
#internal
{
background-color: #111858;
width: 50px;
height: 100%;
}
<div id="external">
content 1
<div id="internal"></div>
</div>
In this case, how can I set a remnant height of external div to the internal div?
The problem is when I set 100% height to internal div, so internal height == external height.
Your request is a little unclear but flexbox can do what I think you are after.
p {
margin: 0;
}
.external {
background-color: rgba(255, 0, 0, 0.5);
width: 200px;
height: 200px;
display: inline-flex;
flex-direction: column;
margin: 10px;
}
.internal {
background-color: #111858;
100%;
flex: 1;
}
<div class="external">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<div class="internal"></div>
</div>
<div class="external">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nemo harum quia tempore! Sit, laboriosam, quam.</p>
<div class="internal"></div>
</div>
use this may help u
<style>
#external
{
background-color: #585858;
width: 200px;
height: 200px;
}
#internal
{
background-color: #111858;
width: 50px;
height: calc(100% - 20px);
}
.content
{
height:20px;
}
</style>
<div id="external">
<div class="content">content 1</div>
<div id="internal"></div>
</div>
Related
I have a hero image that has a text box overlapping the hero a little bit but when I add any content below the box it appears under the text box. Some media queries are added in my code below and it works but I feel like there has to be a way to contain the hero and overlapping text box into its own section. If had to add more text I'd have to go through and adjust all of the media queries to make it look good again so how can I achieve this without using media queries?
Here is my code:
.shell {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
/* overlap */
.shell:before {
content: "";
background-image: url(https://i.ibb.co/x866XdV/test-hero.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: bottom;
position: relative;
height: 300px;
width: 100%;
}
.shell-header {
color: #fff;
padding: 0px 20px;
}
.shell-body {
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.25);
background-color: #fff;
max-width: 85%;
position: absolute;
top: 80%;
}
img {
width: 20%;
height: 20%;
display: block;
margin-left: auto;
margin-right: auto;
}
body {
margin: 0;
font-family: sans-serif;
}
.wrapper {
padding-top: 12rem;
}
#media only screen and (min-width: 800px) {
.wrapper {
padding-top: 8rem;
}
}
#media only screen and (max-width: 360px) {
.wrapper {
padding-top: 11rem;
}
}
<div class="shell">
<div class="shell-header"></div>
<div class="shell-body">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Placeat vel ducimus illo consectetur commodi ex nulla aut amet ipsum maiores itaque, iusto quam mollitia facilis consequatur tempora neque quod eligendi?</p>
</div>
</div>
<div class="wrapper">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Placeholder_view_vector.svg" alt="">
</div>
Using padding is ideal. But you can play around with the positioning of your elements. For instance, you can set body to position: relative; & then nest .wrapper within .shell and set .wrapper to position: absolute;.
.shell {
display: flex;
flex-direction: column;
align-items: center;
}
/* overlap */
.shell:before {
content: "";
background-image: url(https://i.ibb.co/x866XdV/test-hero.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: bottom;
position: relative;
height: 300px;
width: 100%;
}
.shell-header {
color: #fff;
padding: 0px 20px;
}
.shell-body {
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.25);
background-color: #fff;
max-width: 85%;
position: absolute;
top: 80%;
}
img {
width: 20%;
height: 20%;
display: block;
margin-left: auto;
margin-right: auto;
}
body {
margin: 0;
font-family: sans-serif;
position: relative;
}
.wrapper {
position: absolute;
bottom: -80%;
}
<div class="shell">
<div class="shell-header"></div>
<div class="shell-body">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Placeat vel ducimus illo consectetur commodi ex nulla aut amet ipsum maiores itaque, iusto quam mollitia facilis consequatur tempora neque quod eligendi?</p>
</div>
<div class="wrapper">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Placeholder_view_vector.svg" alt="">
</div>
</div>
Example using negative margin.
.shell {
display: flex;
flex-direction: column;
align-items: center;
}
/* overlap */
.shell:before {
content: "";
background-image: url(https://i.ibb.co/x866XdV/test-hero.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: bottom;
position: relative;
height: 300px;
width: 100%;
}
.shell-header {
color: #fff;
padding: 0px 20px;
}
.shell-body {
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.25);
background-color: #fff;
max-width: 85%;
margin-top: -6.375rem;
position: relative;
z-index: 1;
}
img {
width: 20%;
height: 20%;
display: block;
margin-left: auto;
margin-right: auto;
}
body {
margin: 0;
font-family: sans-serif;
position: relative;
}
.wrapper {
margin-top: 1em;
}
<div class="shell">
<div class="shell-header"></div>
<div class="shell-body">
<h1>Title</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Placeat vel ducimus illo consectetur commodi ex nulla aut amet ipsum maiores itaque, iusto quam mollitia facilis consequatur tempora neque quod eligendi?</p>
</div>
</div>
<div class="wrapper">
<img src="https://upload.wikimedia.org/wikipedia/commons/3/3f/Placeholder_view_vector.svg" alt="">
</div>
How can I expand the width of the text group while not affecting the sizing of the image? When I add a width on the text group, it makes the image smaller.
body {
background: #0A0B5B;
}
.hero {
display: flex;
justify-content: space-between;
}
.text-group {
background-color: green;
}
img {
position: relative;
right: -40%;
}
<section class="hero">
<div class="text-group">
<h2>Space Enthusiast & JavaScript Developer</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
</div>
<img src="https://raw.githubusercontent.com/iamshaunjp/responsive-css-grid-build/lesson-14/assets/banner_image.png" alt="">
</section>
I think this is more suitable for a background:
body {
background: #0A0B5B;
}
.hero {
display: flex;
background:
url(https://raw.githubusercontent.com/iamshaunjp/responsive-css-grid-build/lesson-14/assets/banner_image.png)
right/
auto 100%
no-repeat;
}
.text-group {
min-height: 300px;
color:#fff;
}
<section class="hero">
<div class="text-group">
<h2>Space Enthusiast & JavaScript Developer</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
</div>
</section>
You can apply a fixed width and flex-shrink: 0; to the .text-group. That way it won't become any smaller than the defined width.
body {
background: #0A0B5B;
}
.hero {
display: flex;
justify-content: space-between;
}
.text-group {
background-color: green;
width: 300px;
flex-shrink: 0;
}
img {
position: relative;
right: -40%;
}
<section class="hero">
<div class="text-group">
<h2>Space Enthusiast & JavaScript Developer</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
</div>
<img src="https://raw.githubusercontent.com/iamshaunjp/responsive-css-grid-build/lesson-14/assets/banner_image.png" alt="">
</section>
I modified the code with more flex configuration. I hope this is what you are looking for.
body {
background: #0A0B5B;
}
.hero {
display: flex;
justify-content: space-between;
}
.text-group {
background-color: green;
display: flex;
flex-direction: column;
justify-content: center;
flex: 1 0 500px;
}
img {
flex: 0 0 auto;
}
<section class="hero">
<div class="text-group">
<h2>Space Enthusiast & JavaScript Developer</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
</div>
<img src="https://raw.githubusercontent.com/iamshaunjp/responsive-css-grid-build/lesson-14/assets/banner_image.png" alt="">
</section>
I imagine CSS looks out of place in my example but these styles are added by library, particularily styles in #top, #middle, #bottom. I need .header elements to stick to top.
I've tried all kinds of styles but no luck. Feel free to overwrite or add any styles. How to make this work with the HTML structure I have?
#top {
display: flex;
position: relative;
z-index: 0;
overflow: hidden !important;
max-height: 300px;
max-width: 300px;
border: 2px dashed #ec6161;
}
#middle {
padding-right: 19px;
margin-bottom: -34px;
overflow: scroll;
overflow-x: hidden !important;
min-width: 100%! important;
max-height: inherit !important;
box-sizing: content-box !important;
}
#bottom {
padding-bottom: 17px;
margin-right: -19px;
overflow: scroll;
overflow-y: hidden !important;
box-sizing: border-box !important;
min-height: 100% !important;
}
.header {
position: sticky;
top: 0;
z-index: 1;
background: #eee;
padding: 5px 7px;
font-weight: bold;
}
.content {
height: 100px;
padding: 5px 7px;
}
<div id="top">
<div id ="middle">
<div id="bottom">
<div>
<div>
<div class="header">Header</div>
<div class="content">Content</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Content</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Content</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Content</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Content</div>
</div>
</div>
</div>
</div>
</div>
Also: https://jsfiddle.net/bkn0e3gL/2/
Setting overflow: hidden on any parent divs seems to be causing the problem.
Check out this answer:
if you set overflow to hidden on any ancestor of your sticky element, then this ancestor element will be the scrolling container for your sticky element.
.header {
background: #B8C1C8;
border-bottom: 1px solid #989EA4;
border-top: 1px solid #717D85;
color: #FFF;
position: -webkit-sticky;
position: sticky;
top: -1px;
}
.content {
min-height: 200px;
}
#bottom {
padding-bottom: 17px;
margin-right: -19px; //overflow: scroll;
//overflow-y: hidden !important;
box-sizing: border-box !important;
min-height: 100% !important;
}
#middle {
padding-right: 19px;
margin-bottom: -34px; //overflow: scroll;
//overflow-x: hidden !important;
min-width: 100% ! important;
max-height: inherit !important;
box-sizing: content-box !important;
}
#top {
display: flex;
position: relative;
z-index: 0;
//overflow: hidden !important;
max-height: 300px;
max-width: 300px;
border: 2px dashed #ec6161;
}
<div id="top">
<div id="middle">
<div id="bottom">
<div>
<div>
<div class="header">Header</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque viverra.</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque viverra.</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque viverra.</div>
</div>
<div>
<div class="header">Header</div>
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque viverra.</div>
</div>
</div>
</div>
</div>
</div>
I have dealt with this problem for some days now and it's making me crazy, I want the text inside the circle to move in the same position inside the cirkle div when I make the screen smaller, as illustrated in the picture.
If you have any tips please share!
CSS Code and Html Code:
.circleBase {
border-radius: 50%;
}
.contact-circle {
margin-top: 29%;
margin-left: 4%;
position: fixed;
width: 23%;
height: auto;
padding-top: 23%;
background-color: rgba(255, 86, 86, 0.2);
}
#contact-text {
top: 20%;
bottom: 20%;
left: 18%;
font-size: auto;
position: absolute;
text-align: center;
width: 60%;
opacity: 1;
}
<div class="circleBase contact-circle">
<div id="contact-text">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
</p>
</div>
</div>
Use another method to center the text. Here is an idea with flex:
.circleBase {
border-radius: 50%;
}
.contact-circle {
position: fixed;
width: 23%;
height: auto;
padding-top: 23%;
background-color: rgba(255, 86, 86, 0.2);
}
#contact-text {
top: 0;
position: absolute;
bottom: 0;
left: 10%;
right: 10%;
display: inline-flex;
justify-content: center;
align-items: center;
text-align: center
}
<div class="circleBase contact-circle">
<div id="contact-text">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
</p>
</div>
</div>
Responsive web site - #media (min-width:450px) and (max-width:900px) { css style }
<div class="circleBase contact-circle">
<div id="contact-text">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
</div>
</div>
Css #media Example
.circleBase {
height:800px;
width:800px;
}
#media (max-width:479px) {
.circleBase {
height: 400px;
width:400px;
}
}
I've got a layout, here's my css:
body {
background-color: #16193B; /* Old browsers */
margin: 0;
padding: 0;
color: white;
background-attachment: fixed;
overflow: hidden;
}
html {
min-height: 100%;
height: 100%;
margin: 0;
padding: 0;
background-attachment: fixed;
}
#content {
width: 80%;
height: 1000px;
margin: 0 auto;
background-color: #ADD5F7;
overflow : hidden;
}
#wrap div{
height:100%;
width:100%;
}
#b1 {
width: 80%;
height: 1000px;
margin: 0 auto;
background-color: #35478C;
position:relative;
}
#b2 {
width: 90%;
height: 1000px;
margin: 0 auto;
background-color: #4E7AC7;
position:relative;
}
#b3 {
width: 90%;
height: 1000px;
margin: 0 auto;
background-color: #7FB2F0;
position:relative;
}
#b4 {
width: 90%;
height: 1000px;
margin: 0 auto;
background-color: #ADD5F7;
overflow : auto;
position:relative;
}
And thats in the body of the HTML-File:
<div id="b1">
<div id="b2">
<div id="b3">
<div id="b4">
<div id="content">
</div>
</div>
</div>
</div>
</div>
This is my layout, but it should just be the background of the page... Unfortunately if I add text to some other div then "content" the rectangle overlays the others. How can I fix this? Actually I want a menu bar which is the top "layer" and overlays all under it...
Ok, before you look at my jsFiddle-Solution:
Be aware that using divs for such backgrounds is not a beautiful solution. Best would be using a background-image on your body-tag, which you stretch with background-size. It's supported in all modern browsers. The only problem would be IE8 and downwards.
Your CSS is a mess. When styling elements with similar attributes, use a class instead styling every ID by itself.
I basically created a new div with your custom content and a class on your background-divs. I also had to clean up your CSS and deleted unnecessary statements:
-> jsFiddle <-
HTML:
<div class="centerIt" id="b1">
<div class="centerIt" id="b2">
<div class="centerIt" id="b3">
<div class="centerIt" id="b4">
<div id="content"></div>
</div>
</div>
</div>
</div>
<div id="contentContainer">
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam excepturi laboriosam illum esse voluptas libero aperiam voluptate omnis dolor odio natus tempore sunt doloribus. Suscipit iure vel totam eius reprehenderit.</div>
</div>
CSS:
.centerIt {
position: relative;
margin-left: auto;
margin-right: auto;
}