Rectangular inside circle responsive with contents - html

I'm trying to make rectangular inside the circle on the left , when im resizing the screen of the website the shapes moving out and the texts checking out from the shapes , any ways to make texts and shapes responsive to all screens
The code : https://codepen.io/enespro/pen/rNWmLvP
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="circle">
<h3 class="mt-4">Bzns Monster School<br><span style="font-size: 20px; color: #DDDD;">From Zero To Hero</span></h3>
</div>
<div class='rect-box'>
</div>
<div class='rect-content'>
<div class="content">
<span>Lorem ipsum dolor sit amet, consetetur<br> sadipscing elitr, sed diam nonumy eirmod<br> tempor invidunt ut labore et dolore magna.</span>
</div>
</div>
<button class="btn btn-outline-secondary ml-1">Read More</button>
</div>

I see in your code there's a lot of position absolute that will just drive you crazy in long term to maintain that code. What about using the magic of flex, instead? :)
I rewrote your code here below. Check it clicking on "Run Code Snippet" to see it in action.
I suggest on the mobile to separate the banner from the circle to make it responsive and readable.
Enjoy!
.wrapper {
position: relative;
display: flex;
align-items: center;
min-height: 300px;
flex-direction: column;
}
.circle {
border-radius: 50%;
background-color: #000;
min-width: 200px;
min-height: 200px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.circle span {
color: #fff;
}
.rectangle {
width: 100%;
padding: 10px;
text-align: center;
background-color: #eee;
}
#media screen and (min-width: 600px) {
.circle {
position: absolute;
}
.rectangle {
padding: 30px 0 30px 220px;
}
.wrapper {
flex-direction: row;
}
}
<div class='wrapper'>
<div class='circle'><span>Lorem Ipsum</span></div>
<div class='rectangle'>Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum</div>
</div>

Related

How to make an image take up the rest of the available space automatically inside a 100vh container?

I have a container which has the height of 100vh. It contains an image and some text. The height of the text can change based on the screen and text. I want the text to take up the space that it needs and the image should use the rest of the available space.
Here is my code. It is already what I want basically but I want to get rid of the 83vh. The image should take the rest of the space dynamically. Is this possible?
Thank you guys!
PS: I added the Javascript tag because I'm not sure if a Javascript solution might be necessary.
.container {
height: 100vh;
max-height: 100vh;
background-color: #CCCCCC;
}
img {
max-height: 100%;
width: 100%;
object-fit: cover;
object-position: center -180px;
/* this height should be dynamically */
height: 83vh
}
.text-wrapper {
padding-left: 15px;
}
<div class="container">
<img src="https://img.100r.systems/img/be10bc26de653473f80b4348addfc6b5.jpg">
<div class="text-wrapper">
<h1>Some Text goes here</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor <br>invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
</div>
</div>
You could achieve this by using CSS grid. The two cells in the grid being of 1fr (ie as much space as is left) and auto in height.
This snippet also moves the img to be a background-image within a div, covering its cell and centered.
* {
margin: 0;
}
.container {
position: relative;
height: 100vh;
width: 100vw;
rmax-height: 100vh;
background-color: #CCCCCC;
display: grid;
grid-template-rows: 1fr auto;
grid-template-columns: 1fr;
}
.img {
width: 100%;
height: 100%;
background-size: cover;
background-position: center center;
background-image: url(https://img.100r.systems/img/be10bc26de653473f80b4348addfc6b5.jpg);
}
.text-wrapper {
padding-left: 15px;
}
<div class="container">
<div class="img"></div>
<div class="text-wrapper">
<h1>Some Text goes here</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor <br>invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
</div>
</div>
Note: for a completely general solution you need to decide what should happen if the text itself takes up more than the height of the viewport.
You can try this-
.container {
height: 100vh;
max-height: 100vh;
background-color: #CCCCCC;
display: flex;
flex-flow: column;
height: 100%;
}
.image-wrapper {
flex: 1 1 auto;
max-height: 100%;
overflow: hidden;
}
img {
max-height: 100%;
width: 100%;
object-fit: cover;
object-position: center -180px;
}
.text-wrapper {
padding-left: 15px;
flex: 0 1 auto;
}
<div class="container">
<div class="image-wrapper">
<img src="https://img.100r.systems/img/be10bc26de653473f80b4348addfc6b5.jpg">
</div>
<div class="text-wrapper">
<h1>Some Text goes here</h1>
<p>I think it works now<br> and I'm very happy now<br>It works, right?
</div>
</div>

How do I reposition my div element to the bottom of image using media query

How do I reposition my text to the bottom of the image after using media query?
main img {
width: 100%;
height: 100%;
}
div {
background-color: red;
display: flex;
flex-direction: column;
}
<main>
<img src="https://dummyimage.com/800x400/000/fff">
<div>
<h1>
Learn something new everyday
</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<button>Start Here</button>
</div>
</main>
You mean reposition like this? at what viewport? heres a sample
main img {
width: 100%;
height: 100%;
}
div {
background-color: red;
display: flex;
flex-direction: column;
}
#media only screen and (max-width:1024px){
div {
background-color: red;
display: flex;
flex-direction: column-reverse;
text-align:center;
}
}
<main>
<img src="https://dummyimage.com/800x400/000/fff">
<div>
<h1>
Learn something new everyday RESIZE ME
</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<button>Start Here</button>
</div>
</main>

