I would like my gradient to pass on to the next div. Putting one div behind them with the gradient would probably work, but on my website the elements are not exactly next to eachother
.row {
clear: both;
}
.portrait {
width: 200px;
height: 200px;
background-color: red;
float: left;
}
.photo {
width: 200px;
height: 150px;
background-color: blue;
}
.gradient {
width: 200px;
height: 50px;
background-color: green;
}
<div class="row">
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
</div>
<div class="row">
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
<div class="portrait">
<div class="photo"></div>
<div class="gradient"></div>
</div>
</div>
Codepen:
https://codepen.io/chingwai/pen/poEGxBe
To explain my structure:
.portrait = is the container, this is dynamically created based on my database.
.photo = will be a profile photo
.gradient = This is where the gradient should come and continue to the other divs that contain .gradient As you can see .photo will be between the divs, so they are not postioned under eachother.
Give all the divs you want to be with the gradient BG:
background-image: linear-gradient(your choice);
background-repeat: no-repeat;
background-attachment: fixed;
.child{
height:120px;
width:120px;
border:solid 2px white;
background-image: linear-gradient(to right,pink,green);
background-repeat: no-repeat;
background-attachment: fixed;
}
.parent{
display:flex;
width: 250px;
}
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
EDIT
After your explanations on the comments and post edits. Do this:
.gradient{
width: 200px;
height: 50px;
background-image:linear-gradient(to right, blue, lightblue);
background-attachment:fixed;
}
Related
I made the changes as you described but when I check to see how it would look on the phone the blue box and the pink box are separated which I want to be together. I have attached a screenshot of how it looks and I want it to look similar to the desktop version.
I am not sure which entity might be causing this issue.
--EDIT--
Just to provide more clarity here is a screenshot of how the container_tag and container_box should look in the mobile screen (365px).
Should look like this
Is looking like this
.side_feedback{
background-color: pink;
padding: 10px;
height: 300px;
width: 180px;
border-radius: 10%;
margin-left: 17px;
}
.container_tag{
background-color: royalblue;
min-height: 200px;
max-width: 2rem;
border: 6px solid royalblue;
float: left;
}
.tag{
transform: rotate(-90deg);
position: relative;
top: 8rem;
}
.container_box{
background-color: pink;
min-height: 200px;
border-left: 6px solid white;
width: 95%;
position: relative;
float: left;
}
<div class="container-fluid">
<div class="row mb-4 g-5">
<div class="order-2 order-sm-1 col-lg-2 col-md-2 col-xs-10">
<div class="col-md">
<div class="side_feedback">
<p>Give us feedback!</p>
</div>
</div>
</div>
<div class="order-1 order-sm-2 col-10">
<div class="row row-cols-1 row-cols-sm-1 row-cols-md-1 row-cols-lg-1 row-cols-auto g-4">
<div class="col-12">
<div class="container_tag">
<h3 class="tag">TEXT</h3>
</div>
<div class="container_box">
</div>
</div>
<div class="col-12">
<div class="container_tag">
<h3 class="tag">TEXT</h3>
</div>
<div class="container_box">
</div>
</div>
<div class="col-12">
<div class="container_tag">
<h3 class="tag">TEXT</h3>
</div>
<div class="container_box">
</div>
</div>
</div>
</div>
</div>
If you’re referencing the large vertical white space below the two pink blocks, that’s there because you’re using position: relative on the pink container_box. position: relative positions the element normally (below your container_tag div) and then moves the element to the new position — the original space remains.
To get rid of the white space, add float: left to the styles for both of your containers.
.container_tag {
background-color: royalblue;
min-height: 180px;
width: 9%;
max-width: 3.2rem;
float: left;
position: relative;
}
.tag {
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%) rotate(-90deg)
}
.container_box {
background-color: pink;
min-height: 180px;
border-left: 6px solid white;
width: 91%;
position: relative;
float: left;
}
#media (min-width:768px) {
.container_box {
width: calc(100% - 3.2rem);
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-12 col-sm-10 px-0">
<div class="row gx-0">
<div class="col-12 mb-3">
<div class="container_tag">
<h3 class="tag">Text</h3>
</div>
<div class="container_box">
</div>
</div>
<div class="col-12 mb-3">
<div class="container_tag">
<h3 class="tag">Text</h3>
</div>
<div class="container_box">
</div>
</div>
</div>
</div>
</div>
</div>
One other note - you don't need to give the same column class for different breakpoints (col-lg-10 col-md-10 col-xs-10). Just use col-10 and that will apply to all of the following breakpoints. And BS-5 doesn't use xs - that was for Bootstrap 3.
I am trying to build a custom stepper with CSS and I am hitting a wall to center the label on top of each step.
I've build a quick and simplified version of my current implementation :
.wrapper {
display: flex;
}
.circle-wrapper {
flex: 1;
}
.circle-wrapper.active>.circle {
background-color: #3490DC;
transform: scaleX(1.2) scaleY(1.2)
}
.circle-wrapper.complete>.circle {
background-color: #38C172;
}
.circle {
width: 34px;
height: 34px;
background-color: #B8C2CC;
border-radius: 100%;
}
.label {
margin-bottom: 10px;
}
.wrapper> :last-child {
flex: none;
}
.line {
height: 4px;
width: 100%;
background-color: #1F9D55;
position: relative;
bottom: 19px;
}
<div class="wrapper">
<div class="circle-wrapper complete">
<div class="label">Label 1</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper active">
<div class="label">Label 2 with a longer name</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 3</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 4</div>
<div class="circle"></div>
</div>
</div>
You can see it here in this codepen
So far so good, but I want to center the label over the circle div without impacting the flex size between each circle and I can't manage to do it.
Any advice ?
You can use a left and a transform to move it into the centre:
.wrapper {
display: flex;
}
.circle-wrapper {
flex: 1;
position:relative;
}
.circle-wrapper.active>.circle {
background-color: #3490DC;
transform: scaleX(1.2) scaleY(1.2)
}
.circle-wrapper.complete>.circle {
background-color: #38C172;
}
.circle {
width: 34px;
height: 34px;
background-color: #B8C2CC;
border-radius: 100%;
}
.label {
position:relative;
left: 17px; /* move left 17px (half of circle width) */
margin-bottom: 10px;
transform: translateX(-50%); /* move it backwards 50% of itself */
text-align: center; /* align text in centre */
}
.wrapper> :last-child {
flex: none;
}
.line {
height: 4px;
width: 100%;
background-color: #1F9D55;
position: relative;
bottom: 19px;
}
<div class="wrapper">
<div class="circle-wrapper complete">
<div class="label">Label 1</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper active">
<div class="label">Label 2 with a longer name</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 3</div>
<div class="circle"></div>
<div class="line"></div>
</div>
<div class="circle-wrapper">
<div class="label">Label 4</div>
<div class="circle"></div>
</div>
</div>
If you want to center it always above the circle, I would use the following: put the label inside the circle and use the following CSS properties:
.circle {
position: relative;
width: 34px;
height: 34px;
background-color: #B8C2CC;
border-radius: 100%;
margin: 50px 100px; /* remove this */
}
.circle .label {
position: absolute;
left: 50%;
bottom: 100%;
transform: translateX(-50%);
white-space: nowrap;
}
<div class="circle">
<div class="label">Small One</div>
</div>
<div class="circle">
<div class="label">Very long label with long text</div>
</div>
The percentage values of left and bottom reference to the width of the parent element and the percentage value of transform: translate references to the element's size. This allows you to position it in the center of the parent with left: 50% and then moving it to the left again by the half of the width of the element itself.
This should be simple for you CSS gurus, but I really can't get this going. There are 4 boxes, example code:
<div id="wrapper">
<div id="firstPair">
<div style="width: 200px; float: left"></div>
<div style="width: 200px; float: left"></div>
</div>
<div id="secondPair">
<div style="width: 200px; float: left"></div>
<div style="width: 200px; float: left"></div>
</div>
</div>
When the window width is less than 800 only the rightmost div is moved, leaving them with 3 on top, and 1 on the next row.
I want the second two to go down the page as a pair. 2 on top, 2 on bottom, even if there is space for 3 next to eachother.
You need to set style for firstPair and secondPair elements
div[id$="Pair"] {
display: inline-block;
float: left;
}
<div id="wrapper">
<div id="firstPair">
<div style="width: 200px; float: left">s</div>
<div style="width: 200px; float: left">d</div>
</div>
<div id="secondPair">
<div style="width: 200px; float: left">f</div>
<div style="width: 200px; float: left">g</div>
</div>
</div>
And one more solution with shorten html, but some more use css
div[id$="Pair"] {
display: inline-block;
}
[id$="Pair"] > div {
width: 200px;
float: left;
background: lightgreen;
}
#wrapper {
text-align: center;
}
<div id="wrapper">
<div id="firstPair">
<div>s</div>
<div>d</div>
</div>
<div id="secondPair">
<div>f</div>
<div>g</div>
</div>
</div>
div[id$="Pair"] {
display: inline-block;
margin: 0;
}
[id$="Pair"] > div {
display: inline-block;
width: 200px;
margin: 2px 0;
background: lightgreen;
}
#wrapper {
text-align: center;
}
<div id="wrapper">
<div id="firstPair">
<div>1</div>
<div>2</div>
</div>
<div id="secondPair">
<div>3</div>
<div>4</div>
</div>
</div>
It is about BFC.
You might also float the containers :
#wrapper> div {
float:left;
}
<div id="wrapper">
<div id="firstPair">
<div style="width: 200px; float: left">1</div>
<div style="width: 200px; float: left">2</div>
</div>
<div id="secondPair">
<div style="width: 200px; float: left">3</div>
<div style="width: 200px; float: left">4</div>
</div>
</div>
Here's my solution. I tend to work in a fully responsive environment, so this will position them and be fully responsive on mobile. I also isolated the css, the inline colors are just for demo.
<style>
div#firstPair {
width: 100%;
max-width:400px;
float: left;
}
div#firstPair div{
width: 50%;
float: left;
}
div#secondPair {
width: 100%;
max-width: 400px;
float: left;
}
div#secondPair div{
width: 50%;
float: left;
}
</style>
<div id="wrapper">
<div id="firstPair">
<div style="background-color: blue;">first_1</div>
<div style="background-color: green;">first_2</div>
</div>
<div id="secondPair">
<div style="background-color: red;">second_1</div>
<div style="background-color: orange;">second_2</div>
</div>
<div style="clear: both;"></div>
</div>
I have the code:
html:
<div class=container1>
<div class=container2>
<div class="box">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</div>
<div class=container2>
<div class="box">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</div>
<div class=container2>
<div class="box">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</div>
<div class=container2>
<div class="box">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</div>
</div>
css:
.container1 {
background: yellow;
height: 200px;
position: relative !important;
width: 260px !important;
}
.container2 {
background: blue;
border: solid 1px;
float: left !important;
height: 180px;
/*position: relative; can't use, as it would limit icons inside this container*/
text-align: center;
width: 60px;
}
.container2:hover .box {
display: inline-block;
}
.box {
background: red;
border: solid 1px;
display: none;
height: 120px;
position:absolute;
text-align: center;
top: 20px;
width: 180px !important;
}
.box:first-child {
text-align: left;
}
.icon {
border: solid 1px;
background: white;
display: inline-block;
height: 50px;
width: 50px;
}
http://jsfiddle.net/388ygc74/10/
And on IE (any version) the text-align:center does not work.
The solution to make .box width:100% is not applicable, I need it to be a fixed defined width.
Any idea?
How about using left: 30px; (since you set the width to 60px) playing with z-index and position: relative ?
(Yes, you said no position:relative; but it's working :) )
See it here
I think that's what you looking for?
left:50%
margin-left:{-50% of elementh width}px;
Add specific selector to add the element that you want to align
:nth-child(4)
This is what I'm trying to achieve. The top box with a background image that spans the whole browser width, and 2 content boxes inside centered. I've done that no problem.
I then need want 2 more boxes underneath, again centered, but each half needs a different backgkround image that should meet in the middle and bleed of to their respective edge. I am using bootstrap becuase I want these to stack on smaller screens. I can't figure out how this is possible. the black border represents the container. I can wrap the top bit in its own container which is fine, but I can't work out how to get the bottom bit to work, and I don't really want to use absolute positioning because it'll be a nightmare to get the responsive element to work.
Here is what I have so far
HTML:
<div class="fluid-full">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-6 left-half">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6 right-half">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
CSS:
.example{
height: 200px;
border: 1px;
background-color: rgba(0,0,0,0.8);
padding: 30px;
border: 1px solid white;
color: white;
}
.fluid-full{
padding: 40px 0;
background-image: url(http://lorempixel.com/1920/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.left-half{
border-left: 25% solid transparent;
background-image: url(http://lorempixel.com/g/1000/400);
background-position: right;
background-repeat: no-repeat;
background-size: cover;
}
Checkout this Bootply
I need the top and bottom boxes to line up.
Any help appreciated.
I took you Bootply example and modified bottom bit to this:
<div class="col-md-6 fluid-half">
<div class="example col-md-6 pull-right">
<h1 class="text-center">LEFT</h1>
</div>
</div>
<div class="col-md-6 fluid-half">
<div class="example col-md-6 pull-left">
<h1 class="text-center">RIGHT</h1>
</div>
</div>
Here's the Bootply modification
Is this something you're trying to achieve?
OK, I've done it. Had to use some media queries.
HTML:
<div class="fluid-full">
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
<div class="col-md-6">
<div class="example">
<h1>Title</h1>
<p>This is a paragraph</p>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid about-us">
<div class="row">
<div class="col-md-6">
<div class="sec-title text-center work-with-us">
<h2>Work With Us</h2>
</div>
</div>
<div class="col-md-6">
<div class="sec-title text-center what-we-do">
<h2>What We Do</h2>
</div>
</div>
</div>
</div>
CSS
.example{
height: 200px;
border: 1px;
background-color: rgba(0,0,0,0.8);
padding: 30px;
border: 1px solid white;
color: white;
}
.fluid-full{
padding: 40px 0;
background-image: url(http://lorempixel.com/1920/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.about-us .col-md-6 {
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url(http://lorempixel.com/g/1000/400);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding: 70px 0;
}
.about-us .col-md-6 .sec-title {
margin-bottom: 0;
margin: 0 15px;
background-color: rgba(0, 0, 0, 0.8);
border: 1px solid white;
}
.about-us .col-md-6 .sec-title h2 {
color: #FFFFFF;
}
.about-us .col-md-6 .sec-title h2::after {
width: 70px;
}
#media (min-width: 768px) {
.about-us .col-md-6 .sec-title {
width: 720px;
margin: 20px auto;
}
}
#media (min-width: 992px) {
.about-us .col-md-6 .sec-title {
width: 455px;
margin: 0 15px;
}
}
#media (min-width: 1200px) {
.about-us .col-md-6 .sec-title {
width: 555px;
}
}
#media (min-width: 992px) {
.about-us .col-md-6 .work-with-us {
float: right;
}
}
Here is the bootply
Hopefully this might be useful to someone else too.