I had to change the logo's resolution to at least be able to see the logo (format was 3400x1716) to 99x50 for overlapping the picture and added a text with the logo.
I set the pictures that are supposed to get superimposed to 300 height and 100% width to fill out the rest of the page, but that is shown in my code.
The end product will be that I will be able to hover over the picture/logo and the text appears.
My problem is that I can't see the logo nor the text that should superimpose the picture.
In total for 12 pictures with 12 different text's but the same logo.
.portfolio-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.portfolio-item-wrapper {
position: relative;
}
.portfolio-img-background {
height: 300px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100%;
padding-right: 100%;
}
<div class="content-wrapper">
<div class="portfolio-items-wrapper">
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background- image:url(images/portfolio1.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/logos/thought.png">
</div>
<div class="subtitle">
Using a different approach than the NORM!
</div>
</div>
</div>
<div class="portfolio-item-wrapper">
<div class="portfolio-img-background" style="background- image:url(images/portfolio2.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/logos/thought.png">
</div>
<div class="subtitle">
Everything starts with a THOUGHT!
</div>
</div>
</div>
</div>
</div>
You can use the approach you started using, that is setting a background-image to your parent container element, and then you can position the text and logo elements using flexbox.
img {
width:50px;height:50px;
}
div {
background-image:url('https://static-cse.canva.com/image/1578/RoyalBlue_Set1_23.5dfc6872.png');
background-size:contain;
background-repeat:no-repeat;
background-position:center center;
width:300px;height:300px;
display:flex;align-items:center;flex-direction:column;justify-content:center;
color:#FFF;font-size:36px;
}
<div>
<img src="https://assets.codepen.io/5200861/internal/avatars/users/default.png">
<h3>some text here</h3>
</div>
Related
I have 2 divs. In the div on the right has a text. This text has to to be allways in the middle of the screen. Also the text is never allowed to leave the box. I want it responsive. So it works on pc / tablet / phone, etc.
Here my jsfiddle:
https://jsfiddle.net/ourn15f8/106/
.screen-1 {
width: 500px;
display: flex;
}
.div-1 {
background-color: green;
width: 100px;
}
.div-2 {
background-color: red;
width: 400px;
text-align: center;
}
Total Width = Screen Width
<br><br>
Situation:
<div class="screen-1">
<div class="div-1">logo</div>
<div class="div-2">text</div>
</div>
Wanted:
<div class="screen-1">
<div class="div-1" style="position: absolute">logo</div>
<div class="div-2" style="width: 500px">text</div>
</div>
<div class="screen-1" style="width: 400px">
<div class="div-1" style="position: absolute">logo</div>
<div class="div-2" style="width: 300px">text</div>
</div>
<div class="screen-1" style="width: 300px">
<div class="div-1" style="position: absolute">logo</div>
<div class="div-2" style="width: 200px">text</div>
</div>
Text in the middle of screen
<br><br>
Also when screen to small, I want this:
<div class="screen-1" style="width: 150px">
<div class="div-1">logo</div>
<div class="div-2" style="width: 50px">text</div>
</div>
"text" is never allowed to leave the div
<br><br>
Info:<br>
I dont want to use position absolute. The divs have to by dynamic so it works on pc and phone.
You can use grid to make 3 boxes, each 1fr so they're evenly spaced then put your logo in the left one and the content in the middle one. You can then use flexbox to put the text div in to the middle of the centre div which is essentially the centre of the screen.
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
background-color: red;
}
.logo {
background-color: green;
width: 200px;
margin-left: 0;
margin-right: auto;
}
.textcontainer {
display: flex;
justify-content: center;
}
.container>div>div {
padding: 0.5rem 0.25rem;
}
<div class='container'>
<div class='logocontainer'>
<div class='logo'>
Logo
</div>
</div>
<div class='textcontainer'>
<div>
<!-- Put your text here -->
Text
</div>
</div>
<div></div>
<!-- this is a dummy container to push the text container to the middle of the screen -->
</div>
I have a page I'm trying fill some content with and then the remainder of the page fill with a background color. I've kind of been able to achieve this using min-height: 100vh but the problem is now my page scroll get's extended significantly. Is it possible just to color the visible space on the screen without increasing scrollable area on the page.
Here's a simple example with a jsfiddle:
If you remove the min-height: 100vh from .footer notice that the colored square gets much smaller and now the scroll area isn't very large either. How do I only fill that area that's visible when not using the min-height style.
.body {
margin-left: 50px;
}
.footer {
background-color: grey;
min-height: 100vh;
z-index: -100;
margin-top: -150px;
}
img {
z-index: 100;
margin-left: 200px;
}
h1 {
text-align: center;
}
<div class="body">
<div class="row justify-content-center text-centerr">
<h1>
This is my page heading
</h1>
</div>
<div class="row justify-content-center text-center">
<p>
This is some information about this page.
</p>
</div>
<div class="row justify-content-center text-centerr">
<div class="justify-content-center">
<img src="https://cdn.vox-cdn.com/thumbor/RkBHz5tPuCNQOG0a6FooNwiqQyw=/0x0:939x704/1820x1213/filters:focal(0x0:939x704):format(webp)/cdn.vox-cdn.com/uploads/chorus_image/image/49610677/homersimpson.0.0.jpg"
width="300px"
height="300px"
</div>
</div>
<div class="footer">
<br />
</div>
</div>
This is what I came up with, using flexbox and flex-grow: 1 to force the element to grow and take up the remaining space and flex-shrink: 0 to prevent the img and other elements from shrinking.
I had to add a new class to he footer's parent element, to add the flexbox class to it. note the footer-parent class.
<div class="body">
<div class="row justify-content-center text-center">
<h1>
This is my page heading
</h1>
</div>
<div class="row justify-content-center text-center">
<p>
This is some information about this page.
</p>
</div>
<div class="row footer-parent justify-content-center text-center">
<div class="justify-content-center">
<img src="https://cdn.vox-cdn.com/thumbor/RkBHz5tPuCNQOG0a6FooNwiqQyw=/0x0:939x704/1820x1213/filters:focal(0x0:939x704):format(webp)/cdn.vox-cdn.com/uploads/chorus_image/image/49610677/homersimpson.0.0.jpg" width="300px" height="300px" />
</div>
<div class="footer">
<br />
</div>
</div>
</div>
Here's the CSS
body {
margin: 0;
}
.body {
display: flex;
flex-flow: column nowrap;
margin-left: 50px;
height: 100%;
min-height: 100vh;
}
.footer {
background-color: grey;
flex-grow: 1;
z-index: -100;
margin-top: -150px;
}
.footer-parent {
display: flex;
flex-grow: 1;
flex-flow: column nowrap;
}
img {
z-index: 100;
flex-shrink: 0;
margin-left: 200px;
}
h1 {
flex-shrink: 0;
text-align: center;
}
This question already has answers here:
Centering in CSS Grid
(9 answers)
Closed 1 year ago.
I am making my first html/css website and I have the start of a skeleton with placeholder images and icons. I want the icons with text, to each be centered within their respective column. I'm using a CSS grid to set up the columns.
.content-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.content-item-wrapper {
position: relative;
}
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
}
<div class="master-content-wrapper">
<div class="content-items-wrapper">
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image: URL(images/blue-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/wrench-placeholder.png">
</div>
<div class="subtitle">
Services
</div>
</div>
</div>
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image:URL(images/white-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/computer-placeholder.png">
</div>
<div class="subtitle">
Technicians
</div>
</div>
</div>
<div class="content-item-wrapper">
<div class="content-img-background" style="background-image:URL(images/red-placeholder.jpg)"></div>
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="images/paper-placeholder.png">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
I tried different paddings and tweaking some other things but it never gets exactly in the center of the three vertical columns. The icon with text I'm referring to is the ".img-text-wrapper" div.
If we put some background color and border to some of the elements we can more clearly see what is going on:
The absolutely positioned elements' contents are centered within themselves but not within their parent elements. To achieve that we need to display the parents as flex with justification and alignment centered. Also, the div giving the background to each of these elements does not seem to have any particular meaning other than providing a background image so that is removed and the background is put on the parent in this snippet which gives this result (on wide screens see note):
.content-items-wrapper {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
.content-item-wrapper {
position: relative;
border-style: solid;
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: pink;
display: flex;
justify-content: center;
align-items: center;
}
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: pink;
}
.img-text-wrapper {
position: absolute;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
padding-left: 100px;
padding-right: 100px;
background-color: lime;
}
<div class="master-content-wrapper">
<div class="content-items-wrapper">
<div class="content-item-wrapper" style="background-image: URL(images/blue-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Services
</div>
</div>
</div>
<div class="content-item-wrapper" style="background-image:URL(images/white-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Technicians
</div>
</div>
</div>
<div class="content-item-wrapper" style="background-image:URL(images/red-placeholder.jpg)">
<div class="img-text-wrapper">
<div class="logo-wrapper">
<img src="https://i.stack.imgur.com/Iynpe.jpg">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
(Note that on smaller displays the cells shrink to fit - this needs correction for full responsiveness - the square can't be given a fixed px dimension)
Sorry i removed a lot of the css as this is not necessary for the answer.
.content-img-background {
height: 350px;
width: 100%;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.column {
float: left;
width: 30%;
}
div {
text-align: center;
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="column">
<div style= "background-image: URL(images/blue-placeholder.jpg)">
<img src="images/wrench-placeholder.png">
</div>
<div class="subtitle">
Services
</div>
</div>
<div class="column">
<div style= "background-image:URL(images/white-placeholder.jpg)">
<img src="images/computer-placeholder.png">
</div>
<div class="subtitle">
Technicians
</div>
</div>
<div class="column">
<div style= "background-image:URL(images/red-placeholder.jpg)">
<img src="images/paper-placeholder.png">
</div>
<div class="subtitle">
Reviews
</div>
</div>
</div>
</div>
</body>
</html>
I try to develop website for my portfolio. I want to do something like that :
But I've some problem with the 3 icons for Twitter/Instagram and Deviantart. To put the icons like that, I use the flexbox in html. Currently, I've that :
#conteneur {
display: flex;
justify-content: space-between;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
Test with CodePen here : https://codepen.io/lucbenedet/pen/yLbPMgK
But as you can see, the pictures are too large and when I try to put the pictures to a size of 35px like that :
#conteneur
{
display: flex;
justify-content: space-between;
width: 35px;
}
or
.element1
{
width: 35px;
}
The resize doesn't works...
Someone to show how to do that ?
You can update your CSS with following code.
#conteneur {
display: flex;
justify-content: space-between;
width: 150px;
padding: 10px;
}
#conteneur div img {
width: 35px;
height: 35px;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
You can have some space between icons when you maximize the width of the container
you can reset width on the flex-container to max-content (3 icones shouldnot overflow) and use gap to set a distance in between them.
You could use em for the gap and icon's width to have a coherent render.
Possible example:
#conteneur {
display: flex;
width: max-content;
align-items: center;
margin: auto;
gap: 1.6em;
}
#conteneur div img {
width: 3em;
}
<div id="conteneur">
<div class="element1">
<img src="https://zupimages.net/up/21/29/vbxh.png">
</div>
<div class="element2">
<img src="https://zupimages.net/up/19/51/4gl0.png">
</div>
<div class="element3">
<img src="https://zupimages.net/up/21/29/dbtc.png">
</div>
</div>
possible example from your codepen https://codepen.io/gc-nomade/pen/qBmVjBV
I am trying to implement a Flexbox container for an image gallery. I would like this gallery to not require the use of a scrollbar and instead adjust the size of the images to fit the screen.
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
html, body {
height: 100%;
margin: 0;
}
#flex-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
background-color: blue;
height: 90%;
}
.img-wrap {
width: 25%;
height: 25%;
display: flex;
align-items: center;
justify-content: center;
}
.img-wrap img {
max-width: 100%;
max-height: 100%;
height: auto;
width: auto;
}
</style>
</head>
<body>
<div class="text-wrap">This should always be visible</div>
<div id="flex-container">
<div class="img-wrap"><img src="https://picsum.photos/200"></div>
<div class="img-wrap"><img src="https://picsum.photos/300/200"></div>
<div class="img-wrap"><img src="https://picsum.photos/400/800"></div>
<div class="img-wrap"><img src="https://picsum.photos/500/250"></div>
<div class="img-wrap"><img src="https://picsum.photos/450/505"></div>
<div class="img-wrap"><img src="https://picsum.photos/350/520"></div>
<div class="img-wrap"><img src="https://picsum.photos/250/300"></div>
<div class="img-wrap"><img src="https://picsum.photos/550/200"></div>
<div class="img-wrap"><img src="https://picsum.photos/200"></div>
<div class="img-wrap"><img src="https://picsum.photos/300/200"></div>
<div class="img-wrap"><img src="https://picsum.photos/400/800"></div>
<div class="img-wrap"><img src="https://picsum.photos/500/250"></div>
<div class="img-wrap"><img src="https://picsum.photos/450/505"></div>
<div class="img-wrap"><img src="https://picsum.photos/350/520"></div>
<div class="img-wrap"><img src="https://picsum.photos/250/300"></div>
<div class="img-wrap"><img src="https://picsum.photos/550/200"></div>
</div>
<div class="text-wrap">This should always be visible, even without using a scrollbar</div>
</body>
</html>
The problem is that when the window is small enough (vertically), the bottom text gets cut off and the user needs to scroll to see it.
I would like to have both sections of text always visible. The images should always get smaller until both sections of text are touching, at which point a scrollbar is acceptable.
Add position fixed on text-wrap class, it will fix the position of top and bottom heading.
.text-wrap {
postion:fixed;
}