I have a div innerDetails which is a flex item with code as specified below:
.cover{
height: 100vh;
width: 100%;
}
#screenContainer{
display: flex;
justify-content: center;
align-items: center;
}
#screen{
height: 90vh;
width: 87vw;
background-color: #eeeeee;
border-radius: 2%;
display: flex;
justify-content: space-around;
align-items: center;
}
#innerScreen{
background-color: #060b22;
height: 80vh;
width: 80vw;
padding: 15px;
}
#details{
display: flex;
justify-content: space-evenly;
flex-wrap: wrap-reverse;
}
.innerDetails{
height: 100%;
width: 45%;
font-size: 1.7vw;
color: rgb(255, 117, 67);
font-family: Arial, Helvetica, sans-serif;
text-align: justify;
}
#backImage{
background-image: url(https://placehold.it/250px250);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
<div class="cover" id="screenContainer">
<div id="screen">
<div id="innerScreen">
<p class="heading" id="arr"></p>
<div id="details">
<div class="innerDetails">
<p id="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tincidunt ligula vel urna blandit, ut auctor dolor fermentum. Aenean ut augue tincidunt, bibendum nunc non, pulvinar nisl. Maecenas dapibus, ante vel tincidunt laoreet, sem ex finibus odio, sit amet ultricies ligula nunc a sem. Nam nulla velit, congue sit amet commodo interdum, consectetur sed nisi. Vivamus commodo dictum augue nec consectetur. Curabitur molestie viverra interdum. Nullam vel augue sed sem vulputate vulputate non id sapien. Aenean posuere egestas orci. Duis vitae suscipit ante, tempor tempor risus. Sed ut augue quis elit blandit maximus. Phasellus sit amet arcu et odio tristique malesuada</p>
</div>
<div id="backImage" class="innerDetails">fdbd</div>
</div>
</div>
</div>
</div>
(Well, there is a lot of code but I thin without it, reproducing my problem would not be possible. Some values are in vh and vw so expand the results.)
The problem is that the div's height is automatically decreasing from my specified height (100%) to 0%.
I thought it is so because there is no content inside the div, just a background-image. So I added some padding to it but it didn't work.
However, If I insert some text in the div, only that much part has the background image.
Just remove the height: 100% from .innerDetails
.cover {
height: 100vh;
width: 100%;
}
#screenContainer {
display: flex;
justify-content: center;
align-items: center;
}
#screen {
height: 90vh;
width: 87vw;
background-color: #eeeeee;
border-radius: 2%;
display: flex;
justify-content: space-around;
align-items: center;
}
#innerScreen {
background-color: #060b22;
height: 80vh;
width: 80vw;
padding: 15px;
}
#details {
display: flex;
justify-content: space-evenly;
flex-wrap: wrap-reverse;
}
.innerDetails {
/* height: 100%; */
width: 45%;
font-size: 1.7vw;
color: rgb(255, 117, 67);
font-family: Arial, Helvetica, sans-serif;
text-align: justify;
}
#backImage {
background-image: url(https://placehold.it/250px250);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
<div class="cover" id="screenContainer">
<div id="screen">
<div id="innerScreen">
<p class="heading" id="arr"></p>
<div id="details">
<div class="innerDetails">
<p id="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tincidunt ligula vel urna blandit, ut auctor dolor fermentum. Aenean ut augue tincidunt, bibendum nunc non, pulvinar nisl. Maecenas dapibus, ante vel tincidunt laoreet, sem ex finibus
odio, sit amet ultricies ligula nunc a sem. Nam nulla velit, congue sit amet commodo interdum, consectetur sed nisi. Vivamus commodo dictum augue nec consectetur. Curabitur molestie viverra interdum. Nullam vel augue sed sem vulputate vulputate
non id sapien. Aenean posuere egestas orci. Duis vitae suscipit ante, tempor tempor risus. Sed ut augue quis elit blandit maximus. Phasellus sit amet arcu et odio tristique malesuada</p>
</div>
<div id="backImage" class="innerDetails">fdbd</div>
</div>
</div>
</div>
</div>
It works but the #details doesn't actually have a height. Add height: 100% to #details and see the result.
.cover {
height: 100vh;
width: 100%;
}
#screenContainer {
display: flex;
justify-content: center;
align-items: center;
}
#screen {
height: 90vh;
width: 87vw;
background-color: #eeeeee;
border-radius: 2%;
display: flex;
justify-content: space-around;
align-items: center;
}
#innerScreen {
background-color: #060b22;
height: 80vh;
width: 80vw;
padding: 15px;
}
#details {
display: flex;
justify-content: space-evenly;
flex-wrap: wrap-reverse;
height: 100%; /* or 300px etc */
}
.innerDetails {
height: 100%;
width: 45%;
font-size: 1.7vw;
color: rgb(255, 117, 67);
font-family: Arial, Helvetica, sans-serif;
text-align: justify;
}
#backImage {
background-image: url(https://placehold.it/250px250);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
<div class="cover" id="screenContainer">
<div id="screen">
<div id="innerScreen">
<p class="heading" id="arr"></p>
<div id="details">
<div class="innerDetails">
<p id="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tincidunt ligula vel urna blandit, ut auctor dolor fermentum. Aenean ut augue tincidunt, bibendum nunc non, pulvinar nisl. Maecenas dapibus, ante vel tincidunt laoreet, sem ex finibus
odio, sit amet ultricies ligula nunc a sem. Nam nulla velit, congue sit amet commodo interdum, consectetur sed nisi. Vivamus commodo dictum augue nec consectetur. Curabitur molestie viverra interdum. Nullam vel augue sed sem vulputate vulputate
non id sapien. Aenean posuere egestas orci. Duis vitae suscipit ante, tempor tempor risus. Sed ut augue quis elit blandit maximus. Phasellus sit amet arcu et odio tristique malesuada</p>
</div>
<div id="backImage" class="innerDetails">fdbd</div>
</div>
</div>
</div>
</div>
Related
I have created the layout using the flexbox. I have an image and some text in the footer. But when I am zooming out or in the browser to check for responsiveness the image in the footer is going out.
This is what happens when the browser window size is decreased.
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: "Lato", "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-style: normal;
font-weight: 400;
letter-spacing: 0;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-moz-font-feature-settings: "liga" on;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
.container {
display: flex;
height: 100vh;
}
.sidebar {
flex: 1;
}
.content {
-webkit-flex: 5;
flex: 5;
background-color: lightblue;
}
.main {
padding: 1rem;
height: 70vh;
background-color: #ececec;
overflow-y: scroll;
}
.header,
.footer {
display: flex;
align-items: center;
height: 15vh;
}
header,
footer,
article,
nav,
aside {
padding: 1em;
}
.player {
border: 1px solid red;
}
.player {
display: flex;
align-items: center;
}
.album__cover>img {
width: 3.5rem;
height: 3.5rem;
}
.album__cover {
display: flex;
align-items: center;
margin-right: 1rem;
}
.playing__track {
display: flex;
flex-direction: column;
}
.playing__album {
display: flex;
align-items: center;
}
.album {
font-size: .875rem;
font-weight: 300;
}
.track {
font-size: .75rem;
}
<link
href="https://fonts.googleapis.com/css2?family=Lato:ital,wght#0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&display=swap"
rel="stylesheet">
<body>
<div class="container">
<nav class="sidebar">
<a>Logo Goes Here</a>
</nav>
<div class="content">
<header class="header">Header</header>
<main class="main">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mattis auctor sem, vitae
scelerisque eros feugiat non. Mauris sit amet arcu sed ligula pellentesque tempus non imperdiet
elit. Aliquam dapibus metus ac odio facilisis, vitae bibendum quam lacinia. Phasellus a ante ut
justo dictum bibendum et ut massa. Etiam hendrerit sapien venenatis lacinia sodales. In et massa
leo. Integer imperdiet orci ac scelerisque malesuada. Donec mattis velit nec elit tincidunt mattis.
Proin vel varius felis, vel scelerisque mauris. Nunc malesuada purus velit, eu euismod tellus
consectetur et.
</p>
<p>
Quisque tincidunt nisi non dolor porttitor maximus. Donec tempus auctor leo vitae maximus. Sed
mattis nibh velit, iaculis molestie massa tempus vitae. Aliquam ipsum sem, ornare condimentum magna
vitae, auctor sagittis odio. Duis ut urna vel est luctus suscipit. Suspendisse at aliquet metus, in
rhoncus ligula. Aliquam erat volutpat. Nullam ultricies elit vel eros convallis, ut suscipit erat
mattis. In hac habitasse platea dictumst.
</p>
<p>
Ut enim diam, auctor eu turpis non, egestas accumsan dui. Suspendisse vel lorem tempor, imperdiet
purus vel, tincidunt turpis. Praesent sit amet lacus vel enim iaculis egestas vitae eget nibh. Donec
consequat placerat odio, in laoreet magna pretium ac. Curabitur porttitor a elit sed scelerisque.
Curabitur laoreet eu nisi ac ornare. Cras ornare, metus ut vestibulum rhoncus, purus arcu lobortis
odio, ac iaculis urna mi ut ex. Maecenas vitae dolor non felis rhoncus imperdiet a vitae enim.
Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur eget condimentum dolor. Duis
lacinia libero quis lacinia lacinia. Ut pretium pulvinar vestibulum. Ut blandit eget tellus sit amet
ornare.
</p>
</main>
<footer class="footer">
<div class="player">
<div class="playing__album">
<div class="album__cover">
<img src="https://images.pexels.com/photos/1051838/pexels-photo-1051838.jpeg?cs=srgb&dl=pexels-prasanth-inturi-1051838.jpg" />
</div>
<div class="playing__track">
<div class="album">
Last and the first freedom
</div>
<div class="track">
<span> Chapter 1</span>
</div>
</div>
</div>
</div>
</footer>
</div>
</div>
</body>
How can I keep the image precisely inside the footer with the same padding and orientation?
You need to get rid of the fixed height and control the image it's width and height if you want the footer to be either bigger of smaller.
This is the solution
.header, .footer {
display: flex;
align-items: center;
/* height: 15vh; */
background-color: lightblue;
}
I think the issue is the units used for the padding, image size and font size. If you try using the vh unit instead of the rem unit, you might hav success.
.album__cover>img {
width: 3.5rem;
height: 3.5rem;
}
footer {
height: 10vh;
}
.album,
.track {
.album {
font-size: 0.875rem;
}
I have this web page. All the content of the web page is within the size of my desktop's view port. However, the width of the page still goes beyond the view port. I even tried putting margin and padding at 0 but nothing worked. It also looks especially awkward in mobile view. How do I fix that?
Below is the code:
:root {
--main-color:#ff9955ff;
--secondary-color:yellow;
--dark-color:#444;
--light-color:#fafafa;
}
body {
font-family: Montserrat, sans-serif;
background: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin: 0px;
padding: 0px;
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
font-size: 18px;
}
::selection {
background: var(--main-color);
color: var(--light-color);
}
a {
text-decoration: none;
color: var(--dark-color);
}
input {
box-sizing: border-box;
}
.box {
background: red;
height: 100px;
width: 100px;
}
.center-text {
text-align: center;
}
.columns-two, .columns-three, .columns-four, .columns-six {
display: flex;
flex-direction: row;
align-items: center;
align-content: center;
justify-content: center;
gap: 30px;
}
.columns-two div {
width: clamp(480px, 480px, 100%);
}
.columns-three div {
width: clamp(200px, calc((1000px - (30px * 2)) / 3), 100%);
}
.columns-four div {
width: calc((1000px - (30px * 3)) / 4);
}
.columns-six div {
width: calc((1000px - (30px * 5)) / 6);
}
.horizontal {
display: flex;
align-items: center;
align-content: center;
justify-content: center;
gap: 20px;
}
.max-height {
min-height: 100vh;
}
.half-height {
min-height: calc(100vh / 2);
}
.max-width {
width: clamp(200px, 90vw, 1000px);
}
.vertical {
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
justify-content: center;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
/* header */
.header {
height: 70px;
justify-content: space-between;
}
.title {
height: 100%;
}
.title img {
height: 100%;
width: clamp(0px,250px,60%);
}
.nav-toggle-checkbox, .nav-toggle-spans {
position: fixed;
top: 2.5%;
right: -100vw;
height: clamp(10px,80px,20vw);
width: clamp(10px,80px,20vw);
}
.nav-toggle-checkbox {
opacity: 0;
}
.nav-toggle-spans span {
height: 20%;
background: var(--main-color);
margin: 10% 0;
display:flex;
flex-direction: row;
z-index: 2;
transition: 400ms;
}
.navbar {
display: flex;
gap: 2.5px;
transition: 300ms;
}
.navbar a {
margin: 5px;
}
/* footer */
footer {
background: var(--main-color);
width: 100vw;
padding: 20px 0;
text-align: center;
}
.socials {
gap: 10px;
}
footer img {
height: 50px;
width: 50px;
}
#media screen and (max-width:700px) {
.nav-toggle-checkbox, .nav-toggle-spans {
right: 5%;
transition: 400ms;
}
.nav-toggle-spans {
z-index: 2;
}
.nav-toggle-checkbox {
z-index: 3;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans span {
background: var(--light-color);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-one {
position: relative;
top: 30%; /* Changed from 100% */
transform: rotate(45deg);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-two {
opacity: 0;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-three {
position: relative;
top: -30%;
transform: rotate(-45deg);
transition: 400ms;
}
.navbar, .nav-toggle-checkbox:not(:checked) ~ .navbar {
position:fixed;
top: 0;
right: -100vh;
height: 100%;
display: flex;
flex-direction: column;
justify-content:flex-start;
background: var(--main-color);
opacity: 90%;
border-left: 4px solid var(--secondary-color);
padding: 150px 5% 0 50px;
z-index: 1;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar {
right: 0;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar a {
color: var(--light-color);
text-align: right;
font-size: 1.25em;
}
}
<body tabindex="-1">
<div id="svelte">
<body>
<div class="max-width">
<header class="header horizontal">
<div class="title"><img loading="lazy" src="./logo-title.svg" alt="Title"></div> <input type="checkbox" class="nav-toggle-checkbox">
<div class="nav-toggle-spans"><span class="nav-span-one"></span> <span class="nav-span-two"></span> <span class="nav-span-three"></span></div>
<nav class="navbar">Home Elements Services Contact</nav>
</header>
<!--<Header>-->
<head>
<title>Home - CSS Templates</title>
</head>
<section class="vertical">
<h2>2 Columns</h2>
<div class="wrap columns-two">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
</div>
</section>
<!--<ColumnsTwo>-->
<section class="vertical max-height">
<h2>3 Columns</h2>
<div class="wrap columns-three">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
</div>
</section>
<!--<ColumnsThree>-->
<section class="vertical">
<hr>
<h2>4 Columns</h2>
<div class="wrap columns-four">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsFour>-->
<section class="vertical">
<hr>
<h2>6 Columns</h2>
<div class="wrap columns-six">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsSix>-->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Amet luctus venenatis lectus
magna fringilla urna porttitor rhoncus dolor. Nisi quis eleifend quam
adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet consectetur
adipiscing. Eu consequat ac felis donec et odio pellentesque diam. Volutpat
commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Sem et
tortor consequat id porta nibh venenatis cras. Sed faucibus turpis in eu mi
bibendum neque egestas congue. Etiam non quam lacus suspendisse faucibus
interdum posuere lorem. Malesuada fames ac turpis egestas maecenas pharetra.
Lorem ipsum dolor sit amet consectetur. Ut enim blandit volutpat maecenas
volutpat blandit aliquam etiam erat. Id aliquet risus feugiat in ante metus.</p>
<footer>
<p class="socials"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook"></p>
<p>This website was designed by Name</p>
</footer>
</body>
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true" class="s-jHz34e3aRDB7"></div>
</div>
</body>
Go to the top of the CSS and put "* {width: 100%}". If that doesn't work, you might have to manually change the width until it fits the size of your viewport.
Please mark this as an answer if this helped you.
Change the footer CSS width unit from vw to %:
footer {
background: var(--main-color);
width: 100%;
padding: 20px 0;
text-align: center;
}
:root {
--main-color: #ff9955ff;
--secondary-color: yellow;
--dark-color: #444;
--light-color: #fafafa;
}
body {
font-family: Montserrat, sans-serif;
background: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin: 0px;
padding: 0px;
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
font-size: 18px;
}
#svelte {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: center;
justify-content: center;
align-items: center;
}
::selection {
background: var(--main-color);
color: var(--light-color);
}
a {
text-decoration: none;
color: var(--dark-color);
}
input {
box-sizing: border-box;
}
.box {
background: red;
height: 100px;
width: 100px;
}
.center-text {
text-align: center;
}
.columns-two,
.columns-three,
.columns-four,
.columns-six {
display: flex;
flex-direction: row;
align-items: center;
align-content: center;
justify-content: center;
gap: 30px;
}
.columns-two div {
width: clamp(480px, 480px, 100%);
}
.columns-three div {
width: clamp(200px, calc((1000px - (30px * 2)) / 3), 100%);
}
.columns-four div {
width: calc((1000px - (30px * 3)) / 4);
}
.columns-six div {
width: calc((1000px - (30px * 5)) / 6);
}
.horizontal {
display: flex;
align-items: center;
align-content: center;
justify-content: center;
gap: 20px;
}
.max-height {
min-height: 100vh;
}
.half-height {
min-height: calc(100vh / 2);
}
.max-width {
width: clamp(200px, 90vw, 1000px);
}
.vertical {
display: flex;
flex-direction: column;
align-items: center;
align-content: center;
justify-content: center;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
/* header */
.header {
height: 70px;
justify-content: space-between;
}
.title {
height: 100%;
}
.title img {
height: 100%;
width: clamp(0px, 250px, 60%);
}
.nav-toggle-checkbox,
.nav-toggle-spans {
position: fixed;
top: 2.5%;
right: -100vw;
height: clamp(10px, 80px, 20vw);
width: clamp(10px, 80px, 20vw);
}
.nav-toggle-checkbox {
opacity: 0;
}
.nav-toggle-spans span {
height: 20%;
background: var(--main-color);
margin: 10% 0;
display: flex;
flex-direction: row;
z-index: 2;
transition: 400ms;
}
.navbar {
display: flex;
gap: 2.5px;
transition: 300ms;
}
.navbar a {
margin: 5px;
}
/* footer */
footer {
background: var(--main-color);
width: 100vw;
padding: 20px 0;
text-align: center;
}
.socials {
gap: 10px;
}
footer img {
height: 50px;
width: 50px;
}
#media screen and (max-width: 700px) {
.nav-toggle-checkbox,
.nav-toggle-spans {
right: 5%;
transition: 400ms;
}
.nav-toggle-spans {
z-index: 2;
}
.nav-toggle-checkbox {
z-index: 3;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans span {
background: var(--light-color);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-one {
position: relative;
top: 30%; /* Changed from 100% */
transform: rotate(45deg);
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-two {
opacity: 0;
}
.nav-toggle-checkbox:checked ~ .nav-toggle-spans .nav-span-three {
position: relative;
top: -30%;
transform: rotate(-45deg);
transition: 400ms;
}
.navbar,
.nav-toggle-checkbox:not(:checked) ~ .navbar {
position: fixed;
top: 0;
right: -100vh;
height: 100%;
display: flex;
flex-direction: column;
justify-content: flex-start;
background: var(--main-color);
opacity: 90%;
border-left: 4px solid var(--secondary-color);
padding: 150px 5% 0 50px;
z-index: 1;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar {
right: 0;
transition: 400ms;
}
.nav-toggle-checkbox:checked ~ .navbar a {
color: var(--light-color);
text-align: right;
font-size: 1.25em;
}
}
<body tabindex="-1">
<div id="svelte">
<body>
<div class="max-width">
<header class="header horizontal">
<div class="title"><img loading="lazy" src="./logo-title.svg" alt="Title"></div> <input type="checkbox" class="nav-toggle-checkbox">
<div class="nav-toggle-spans"><span class="nav-span-one"></span> <span class="nav-span-two"></span> <span class="nav-span-three"></span></div>
<nav class="navbar">Home Elements Services Contact</nav>
</header>
<!--<Header>-->
<head>
<title>Home - CSS Templates</title>
</head>
<section class="vertical">
<h2>2 Columns</h2>
<div class="wrap columns-two">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue. Etiam non quam
lacus suspendisse faucibus interdum posuere lorem. Malesuada fames ac
turpis egestas maecenas pharetra. Lorem ipsum dolor sit amet
consectetur. Ut enim blandit volutpat maecenas volutpat blandit aliquam
etiam erat. Id aliquet risus feugiat in ante metus.</p>
</div>
</div>
</section>
<!--<ColumnsTwo>-->
<section class="vertical max-height">
<h2>3 Columns</h2>
<div class="wrap columns-three">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Amet luctus
venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisi quis
eleifend quam adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet
consectetur adipiscing. Eu consequat ac felis donec et odio pellentesque
diam. Volutpat commodo sed egestas egestas fringilla phasellus faucibus
scelerisque. Sem et tortor consequat id porta nibh venenatis cras. Sed
faucibus turpis in eu mi bibendum neque egestas congue.</p>
</div>
</div>
</section>
<!--<ColumnsThree>-->
<section class="vertical">
<hr>
<h2>4 Columns</h2>
<div class="wrap columns-four">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsFour>-->
<section class="vertical">
<hr>
<h2>6 Columns</h2>
<div class="wrap columns-six">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<hr>
</section>
<!--<ColumnsSix>-->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Amet luctus venenatis lectus
magna fringilla urna porttitor rhoncus dolor. Nisi quis eleifend quam
adipiscing vitae proin sagittis nisl. Ipsum dolor sit amet consectetur
adipiscing. Eu consequat ac felis donec et odio pellentesque diam. Volutpat
commodo sed egestas egestas fringilla phasellus faucibus scelerisque. Sem et
tortor consequat id porta nibh venenatis cras. Sed faucibus turpis in eu mi
bibendum neque egestas congue. Etiam non quam lacus suspendisse faucibus
interdum posuere lorem. Malesuada fames ac turpis egestas maecenas pharetra.
Lorem ipsum dolor sit amet consectetur. Ut enim blandit volutpat maecenas
volutpat blandit aliquam etiam erat. Id aliquet risus feugiat in ante metus.</p>
</body>
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true" class="s-jHz34e3aRDB7"></div>
</div>
<footer>
<p class="socials"><img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/fb/Facebook_icon_2013.svg" alt="facebook">
</p>
<p>This website was designed by Name</p>
</footer>
</body>
I need to create a website (two columns) where one column contains some text (vertical centered) and the other column contains a picture (sticky to bottom).
Both of them need to be responsive (so position: fixed is not an option for the image).
I tried to achieve this by using Bootstrap and the w3 responsive framework. But both of them seem unable to put a responsive image inside a column that is always stuck to the bottom.
Any tips on how I can achieve this layout while being responsive (Picture needs to resize etc)?
Here's a solution without using flex. It's completely responsive and can be scaled both horizontally and vertically.
body {
margin: 0;
padding: 0;
}
#container {
width: 100%;
height: 100vh;
overflow: hidden;
}
#column1 {
position: relative;
width: calc(50% - 4px);
height: calc(100% - 4px);
display: inline-block;
border: 2px solid black;
}
#column1 span {
display: block;
position: relative;
top: 50%;
transform: translateY(-50%);
padding: 10px;
}
#column2 {
position: relative;
top: -50%;
left: 50%;
width: calc(50% - 2px);
height: calc(50% - 4px);
display: inline-block;
border: 2px solid black;
border-left: none;
}
<div id="container">
<div id="column1">
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus interdum bibendum laoreet. Suspendisse eu mauris urna. Vestibulum vel blandit erat. Suspendisse egestas semper urna in convallis. Aliquam lobortis, leo nec pharetra semper, elit risus aliquet metus, non malesuada massa turpis tincidunt lectus. Fusce pellentesque metus ac lectus ultricies, et fermentum tellus fringilla.</span>
</div>
<footer id="column2"></footer>
</div>
Here's a quick example of how you can achieve it with flex.
/* Std */
body {
margin: 0;
width: 100%;
height: 100%;
}
/* Flex Classes */
.flex {
display: flex;
}
.flex--row {
flex-direction: row;
}
/* Column Classes */
.column {
position: relative;
min-height: 100vh;
}
.left-column {
flex: 0.7;
background: red;
}
.right-column {
flex: 0.3;
background: blue;
}
/* Picture */
#column-picture {
width: 100%;
height: inherit;
position: absolute;
bottom: 0;
}
<div class="flex flex--row">
<div class="column left-column">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur lacinia auctor tincidunt. Sed a turpis et eros iaculis convallis quis in nisl. Donec fringilla auctor eros ut ultrices. Donec laoreet dui urna, ut pharetra neque molestie et. Ut sagittis diam a lacus euismod dignissim. Sed vulputate dui erat, at hendrerit ante commodo et. Sed gravida ex et est bibendum pretium. Aliquam a convallis dui. Maecenas magna velit, ultrices eu massa sit amet, dictum accumsan tellus. Maecenas eget placerat magna. Nullam mollis lacus tempor lorem tempor tincidunt. Aliquam erat volutpat.
</div>
<div class="column right-column">
<img id="column-picture" alt="Lion" src="https://cbs.umn.edu/sites/cbs.umn.edu/files/public/african_lion_king-wide.jpg"/>
</div>
</div>
Tell me what you think of this. #Mech
https://codepen.io/rickydam/pen/zdrmWX
HTML
<div class="left">
<div class="innerleft">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus interdum bibendum laoreet. Suspendisse eu mauris urna. Vestibulum vel blandit erat. Suspendisse egestas semper urna in convallis. Aliquam lobortis, leo nec pharetra semper, elit risus aliquet metus, non malesuada massa turpis tincidunt lectus. Fusce pellentesque metus ac lectus ultricies, et fermentum tellus fringilla. Phasellus vel quam a sem elementum volutpat vel eget neque. Nam efficitur maximus risus, ac eleifend augue tempor rutrum. Fusce vehicula non lorem vitae blandit. Donec in scelerisque sem, quis congue velit.
</p>
</div>
</div><!--
--><div class="right">
<img src="http://www.uniwallpaper.com/static/images/Sunset-Village-Wallpaper_8I7ogbf.jpg">
</div>
CSS
.left {
width: 50%;
height: 100vh;
background-color: lightgray;
display: inline-block;
vertical-align: middle;
margin: auto;
}
.innerleft {
background-color: lightblue;
height: 100vh;
display: flex;
align-items: center;
}
.left p {
margin: 20px;
padding: 10px;
background-color: gray;
}
.right {
width: 50%;
height: 100vh;
background-color: slategray;
display: inline-block;
vertical-align: top;
position: relative;
}
.right img {
position: absolute;
bottom: 0;
max-width: 100%;
}
I have a button nested inside of 3 div's. The innermost div where the button is nested has a higher z-index of all the other div's. Still cannot click the button. What am I doing wrong?
* {
font-family: 'Raleway', sans-serif;
}
#main {
background: url('../image/bg2.jpg');
background-size: cover;
background-position: center;
height: 720px;
width: 2000px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
margin-top: -50px;
position: relative;
z-index: -50;
}
#content {
z-index: -25;
}
#content h3 {
font-size: 8rem;
color: #fff;
}
#button {
z-index: 99999!important;
}
.submain h3 {
display: inline;
padding: 25px;
}
<!--Main-->
<div id="main">
<div id="content">
<h3><i class="fa fa-cogs" aria-hidden="true"></i>DNS<sup>2</sup></a></h3>
<div id="button">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">Learn More</button>
</div>
<div class="collapse" id="collapseExample">
<div class="card card-block">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras molestie dignissim lacus id tempus. Donec malesuada efficitur ultricies. Vestibulum nec lobortis est, quis efficitur nunc. Proin finibus, massa in pharetra tempus, velit ante dictum massa,
eget porttitor arcu tellus eu orci. Quisque vitae ante lacus. In tortor purus, tristique nec felis ac, accumsan malesuada risus. Nam consectetur eget lacus vel condimentum. Donec in nisl volutpat, cursus arcu ac, mattis neque. Pellentesque metus
nisi, maximus eget metus sed, tincidunt euismod nisl. Quisque sed ipsum imperdiet, semper quam ac, varius leo.
</div>
</div>
</div>
</div>
please change that
z-index: -50;
to any positive value.
Then It will work
Here is 2 ways :
A)
body {
position: relative;
z-index: 0;
}
*{
font-family: 'Raleway', sans-serif;
}
body { position: relative; z-index: 0; }
#main {
background: url('../image/bg2.jpg');
background-size: cover;
background-position: center;
height: 720px;
width: 2000px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
margin-top: -50px;
position: relative;
z-index: -50;
}
#content{
z-index: -25;
}
#content h3{
font-size: 8rem;
color: #fff;
}
#button{
z-index: 999!important;
}
.submain h3{
display: inline;
padding: 25px;
}
<div id="main">
<div id="content">
<h3><i class="fa fa-cogs" aria-hidden="true"></i>DNS<sup>2</sup></a></h3>
<div id ="button">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">Learn More</button>
</div>
<div class="collapse" id="collapseExample">
<div class="card card-block">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras molestie dignissim lacus id tempus. Donec malesuada efficitur ultricies. Vestibulum nec lobortis est, quis efficitur nunc. Proin finibus, massa in pharetra tempus, velit ante dictum massa, eget porttitor arcu tellus eu orci. Quisque vitae ante lacus. In tortor purus, tristique nec felis ac, accumsan malesuada risus. Nam consectetur eget lacus vel condimentum. Donec in nisl volutpat, cursus arcu ac, mattis neque. Pellentesque metus nisi, maximus eget metus sed, tincidunt euismod nisl. Quisque sed ipsum imperdiet, semper quam ac, varius leo.
</div>
</div>
</div>
OR
B)
#main {
z-index:0;
//more code....
}
*{
font-family: 'Raleway', sans-serif;
}
#main {
background: url('../image/bg2.jpg');
background-size: cover;
background-position: center;
height: 720px;
width: 2000px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
margin-top: -50px;
position: relative;
z-index: 0;
}
#content{
z-index: -25;
}
#content h3{
font-size: 8rem;
color: #fff;
}
#button{
z-index: 999!important;
}
.submain h3{
display: inline;
padding: 25px;
}
<div id="main">
<div id="content">
<h3><i class="fa fa-cogs" aria-hidden="true"></i>DNS<sup>2</sup></a></h3>
<div id ="button">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">Learn More</button>
</div>
<div class="collapse" id="collapseExample">
<div class="card card-block">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras molestie dignissim lacus id tempus. Donec malesuada efficitur ultricies. Vestibulum nec lobortis est, quis efficitur nunc. Proin finibus, massa in pharetra tempus, velit ante dictum massa, eget porttitor arcu tellus eu orci. Quisque vitae ante lacus. In tortor purus, tristique nec felis ac, accumsan malesuada risus. Nam consectetur eget lacus vel condimentum. Donec in nisl volutpat, cursus arcu ac, mattis neque. Pellentesque metus nisi, maximus eget metus sed, tincidunt euismod nisl. Quisque sed ipsum imperdiet, semper quam ac, varius leo.
</div>
</div>
</div>
button is descendant of elements which are overlapped by body due to negative z-index of #main and #content. You can remove those negative z-indexes.
Demo:
* {
font-family: 'Raleway', sans-serif;
}
#main {
background: url('../image/bg2.jpg');
background-size: cover;
background-position: center;
height: 720px;
width: 2000px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
margin-top: -50px;
position: relative;
}
#content h3 {
font-size: 8rem;
color: #fff;
}
#button {
z-index: 99999!important;
}
.submain h3 {
display: inline;
padding: 25px;
}
<!--Main-->
<div id="main">
<div id="content">
<h3><i class="fa fa-cogs" aria-hidden="true"></i>DNS<sup>2</sup></a></h3>
<div id="button">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">Learn More</button>
</div>
<div class="collapse" id="collapseExample">
<div class="card card-block">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras molestie dignissim lacus id tempus. Donec malesuada efficitur ultricies. Vestibulum nec lobortis est, quis efficitur nunc. Proin finibus, massa in pharetra tempus, velit ante dictum massa,
eget porttitor arcu tellus eu orci. Quisque vitae ante lacus. In tortor purus, tristique nec felis ac, accumsan malesuada risus. Nam consectetur eget lacus vel condimentum. Donec in nisl volutpat, cursus arcu ac, mattis neque. Pellentesque metus
nisi, maximus eget metus sed, tincidunt euismod nisl. Quisque sed ipsum imperdiet, semper quam ac, varius leo.
</div>
</div>
</div>
</div>
My HTML structure shows a paragraph first and then a graphics at the bottom. Using CSS, I want to show the graphics at the top and paragraph at the bottom. The paragraph will be dynamic so the height is not fixed. I can't figure out how to solve the issue.
This my code:
.centerDiv {
width: 500px;
margin: 0 auto;
}
.topDiv {
display: inline-block;
width: 460px;
vertical-align: top;
}
.bottomDiv {
display: inline-block;
width: 460px;
height: 100px;
background-color: #ff0000;
vertical-align: top;
}
<div class="centerDiv">
<div>
<div class="topDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pharetra vel risus sed ultricies. Nulla vitae arcu dolor. Integer ut ex dapibus, malesuada urna maximus, laoreet tellus. Sed enim massa, elementum nec ultrices nec, pellentesque tristique
nibh. Donec dignissim facilisis dui, eu porttitor ante. Fusce posuere convallis augue, sed ultricies massa finibus vel.</div>
<div class="bottomDiv">Graphic</div>
</div>
</div>
If the Graphic has a fixed height you can achieve that using positioning
see the code bellow
.centerDiv {
width: 500px;
margin: 0 auto;
}
/* added code */
.centerDiv>div {
position: relative;
padding-top: 100px; /* padding value equals to bottomDiv's height*/
}
/*---------------*/
.topDiv {
display: inline-block;
width: 460px;
}
.bottomDiv {
display: inline-block;
width: 460px;
height: 100px;
background-color: #ff0000;
/* added code */
position: absolute;
top: 0;
left: 0;
/*---------*/
}
<div class="centerDiv">
<div>
<div class="topDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pharetra vel risus sed ultricies. Nulla vitae arcu dolor. Integer ut ex dapibus, malesuada urna maximus, laoreet tellus. Sed enim massa, elementum nec ultrices nec, pellentesque tristique
nibh. Donec dignissim facilisis dui, eu porttitor ante. Fusce posuere convallis augue, sed ultricies massa finibus vel.</div>
<div class="bottomDiv">Graphic</div>
</div>
</div>
Or you can use flex-direction: column-reverse; which reverses the order of the div children
But this may not be supported in some browsers
.centerDiv {
width: 500px;
margin: 0 auto;
}
.centerDiv>div {
display: flex;
flex-direction: column-reverse;
}
.topDiv {
display: inline-block;
width: 460px;
}
.bottomDiv {
display: inline-block;
width: 460px;
height: 100px;
background-color: #ff0000;
}
<div class="centerDiv">
<div>
<div class="topDiv">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut pharetra vel risus sed ultricies. Nulla vitae arcu dolor. Integer ut ex dapibus, malesuada urna maximus, laoreet tellus. Sed enim massa, elementum nec ultrices nec, pellentesque tristique
nibh. Donec dignissim facilisis dui, eu porttitor ante. Fusce posuere convallis augue, sed ultricies massa finibus vel.</div>
<div class="bottomDiv">Graphic</div>
</div>
</div>