This question already has answers here:
Text in Border CSS HTML
(10 answers)
CSS technique for a horizontal line with words in the middle
(34 answers)
Closed 2 years ago.
So I am working on a front end website with React/HTML/CSS to mimic a wireframe design and am curious about achieving the desired effect below where the border breaks just behind the image placement over it. Perhaps there is a trick I can do with the image to give it a similar texture and color as the background image, but I would prefer to use code to achieve the effect. Any ideas on how to achieve this? Is this possible?
Attempted CodePen Link
Relevant CSS:
.middle-logo {
width: 100%;
height: auto;
max-width: 125px;
}
.negative-top-margin {
margin: -50px 0px 0px 0px;
}
.bg-image-container {
position: relative;
text-align: center;
}
.bg-image {
/* The image used */
background:
/* top, transparent red, faked with gradient */
linear-gradient(
rgba(68, 105, 126, 0.788),
rgba(68, 105, 126, 0.788)
),
/* bottom, image */
url("https://firebasestorage.googleapis.com/v0/b/theblairfamilyfoundation-org.appspot.com/o/nature.png?alt=media&token=f2dc74ac-bb80-4847-9345-f47346f736de");
/* Full height */
height: 700px;
/* Center and scale the image nicely */
background-position: 50% 35%;
background-repeat: no-repeat;
background-size: cover;
}
/* Position text in the middle of the page/image */
.bg-content {
color: white;
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
text-align: center;
width: 75%;
}
.bg-content:before {
content: " ";
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 100%;
border: 1px solid white;
}
.bg-h1 {
font-size: 2.5em;
margin: 0;
}
.bg-p {
font-size: 1.2em;
}
.bg-text-box {
padding: 50px 0 50px 0;
}
Design to achieve:
This is one way to do it. Remove the top border and use :after and :before elements for those top lines.
BTW Your image is not completely symmetrical, it should have the same empty space in both sides for it to look perfect.
.middle-logo {
width: 100%;
height: auto;
max-width: 125px;
}
.negative-top-margin {
margin: -50px 0px 0px 0px;
}
.bg-image-container {
position: relative;
text-align: center;
}
.bg-image {
/* The image used */
background:
/* top, transparent red, faked with gradient */
linear-gradient(
rgba(68, 105, 126, 0.788),
rgba(68, 105, 126, 0.788)
),
/* bottom, image */
url("https://firebasestorage.googleapis.com/v0/b/theblairfamilyfoundation-org.appspot.com/o/nature.png?alt=media&token=f2dc74ac-bb80-4847-9345-f47346f736de");
/* Full height */
height: 700px;
/* Center and scale the image nicely */
background-position: 50% 35%;
background-repeat: no-repeat;
background-size: cover;
}
/* Position text in the middle of the page/image */
.bg-content {
color: white;
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
text-align: center;
width: 75%;
border: 1px solid white;
border-top: 0;
}
.bg-content:before {
content: "";
position: absolute;
top: 0;
right: 0;
left: calc(50% + 125px/2);
height: 1px;
background: white;
}
.bg-content:after {
content: "";
position: absolute;
top: 0;
left: 0;
right: calc(50% + 125px/2);
height: 1px;
background: white;
}
.bg-h1 {
font-size: 2.5em;
margin: 0;
}
.bg-p {
font-size: 1.2em;
}
.bg-text-box {
padding: 50px 0 50px 0;
}
<div class="bg-image-container">
<div class="bg-image"></div>
<div class="bg-content">
<img
class="responsive middle-logo negative-top-margin"
alt="creek"
src="https://firebasestorage.googleapis.com/v0/b/theblairfamilyfoundation-org.appspot.com/o/Asset%202.png?alt=media&token=df5a94b2-2b06-4fd8-947e-13dd0d5abbf9" />
<br/>
<div class="bg-text-box">
<h1 class="bg-h1">Committed to Montgomery County</h1>
<div class="m-width center">
<p class="bg-p">Working with partners and communities across the county to address long-term quality of life challenges and opportunities.</p>
</div>
</div>
</div>
</div>
Related
This question already has answers here:
Circle with two borders
(4 answers)
Closed 7 months ago.
I want to make a 1€ coin with CSS but I have the problem that I can't give it it's characteristic shape consisting of two circles. I don't want to use multiple divs for making the two circles because I want to have it as a Button. Is there any way to put 2 different shapes in one button tag or are you forced to use divs?
Here is my failed attempt at trying to do so:
.btnCircle1 {
height: 50px;
width: 50px;
border-radius: 50%;
background: red;
z-index: 100;
}
.btnCircle2 {
height: 100px;
width: 100px;
border-radius: 50%;
background: blue;
z-index: 1;
}
<button type="button" class="btnCircle1 btnCircle2"></button>
.btnCircle {
/* here just change one value, to change the other automatically */
/* for example you can use a responsive unit (that change often) like `vw` and the other element will automatically changed automatically */
--bigCirle-Height: 100px;
height: var(--bigCirle-Height);
width: var(--bigCirle-Height);
/* is always a perfect circle */
border-radius: var(--bigCirle-Height);
border: none; /* Remove default borders */
/* add this to make the ::before works */
position: relative;
}
.btnCircle::before {
/* change this value 1 means bigger, the smaller is the number (for example 0.7) the yellow circle is smaller */
/* using css variables and calculations the money it will be always responsive to the parent height */
--smallCirle-Height: calc(var(--bigCirle-Height) * 0.7);
content: '1€';
height: var(--smallCirle-Height);
width: var(--smallCirle-Height);
border-radius: var(--smallCirle-Height);
background: yellow;
/* this two lines will center the circle */
/* inset is like writing top: 50%, left: 50% */
inset: 50%;
transform: translate(-50%, -50%);
/* center the text inside circle */
display: grid;
place-content: center;
/* positioning absolutely */
position: absolute;
}
<button type="button" class="btnCircle"></button>
as A Haworth mentioned you, one way is using the before/after pseudo elements
here's an example:
.btnCircle {
position: relative;
border: none;
padding: 45px;
border-radius: 50%;
background: red;
}
.btnCircle::after {
position: absolute;
inset: 10px;
content: '';
background: blue;
border-radius: 50%;
}
<button class="btnCircle"></button>
One you can use background and border.
/*With background and border css start*/
.btnCircle1 {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
width: 85px;
color: white;
background-color: blue;
border: 15px solid red;
border-radius: 100%;
}
/*With background and border css end*/
/*With pesudo element css start*/
.btnCircle1-psd {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
width: 50px;
color: white;
}
.btnCircle1-psd::before,
.btnCircle1-psd::after {
content: "";
position: absolute;
top: 0;
left: 0;
display: inline-block;
height: 50px;
width: 50px;
border-radius: 50%;
background: red;
z-index: -1;
}
.btnCircle1-psd::after {
transform: scale(0.8);
background-color: blue;
}
/*With pesudo element css end*/
/*With radial gradient background color start*/
.btnCircle1-bg {
position: relative;
background: transparent;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
height: 85px;
width: 85px;
color: white;
border-radius: 100%;
background: rgb(255, 0, 0);
background: radial-gradient(circle, rgba(255, 0, 0, 1) 50%, rgba(0, 160, 255, 1) 50%);
}
/*With radial gradient background color end*/
/*With box inset shadow color start*/
.btnCircle1-shadow {
position: relative;
background: red;
border: none;
z-index: 99;
line-height: 50px;
text-align: center;
height: 85px;
width: 85px;
color: white;
border-radius: 100%;
-webkit-box-shadow: inset 0px 0px 0px 10px blue;
box-shadow: inset 0px 0px 0px 10px blue;
}
/*With box inset shadow color end*/
<h1> With background and border</h1>
<button type="button" class="btnCircle1">1$</button>
<h1> With radial gradient background color</h1>
<button type="button" class="btnCircle1-bg">1$</button>
<h1> With box inset shadow color</h1>
<button type="button" class="btnCircle1-shadow">1$</button>
<h1>With pesudo element <strong>before</strong> and <strong>after</strong>.</h1>
<button type="button" class="btnCircle1-psd">1$</button>
Title is a bit of a mouthful. I've just started with CSS and am trying to achieve the effect a text overlay while the image is still transparent behind the text.
Below is what I've managed to achieve by snipping together various bits of code I've found. I am struggling to get the dark overlay the same size as the image. I haven't used any margin or padding on the overlay or image so have no clue why it's happening. I've also tried several ways to align the text so it sits vertically in the middle but have had no such luck.
.image-container {
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
}
.border {
border-radius: 50%;
}
.image-container .after {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 100%;
display: none;
color: #FFF;
border-radius: 50%;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
border-radius: 50%;
}
#title {
background: url('https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png');
background-size: cover;
color: #fff;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
padding: 0;
display: flex;
}
h1 {
font-size: 80px;
font-family: sans-serif;
text-align: center;
text-shadow: 0 0 1px rgba(0, 0, 0, .1);
margin: 0;
padding: 0;
letter-spacing: -1px;
line-height: 0.8;
}
<div class="image-container">
<img src="https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png" class='border' />
<div class="after">
<div id="title">
<h1><b>ONE<br>TWO</b></h1>
</div>
</div>
</div>
For the first issue You will not able to center the overlay on to the image because the image isn't actually 200px x 200px because there are transparent pixels around the image. so first crop the transparent pixels around the image and get it's real size. Then replace the 200px size in the css below to the appropriate size.
I have corrected your code snippet to be able to center the text by adding display: flex and align-content: center (for vertical alignment) and justify-content: center(for horizontal alignment),
I have also added overflow: hidden to the .image-container .after to prevent overflowed text and changed the text size to 60px for better visibility.
.image-container {
position: absolute;
width: 200px;
height: 200px;
border-radius: 50%;
}
.image-container .after {
position: absolute;
display: none;
left: 0;
bottom: 0;
overflow: hidden;
color: #FFF;
}
.image-container:hover .after {
display: flex;
background: rgba(0, 0, 0, 0.6);
border-radius: 50%;
border-width: 0px;
width: 200px;
height: 200px;
}
#title {
background: url('https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png');
background-size: cover;
color: #fff;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
padding: 0;
display: flex;
align-content: center;
justify-content: center;
width: 100%;
}
h1 {
font-size: 60px;
font-family: sans-serif;
text-align: center;
text-shadow: 0 0 1px rgba(0, 0, 0, .1);
margin: 0;
padding: 0;
display: flex;
align-items: center;
letter-spacing: -1px;
line-height: 0.8;
}
<div class="image-container">
<img src="https://bopepor.es/wp-content/uploads/2018/08/Logo-200x200PX.png" class='border' />
<div class="after">
<div id="title">
<h1><b>ONE<br>TWO</b></h1>
</div>
</div>
</div>
so i have the following design for some "button tabs".
One side is curved, so border radius would not really be possible.
But is this type of curve even possible ?
or am i doomed to use some sort of image?
mostly looking for tips on how this might be accomplished, or somewhere i can look for a solution, since my previous tries to find a solution has yet to yield a result.
Html
<div class="tab-row">
<button>All Products<div class="tab-row__counter">20</div></button>
<button>Hardware<div class="tab-row__counter">20</div></button>
<button>Virtual<div class="tab-row__counter">20</div></button>
<button>Bundles<div class="tab-row__counter">20</div></button>
</div>
Css
.tab-row{
button{
background-color:$element-bg;
border:0;
color:$white;
width:300px;
height:90px;
margin-right:20px;
margin-top:40px;
border-radius: 5px 100px 0 0;
&:first-child{
margin-left:40px;
}
.tab-row__counter{
}
}
}
This is what i ended up with as a result,
https://codepen.io/andrelange91/pen/YzPqJXO
not exactly curved but close enough
You can try the curves by using the border-radius, transform, and transform-origin properties like,
/**
* Slanted tabs with CSS 3D transforms
* See http://lea.verou.me/2013/10/slanted-tabs-with-css-3d-transforms/
*/
body { padding: 50px;background:#20273d }
nav {
position: relative;
z-index: 1;
white-space: nowrap;
}
nav a {
position: relative;
display: inline-block;
padding: 1.5em 2em 1em 1em;
color:#9a9a9a;
text-decoration: none;
margin: 0 -7px;
}
nav a::before {
content: ''; /* To generate the box */
position: absolute;
top: 0; right: 0; bottom: .5em; left: 0;
z-index: -1;
border-radius: 10px 10px 0 0;
background: #434f78;
box-shadow: 0 2px hsla(0,0%,100%,.5) inset;
transform: perspective(5px) rotateX(2deg);
transform-origin: bottom left;
}
nav a.selected {
z-index: 2;
color:#FFF;
}
<nav class="left">
All Products
Hardware
Virtual
</nav>
You can use radial gradient also,
body { padding: 50px;background:#20273d }
nav {
position: relative;
z-index: 1;
white-space: nowrap;
}
nav a {
position: relative;
display: inline-block;
padding: 1em 5em 1.2em 1em;
color:#9a9a9a;
text-decoration: none;
margin: 0 -20px;
border: 0px none;
}
nav a::before {
content: ''; /* To generate the box */
position: absolute;
top: 0;
right: 0;
bottom: .5em;
left: 0;
z-index: -1;
background: radial-gradient(circle at top right,transparent 5.8vw, #434f78 6.8vw);
transform: perspective(10px) rotateX(1deg);
transform-origin: bottom left;
border: 0px none;
}
nav a.selected {
z-index: 2;
color:#FFF;
}
<nav class="left">
All Products
Hardware
Virtual
</nav>
Whilst this does not replicate the exact shape you're after, this does provide an example of the method I described in the comments in how to approach it. You will just need to edit the values in ::before and ::after to get it to your desired shape.
.curve {
background: blue;
width: 50px;
height: 75px;
position: relative;
}
.curve:before {
content: '';
background-image: radial-gradient(circle at 100% 100%, rgba(204, 0, 0, 0) 100px, blue 100px);
position: absolute;
top: 0;
left: 100%;
width: 100px;
height: 75px;
}
.curve:after {
content: '';
position: absolute;
width: 50px;
height: 75px;
background: blue;
border-radius: 0 0 100% 0 / 0 0 100% 0;
top: 100%;
left: 0;
}
.container {
display: flex;
align-items: flex-start;
justify-content: center;
}
.tab {
height: 150px;
width: 300px;
background: red
}
<div class="container">
<div class="tab"></div>
<div class="curve"></div>
</div>
Also take a look at Creating s-shaped curve using css
I am trying to add sides to a box div with CSS but can't seem to figure it out. This is what I have so far. Can anyone point me in the right direction? I have included below the picture I am trying to replicate. It is the middle box.
body {
background: #1b1b1b;
color: white;
}
.container {
display: table;
margin: auto;
}
.box {
width: 150px;
height: 150px;
background: #cc0000;
margin: 50px;
}
.right-skew {
position: relative;
}
.right-skew:before {
z-index: -1;
content: '';
position: absolute;
top: 0;
bottom: 0;
right: -15px;
display: block;
width: 35px;
background: grey;
-webkit-transform: skew(-10deg);
-ms-transform: skew(-10deg);
transform: skew(-10deg);
}
.right-skew:after {
z-index: -1;
content: '';
position: absolute;
top: 0;
bottom: 0;
right: -15px;
display: block;
width: 35px;
background: grey;
-webkit-transform: skew(10deg);
-ms-transform: skew(10deg);
transform: skew(10deg);
}
.skew-border {
border: 5px solid yellow;
}
<div class="container">
<div class="box right-skew"></div>
</div>
You can accomplish this with borders pretty easily.
I'd put a large border around the left and right boxes and only color and left and right borders inversely.
* {
box-sizing: border-box;
}
.boxes {
display: flex;
justify-content: center;
}
.box {
width: 30%;
height: 200px;
text-align: center;
}
.box--1,
.box--3 {
border: 20px solid white;
background-color: rgb(200, 0, 0);
}
.box--1 {
border-right-color: red;
}
.box--3 {
border-left-color: red;
}
.box--2 {
background-color: darkred;
}
<div class="boxes">
<div class="box box--1">1</div>
<div class="box box--2">2</div>
<div class="box box--3">3</div>
</div>
Here's a quick demo: https://jsfiddle.net/15k214am/3/
Some fun with transitions cause I'm bored: https://jsfiddle.net/15k214am/4/
Here's a small adjustment to allow the background color to show through: https://jsfiddle.net/15k214am/5/
On either side, you need to add a couple of pseudo elements that are rotated with perspective added to the rotation transform.
body {
background: #1b1b1b;
color: white;
}
.container {
display: table;
margin: auto;
}
.box {
width: 150px;
height: 150px;
background: #cc0000;
margin: 50px;
}
/* following lines were added/modified */
.with-depth {
position: relative;
}
.with-depth:before, .with-depth:after {
content: '';
position: absolute;
top: 0px; /* no need to change */
height: 100%; /* no need to change */
width: 25px; /* can be changed depending on the required width */
background: grey;
z-index: -1; /* not really needed but will stop it from interfering with interation */
}
.with-depth:before {
right: -25px; /* equal to -1 * width of pseudo-element */
transform-origin: left; /* don't change */
transform: perspective(10px) rotateY(10deg); /* can be changed as per need */
}
.with-depth:after {
left: -25px; /* equal to -1 * width of pseudo-element */
transform-origin: right; /* don't change */
transform: perspective(10px) rotateY(-10deg); /* can be changed as per need */
}
/* just for demo */
.box:hover{
height: 250px;
width: 250px;
}
<div class="container">
<div class="box with-depth"></div>
</div>
Using this method would:
produce a responsive output (try hovering the element in the demo) unlike the output that would be produced through the border method (was referring to adding borders with pseudo-element on the middle one and not borders on the side elements like the other answer, which is very good).
leave the portion above and below the side elements transparent just in case the need is to show the background.
let you have greater control over the angle of the depth.
make it a little more easier to add extra effects like shadows etc to the box. Refer demo below. (This point is not applicable for shape shown in question but would be useful for a generic one.)
.box {
width: 150px;
height: 150px;
background: #cc0000;
margin: auto;
box-shadow: 0px 2px 4px 2px #CCC;
}
.with-depth {
position: relative;
}
.with-depth:before,
.with-depth:after {
content: '';
position: absolute;
top: 0px;
height: 100%;
width: 25px;
background: grey;
}
.with-depth:before {
right: -25px;
transform-origin: left;
transform: perspective(10px) rotateY(10deg);
box-shadow: 4px 4px 4px 2px #CCC;
}
.with-depth:after {
left: -25px;
transform-origin: right;
transform: perspective(10px) rotateY(-10deg);
box-shadow: -4px 4px 4px 2px #CCC;
}
/* just for demo */
.box:hover {
height: 250px;
width: 250px;
}
<div class="box with-depth"></div>
I have been trying to do the white shape with a div:
http://sircat.net/joomla/sircat/mies/2.png
how do I get the diagonal shapes of the bottom of the div?
I have this for the div:
width: 620px;
height: 440px;
background-color: white;
thank you
Edit: just forget the bg behind the div, I want to make the div with the diagonal borders, not with the help of the bg because it is in the top layer
You can also use borders and the :after pseudo selector: http://jsfiddle.net/qQySU/
#pointed {
position: relative;
margin: 0 auto;
width: 200px;
height: 200px;
background-color: white;
}
#pointed:after,
#pointed::after {
position: absolute;
top: 100%;
left: 50%;
margin-left: -50%;
content: '';
width: 0;
height: 0;
border-top: solid 150px red;
border-left: solid 100px transparent;
border-right: solid 100px transparent;
}
I've colored the tip for easy identification of the borders. Play around the border widths on the last 3 lines to get the tip you want.
Edit.:
Reference for compability: http://caniuse.com/css-gencontent
Edit 2:
In exchange for semantics, you can get it more crossbrowser you can place the stle on a inner element instead of on the :after pseudo selector.
Simplest (least amount of code) method: just use a CSS linear-gradient http://dabblet.com/gist/3610406
HTML:
<div class='box'>Text goes here...</div>
CSS:
.box {
width: 26em;
min-height: 31em;
padding: 1em;
outline: solid 1px lightblue;
margin: 0 auto;
background: linear-gradient(45deg, dimgrey 47%, black 50%, transparent 50%)
no-repeat 0 100%,
linear-gradient(-45deg, dimgrey 47%, black 50%, transparent 50%)
no-repeat 100% 100%;;
background-size: 50% 14em;
}
Better compatibility & better looking: you could use a pseudo-element with a box-shadow: http://dabblet.com/gist/3610548
HTML:
<div class='box'>text goes here... hover me ;)</div>
CSS:
html { background: darkgrey; }
.box {
box-sizing: border-box;
position: relative;
width: 20em;
height: 20em;
padding: 1em;
margin: 3em auto 0;
background: white;
}
.box:before {
position: absolute;
right: 14.65%; /* 50% - 35.35% */ bottom: -35.35%; /* half of 70.71% */
width: 70.71%; /* 100%*sqrt(2)/2 */
height: 70.71%;
box-shadow: 2px 2px 1px dimgrey;
transform: rotate(45deg);
background: white;
content: '';
}
.box:hover, .box:hover:before {
background: plum;
}