I have to components one above the other. I would like to stretch the bg image from the lower one to the upper one. I set the background of the upper one as transparent but I cannot figure out what to do to stretch the image above the component in the second one. I've got
display: block;
background-image: url(${background});
background-position: bottom;
background-repeat: no-repeat;
background-size: 100% -50%;
but the size property is invalid and any positive value doesn't seen to do what I would like it to do. Could you help?
It's hard to know exactly what you are going for without a proper link, but I think you could achieve this by having the second component with a negative margin-top, and equivalent padding-top.
HTML:
<div class="comp-a">
I am the first component
</div>
<div class="comp-b">
I am the second. I control the background!
</div>
CSS:
* {
box-sizing:border-box;
}
.comp-a {
height: 100px;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
.comp-b {
height: 200px;
padding-top: 100px;
margin-top: -100px;
background: red;
display: flex;
color: white;
align-items: center;
justify-content: center;
}
http://jsfiddle.net/hrsapyqv/
Related
I have a question feel troubled CSS settings need everyone's help -
requirements are as follows:
a picture of a button, the picture has a text
design draft marked above the button is the size of the picture must be 200px width of the text must be 26px
text In the middle of the picture, the upper and lower spacing between the picture and the picture is 8px. The example shown in the figure below needs to be achieved.
But I can’t do it anyway. I hope you can provide some solutions to let me know how to deal with this kind of demand. Thank you Everyone
.btn{
display: inline-block;
width: 200px;
height: 100px;
background-image: url('https://upload.cc/i1/2021/09/12/IX7D1d.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-size: 140%;
}
.txt{
font-size: 26px;
text-align: center;
padding: 16px;
}
<a class="btn" href="javascript:;">
<p class="txt">send</p>
</a>
Your background is misleading you to believe that it matches the button position and size (if you add a border to the .btn style you will see what I mean)
So if your background is yellow and need a blackborder better to style it, is faster than loading a button image and scale it.
.btn{
position: relative ;
display: inline-block;
width: 200px;
height: 42px; /* 8 + 26 +8*/
border: 5px solid black ;
background-color: yellow ;
border-radius: 25px ;
/* to center the text vertically using flex*/
display: flex;
justify-content: center;
align-content: center;
flex-direction: column;
}
.txt{
font-size: 26px;
text-align: center;
}
<a class="btn" href="javascript:;">
<p class="txt">send</p>
</a>
first make sure no margin is defined by default by adding margin: 0px;
2ndly, Add a line-height property to it using line-height: 1.5;
There are several other ways, but this should be the fastest
.btn{
display: inline-block;
width: 200px;
height: 100px;
background-image: url('https://upload.cc/i1/2021/09/12/IX7D1d.png');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-size: 140%;
}
.txt {
font-size: 26px;
text-align: center;
padding: 16px;
margin: 0px;
line-height: 1.5;
}
<a class="btn" href="javascript:;">
<p class="txt">send</p>
</a>
I'm working on a website that has sections with text on one side and a background image on the other. In one section everything is working fine. When I resize my browser the background image is responsive and scales down. But in the next section, the background image is not responsive, the image actually gets bigger when I resize my browser and I have no idea why. (I've only been learning how to code for about a month so I'm hoping the answer is glaringly obvious)
Here's the css from the section that works:
#welcome {
margin-top: 34px;
padding-top: 0px;
padding-bottom: 0px;
height: 120vh;
background-color: #dae7e9;
}
#welcome .box1 {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex-wrap: wrap;
width: 55%;
height: 120vh;
}
#welcome .box2 {
width: 45%;
overflow: hidden;
background-image: url("https://i.ibb.co/c6txf7Y/Gabriel-Venneri1-3.jpg");
background-size: cover;
background-position: center;
border: 1px solid black;
}
And here's the css from the section that doesn't:
#about {
background-color: #5d5c61;
}
#about h1 {
color: #123c69;
margin-bottom: 0;
}
#about .box1 {
width: 40%;
background-image: url("https://i.ibb.co/k6mNw42/IMG-6333-2.jpg");
background-size: cover;
background-position: center;
border: 1px solid black;
}
#about .box2 {
width: 60%;
}
The HTML:
<section id="about">
<div class="container-1">
<div class="box1"></div>
<div class="box2">
<h1>About</h1>
<p>Text</p>
</div>
</div>
</section>
I've been trying to find a solution for a week and a half so any help would be greatly appreciated
Here is a link to the site, the about section image is the issue: https://codepen.io/gvenn/full/XWNzeqW
How can a scale this perfect circle svg to the width of the div and keep in the center - and no repeat it. It is placed as a background image:
<style>
.play_full{
background: url('../_svg/_ionicons_svg_md-play-circle.svg');
position:absolute;
background-size: 100% 100%;
background-repeat: no-repeat;
}
This is what I am getting now?
How can I center the svg V and H?
you can use flexbox position to center, I changed this:
use Flexbox to centering elements in .cotainer
added width and height on .play_full
.container {
border : 1px solid red;
display: inline-flex;
justify-content: center;
align-items: center;
}
.play-full {
display: inline-block;
width: 50px;
height: 50px;
background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHg9IjBweCIgeT0iMHB4IgogICAgIHdpZHRoPSI1MCIgaGVpZ2h0PSI1MCIKICAgICB2aWV3Qm94PSIwIDAgMzIgMzIiCiAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDsiPjxnIGlkPSJzdXJmYWNlMSI+PHBhdGggc3R5bGU9IiAiIGQ9Ik0gMTYgNiBDIDEyLjIzNDM3NSA2IDguOTA2MjUgNi4zOTA2MjUgNi44NzUgNi42ODc1IEMgNS4xOTUzMTMgNi45MzM1OTQgMy44Mzk4NDQgOC4xOTkyMTkgMy41MzEyNSA5Ljg3NSBDIDMuMjY5NTMxIDExLjMwMDc4MSAzIDEzLjM4NjcxOSAzIDE2IEMgMyAxOC42MTMyODEgMy4yNjk1MzEgMjAuNjk5MjE5IDMuNTMxMjUgMjIuMTI1IEMgMy44Mzk4NDQgMjMuODAwNzgxIDUuMTk1MzEzIDI1LjA3MDMxMyA2Ljg3NSAyNS4zMTI1IEMgOC45MTQwNjMgMjUuNjA5Mzc1IDEyLjI1MzkwNiAyNiAxNiAyNiBDIDE5Ljc0NjA5NCAyNiAyMy4wODU5MzggMjUuNjA5Mzc1IDI1LjEyNSAyNS4zMTI1IEMgMjYuODA0Njg4IDI1LjA3MDMxMyAyOC4xNjAxNTYgMjMuODAwNzgxIDI4LjQ2ODc1IDIyLjEyNSBDIDI4LjczMDQ2OSAyMC42OTUzMTMgMjkgMTguNjA1NDY5IDI5IDE2IEMgMjkgMTMuMzk0NTMxIDI4LjczNDM3NSAxMS4zMDQ2ODggMjguNDY4NzUgOS44NzUgQyAyOC4xNjAxNTYgOC4xOTkyMTkgMjYuODA0Njg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eat;
background-size: 100%;
}
<div class="container">
<div class="play-full"></div>
</div>
I have an interesting issue where the background image of an element is not showing up the same between the two browsers. Chrome 65, FF 59.
I'm using the technique to show a ratio of the background image using padding-top percentage, where height is zero.
A codepen is also included.
https://codepen.io/anon/pen/OvGeeJ
A quick thing to note. The content div was only for visually knowing when the flex container ended.
It seems like the way % is calculated is different.
body{
border: 0;
padding: 0;
margin: 0;
}
.flex{
display: flex;
position: relative;
width: 100%;
flex-direction: row;
flex-wrap: wrap;
height: 300vh;
background: black;
align-items: flex-start;
}
.stickybg{
height:0;
width: 100%;
background-image: url(https://i.imgur.com/8bKkEfR.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
padding-top: 19%;
}
.content{
height: 100vh;
background: #111;
}
<div class="flex">
<div class="stickybg"></div>
</div>
<div class="content"></div>
As dholbert said in a comment, it appears FF beta 60 has the issue fixed.
A workaround is to use VH or VW units which in my case would simulate the same thing.
Replacing
padding-top: 19%;
for
padding-top: 19vw;
I'm having some trouble with aligning certain elements using Flexbox. You can see the JSfiddle here,
I used flex because the image from the Steve Jobs movie is higher then the image of Legend, so when I place the images in the divs there would be a gap.I want them to be the same size. So I used Flex to create divs with the same size and then use the image as the background to fill it up. Which works fine.
But the problem is that I want to show the release date above the images and for some reason Flex decides to put the span element with the date and the image element with the image next to each other.
If I remove the display: flex from the .movie_container it places the release date above the image but then the images have different sizes.
So I'm wondering if there's a way to keep the Flex aspect but also have the span element above the image instead of next to it.
div#got-gridbox {
padding: 20px;
background: #F1F1F1;
display: flex;
flex-flow: row wrap
}
.movie_container {
width: 150px;
background: #ddd;
padding: 10px;
display: flex
}
.movie_container img {
width: 100%;
opacity: 0;
}
span {} .poster_1 {
background: url('http://image.tmdb.org/t/p/w500//7SUaf2UgoY0ZRGbQtRlfDkLDBCb.jpg') no-repeat center center;
background-size: cover;
background-color: green;
display: inline-block;
}
.poster_2 {
background: url('http://image.tmdb.org/t/p/w500//3tD0r8F6b7vygxZt3iRvf2ELwAO.jpg') no-repeat center center;
background-size: cover;
background-color: green;
display: inline-block;
}
The default flex-direction value is row. Thus the date is placed in line with the image. Set the flex-direction to column so that the two elements occupy the full width of the parent and the date is place above the poster.
For setting the images with same height, you need to assign flex: 1 to the poster elements.
flex: 1 is equivalent to flex: 1 1 0[flex-grow flex-shrink flex-basis] which tells the item to grow and shrink with the parent container and absorb the remaining space.
Updated JSfiddle
div#got-gridbox {
padding: 20px;
background: #F1F1F1;
display: flex;
flex-flow: row wrap
}
.movie_container {
width: 150px;
background: #ddd;
padding: 10px;
display: flex;
flex-direction: column;
}
.movie_container img {
width: 100%;
opacity: 0;
}
span {} .poster_1 {
background: url('http://image.tmdb.org/t/p/w500//7SUaf2UgoY0ZRGbQtRlfDkLDBCb.jpg') no-repeat center center;
background-size: cover;
background-color: green;
display: inline-block;
}
.poster_2 {
background: url('http://image.tmdb.org/t/p/w500//3tD0r8F6b7vygxZt3iRvf2ELwAO.jpg') no-repeat center center;
background-size: cover;
background-color: green;
display: inline-block;
flex: 1;
}
<div id="got-gridbox">
<div class="movie_container">
<span>2015-08-01</span>
<div class="poster_1">
<img src="http://image.tmdb.org/t/p/w500//7SUaf2UgoY0ZRGbQtRlfDkLDBCb.jpg"></img>
</div>
</div>
<div class="movie_container">
<span>2015-08-01</span>
<div class="poster_2">
<img src="http://image.tmdb.org/t/p/w500//3tD0r8F6b7vygxZt3iRvf2ELwAO.jpg" />
</div>
</div>
</div>