Make <div> with childs always fit in parent <div>

I'm trying to make a div with some children inside always fit to the parent div which covers the whole page. It already works that the child div's width fits into the parent's. But the height should also fit inside the parent div. I want to avoid using overflow: auto because then the user will have to scroll in some cases. The child div (with it's children inside) should always fit in the parent's height and width.
How can I make this in CSS?
<div class="parent">
<div class="child">
<button>Toggle</button>
<img />
<p>Some text here...</p>
</div>
</div>
The <div class="parent"> covers the whole page. The <div class="child"> should scale into the <div class="parent"> width and height.
You can try this. You would need a media query for mobile but does what I think you are asking...
<html>
<head>
<style>
body {
font-weight: 400;
background-color: black;
color: white;
font-family: sans-serif;
margin: 0;
}
.grid {
min-height: 100%;
grid-column: 1 / -1;
grid-gap: 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(33%, 1fr));
}
.grid>span {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
}
.image {
background-image: url('https://live.staticflickr.com/7206/6859864719_5d68aedbd7.jpg');
background: cover;
background-position: center center;
background-repeat: no-repeat;
}
.toggle {
background: #4096C0;
border-radius: 2px;
padding: 12px 24px;
color: white;
width: auto;
text-align: center;
cursor: pointer;
}
.toggle:hover {
background: #00537C;
}
.text {
background: #40B6C0;
padding: 72px;
color: white;
}
</style>
</head>
<body>
<div class="container">
<div class="grid">
<span class="toggle">TOGGLE</span>
<span class="image"></span>
<span class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu fermentum dolor. Cras aliquet tempus elit ut eleifend. In commodo malesuada nisi non vulputate.</span>
</div>
</div>
</body>
</html>

How can I extend an image's height equidistant beyond its full-width container?

I have an image I'd like to extend beyond its parent container, just on the top and bottom, the same distance. I'm able to achieve this effect on the top, but am not able to do so on the bottom. How can I achieve this effect while still remaining responsive and keeping remaining content within the parent?
I've tried various methods of absolute positioning, but kept breaking the grid. I was able to achieve what I have thus far using negative margins, but only on top.
This is the very basic code I have thus far and here's the jsfiddle.:
.band {
background-color: #ddd;
margin-top: 100px;
}
.contain {
margin: 0 auto;
max-width: 600px;
}
.row {
align-content: flex-start;
clear: both;
display: flex;
flex-flow: row wrap;
overflow: visible;
}
.col {
width: 50%;
}
.col-image {
margin-top: -20px;
}
p {
padding: 20px;
}
img {
display: block;
height: auto;
max-width: 100%;
}
<div class="band">
<div class="contain">
<div class="row">
<div class="col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="col col-image">
<img src="https://via.placeholder.com/800x450?text=fpo">
</div>
</div>
</div>
</div>
Another solution using negative margins and absolute positioning on the image:
use negative margins for the offsetting of the second column,
using absolute positioning of the image in the second column ensures that the height is determined by the left column (because the row container is a flexbox and align-items: stretch is the default), and
use object-fit: cover to maintain image aspect ratio.
See demo below:
.band {
background-color: #ddd;
margin-top: 100px;
}
.contain {
margin: 0 auto;
max-width: 600px;
}
.row {
align-content: flex-start;
clear: both;
display: flex;
flex-flow: row wrap;
overflow: visible;
}
.col {
width: 50%;
}
.col-image {
margin: -20px 0 -20px 0; /* negative margin */
position: relative;
}
p {
padding: 20px;
}
img {
display: block;
height: 100%;
width: 100%;
object-fit: cover;
/* absolute positioning */
position: absolute;
top: 0;
left: 0;
}
<div class="band">
<div class="contain">
<div class="row">
<div class="col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="col col-image">
<img src="https://via.placeholder.com/800x450?text=fpo">
</div>
</div>
</div>
</div>
Positioning seems to work
.band {
background-color: #ddd;
margin-top: 100px;
}
.contain {
margin: 0 auto;
max-width: 600px;
}
.row {
align-content: flex-start;
clear: both;
display: flex;
flex-flow: row wrap;
overflow: visible;
position: relative;
}
.col {
width: 50%;
}
.col-image {
position: absolute;
top: -20px;
bottom: -20px;
left: 50%
}
p {
padding: 20px;
}
img {
display: block;
height: 100%;
}
<div class="band">
<div class="contain">
<div class="row">
<div class="col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="col col-image">
<img src="https://via.placeholder.com/800x450?text=fpo">
</div>
</div>
</div>
</div>
You can also play with background of the band element to simulate this
.band {
background:
url(https://via.placeholder.com/800x450?text=fpo) calc(50% + 160px) 0/auto 100%,
linear-gradient(#ddd,#ddd) center/100% calc(100% - 40px);
background-repeat:no-repeat;
margin-top: 100px;
}
.contain {
margin: 0 auto;
max-width: 600px;
}
.row {
display: flex;
flex-flow: row wrap;
}
.col {
width: 50%;
}
p {
padding:40px 20px;
}
<div class="band">
<div class="contain">
<div class="row">
<div class="col">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</div>
</div>
</div>

3 column fixed header that expands height to fit content

I'm trying to create a fixed header at the top of my page that has 3 "columns". The first is left justified on the left side, the second is centered relative to the whole page - regardless of the other two column sizes, and the third is right justified, stuck on the right. I want all of the content centered vertically.
Floats didn't really work because then the middle column was not properly centered. So I used two position: absolute div's for the left and right, and just left one div in the middle.
My problem is that I can't get the header to expand to contain the left div, which is taller, and I can't get the content to center vertically.
What am I doing wrong? Thanks!
Here is my code:
.header {
z-index: 8;
top: 0;
left: 0;
position: fixed;
padding-top: 1rem;
padding-bottom: 1rem;
width: 100%;
background: white;
z-index: 8;
border-bottom: 1px solid black;
text-align: center;
}
.left {
position: absolute;
top: 1rem;
left: 1rem;
border: 1px solid gray;
background: red;
padding: 1rem;
height: 10rem;
}
.right {
position: absolute;
right: 1rem;
top: 1rem;
background: yellow;
border: 1px solid gray;
}
.middle {
background: green;
border: 1px solid gray;
}
<div class="header">
<div class="left">Left</div>
<div class="middle">MIDDLE......</div>
<div class="right">Right</div>
</div>
Here is the link to my fiddle.
I would suggest using a flexbox for the vertical alignment.
header {
display: flex;
justify-content: space-between;
align-items: center;
}
header>div {
padding: 1rem; /* To improve visibility */
width: calc(100% / 3);
}
.col1 {
text-align: left;
}
.col2 {
text-align: center;
}
.col3 {
text-align: right;
}
<header>
<div class="col1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="col2">Lorem ipsum dolor sit amet, consectetur adipiscing elit...</div>
<div class="col3">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
</header>
Instead of the css that you have written, you can finish the above in just 8 lines. You just need to write the following:
.header{
display:flex;
}
.left, .middle, .right{
width: calc(100% / 3);
text-align:center;
}
and you can add the following class to check if everything is according what you planned to do:
*{
border: 1px solid red;
}
Here is the link to the fiddle displaying the result of the above code.
Check the result in the following stack overflow snippet:
* {
border: 1px solid red;
}
.header {
display: flex;
}
.left,
.middle,
.right {
width: calc(100% / 3);
text-align: center;
}
<div class="header">
<div class="left">Left</div>
<div class="middle">MIDDLE......</div>
<div class="right">Right</div>
</div>