I am trying to create a h1 style that is surrounding the text with a background color.
h1.skew {
padding-left: 10px;
text-decoration: none;
color: white;
font-weight: bold;
display: inline-block;
border-right: 50px solid transparent;
border-top: 50px solid #4c4c4c;
height: 0;
line-height: 50px;
}
<h1 class="skew">HELLO WORLD</h1>
https://jsfiddle.net/zo32q98n/
At this point the text appears beneath the background. How can I make the text appear inside the brown colored background?
You can use pseudo-element for background and set z-index: -1 so it appears under the text.
h1.skew {
padding-left: 10px;
text-decoration: none;
color: white;
font-weight: bold;
display: inline-block;
position: relative;
height: 0;
line-height: 50px;
}
h1.skew:before {
content: '';
z-index: -1;
border-right: 50px solid transparent;
border-top: 50px solid #4c4c4c;
height: 100%;
position: absolute;
top: 0;
left: 0;
width: 100%;
}
<h1 class="skew">HELLO WORLD</h1>
Since the border is 50px tall, you can insert a negative margin of the same amount inside:
h1.skew::before {
content: '';
display: block;
margin-top: -50px;
}
body {
background: #ddd;
}
h1.skew {
padding-left: 10px;
text-decoration: none;
color: white;
font-weight: bold;
display: inline-block;
border-right: 50px solid transparent;
border-top: 50px solid #4c4c4c;
height: 0;
line-height: 50px;
}
h1.skew::before {
content: '';
display: block;
margin-top: -50px;
}
<h1 class="skew">HELLO WORLD</h1>
You can use CSS3 linear-gradient().
h1.skew {
padding: 10px 80px 10px 10px;
display: inline-block;
color: white;
background: #4c4c4c; /* fallback */
background: linear-gradient(135deg, #4c4c4c 80%, transparent 80%);
}
<h1 class="skew">HELLO WORLD</h1>
Alternatively there is no problem if you use border-bottom instead of border-top.
body {
background: #ddd;
}
h1.skew {
padding-left: 10px;
text-decoration: none;
color: white;
font-weight: bold;
display: inline-block;
border-right: 50px solid transparent;
border-bottom: 50px solid #4c4c4c;
height: 0;
line-height: 50px;
}
<h1 class="skew">HELLO WORLD</h1>
You can wrap the text in a span...
<h1 class="skew"><span class="text">HELLO WORLD</span></h1>
And then add the following to your stylesheet...
span.text {
position: relative;
top: -50px;
}
This will move the text up so that it appears over the border you've defined.
Related
I want to create a border (camera type) with 3 colors (blue, white and red).
I created this HTML code:
<div class="reinsurance-offer">
<div class="reinsurance-offer-link">Faites la promotion de vos événements</div>
</div>
I applied this CSS:
#block-subtheme-olivero-views-block-reassurance-block-1 .reinsurance-offer {
background-color: #f7f9fa;
padding-right: 2.25rem;
padding-left: 2.25rem;
padding-top: 1.6875rem;
padding-bottom: 1.6875rem;
text-align: center;
}
#block-subtheme-olivero-views-block-reassurance-block-1 .reinsurance-offer-link {
display: inline-flex;
padding: 0.75rem;
border: 5px solid;
border-color: #E20E17 #1F71B8;
background-color: #ffffff;
}
Here is the rendering :
I want to make the same display as in the image below, without the blur effect.
How can I do this in CSS and is it possible?
I didn't manage to get the desired result
You don't really need a lot of code. One gradient can do the job:
.box {
width: 250px;
height: 150px;
border: 10px solid;
border-image: linear-gradient(90deg,red 33%,#0000 0 66%,blue 0) 1;
}
<div class="box"></div>
i'm not really sure where you want to use this, but what about something like this:
.link {
--link-border-width: 5px;
color: grey;
position: relative;
width: fit-content;
display: block;
padding: .5rem 1rem 0;
text-decoration: none;
}
.link::before,
.link::after {
content: "";
height: 100%;
width: calc(100% / 3);
border: 4px solid red;
display: block;
position: absolute;
top: 0;
}
.link::before {
border: var(--link-border-width) solid blue;
border-right: none;
left: 0;
}
.link::after {
border: var(--link-border-width) solid red;
border-left: none;
right: 0;
}
<a href="#" class="link">This is my link<a>
I want to make a line between two circles, for that, I have used the below code by using pseudo-element CSS. I would like to make the line between these two circles responsive, now it's intersecting with circle in some other devices like mobile, etc. How to make it responsive or any other solution that does the same design? Please help.
.cart_header_tab {
display: flex;
margin-top: 35px;
}
.cart_header_tab > div {
text-align: center;
margin-right: 100px;
cursor: pointer;
}
.cart_header_tab h6 {
color:#02b5f9;
font-weight: 400;
}
.cart_header_tab div:last-child h6 {
color:#ccc
}
span.circle_one::after {
content: "";
width: 152px;
height: 1px;
background: #eee;
position: absolute;
top: 6px;
left: 14px;
}
.cart_header_tab span.circle_one {
border: 1px solid #2fe4ba;
}
.cart_header_tab span {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #ccc;
border-radius: 100%;
position: relative;
}
<div class="cart_header_tab">
<div>
<span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div>
<span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
You can start tweaking the code something like this:
Be aware that if you wanted to change the size or width of the circle you have to tweak the other property in the css, hope that is not an issue here.
#cart_header_tab {
position: relative;
display: inline-block;
}
#cart_header_tab::after {
content: "";
position: absolute;
width: 50%;
z-index: -1;
top: 20%;
left: 25%;
border: 1px solid gray;
/* line between circles */
}
#cart_header_tab div {
display: inline-block;
font-size: 12px;
text-align: center;
min-width: 150px;
}
#cart_header_tab span {
color: white;
background: white;
display: block;
height: 15px;
margin: 0 auto 10px;
padding-top: 20px;
width: 30px;
border-radius: 50%;
border: 1px solid #22A7F2;
}
<div id="cart_header_tab">
<div><span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div><span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
Using flex i insert that line between circle as separator itself is a child of flex and hen using margin adjust that according to circles
.cart_header_tab {
display: flex;
margin-top: 35px;
}
.cart_header_tab>div {
text-align: center;
cursor: pointer;
}
.cart_header_tab h6 {
color: #02b5f9;
font-weight: 400;
}
.cart_header_tab div:last-child h6 {
color: #ccc
}
.cart_header_tab {
position: relative
}
.sep {
width: 100%;
height: 1px;
background: #eee;
margin: 9px -21px 0;
}
.cart_header_tab span.circle_one {
border: 1px solid #2fe4ba;
background: #fff;
z-index: 1;
}
.circle_two {
background: #fff;
z-index: 1;
}
.cart_header_tab span {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid #ccc;
border-radius: 100%;
position: relative;
}
<div class="cart_header_tab">
<div>
<span class="circle_one"></span>
<h6>Order Details</h6>
</div>
<div class="sep"></div>
<div>
<span class="circle_two"></span>
<h6>Freight Options</h6>
</div>
</div>
Creating a circle around a letter or text works fine, but in my case I only want to circle a single letter within a word (which is within an H1 tag):
.large {
font-size: 5em;
}
.circle {
border-radius: 50%;
padding: -0.5% 5% 0% 5%;
background: #fff;
border: 10px solid red;
color: red;
}
<h1 class="large">
<span class="circle">e</span>Text
</h1>
Fiddle is here: https://jsfiddle.net/henzen/zwph2nsv/4/
This produces:
Notice that the circle is conforming to the H1 height (I think) - I need it to be compressed vertically, ie the vertical padding needs to be the same as the horizontal, tightly wrapped around the "e".
Is this possible, or would I need to separate the "e" from the "Text" completely in the HTML?
I have tried Unicode chars (eg, ⓔ), which work, but cannot be reliably styled across browsers.
Thanks for any pointers.
You could use a pseudo element.
.large {
font-size: 5em;
}
.circle {
position: relative;
color: red;
}
.circle:after {
content: '';
width: 39px;
height: 44px;
border: 4px solid red;
position: absolute;
border-radius: 50%;
left: -5px;
top: 27px;
}
<h1 class="large">
<span class="circle">e</span>Text
</h1>
use a pseudo element.
Try This: https://jsfiddle.net/2gtazqdy/12/
* {
margin: 0;
padding: 0;
}
.large {
font-size: 5em;
}
.circle {
height: 50px;
width: 50px;
display: inline-block;
padding-left: 20px;
}
.circle::after {
display: inline-block;
height: 50px;
width: 50px;
z-index: 1;
position: absolute;
top: 18px;
left: 4px;
content: "";
color: red;
background: transparent;
border: 10px solid red;
border-radius: 50%;
}
My output:
try this
for your html do <h1> <span> C </span> ircle </h1>
then in the css define your h1 span
and give it padding, in the shape of a rectangle you could use this =
padding: 20px 10px;
then add a border, for example =
border: 5px solid #ddd;
then at last give it a border radius, this is a bit tidious to figure out but just play around with the pixels and you'll eventually get it right how you want it.
for example =
Border-radius: 20px
your html:
<h1> <span> C </span>ircle </h1>
your total css:
h1 span{
padding: 20px 10px;
border: 5px solid #ddd;
border-radius: 20px;
}
If you want to make a circle, the following is needed:
display: inline-block (or display: block)
same width, height and line-height
text-align: center
Use em to correspond with the font-size of the container.
Example
.large {
font-size: 5em;
}
.circle {
display: inline-block;
width: 0.8em;
height: 0.8em;
line-height: 0.8em;
text-align: center;
border-radius: 50%;
background: #fff;
border: 0.05em solid red;
color: red;
}
<h1 class="large">
<span class="circle">e</span>Text
</h1>
Please try this code
.large{
text-align: center;
font: 40px Arial, sans-serif;
color:#000;
font-weight:bold;
}
.circle {
border-radius: 50%;
background: #fff;
border: 6px solid red;
padding: 3px 10px;
text-align: center;
font: 28px Arial, sans-serif;
color: #000;
font-weight: bold;
}
<h1 class="large">
<span class="circle">e</span>Text
</h1>
I have a text in the middle of the div block with a font size 80px. When I hover on the div block, it will change the border size from 1px to 5px with a blue color but the text will moves down.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.calendarday-number:hover {
margin: 12px 2px;
}
.calendarday-container:hover {
border: 5px solid #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Jsfiddle: http://jsfiddle.net/f0k6r9nb/
I have tried to change the margin in the calendarday-container:hover .add-day-ico but it didn't help to resolve the issue.
Can you please show me an example how I can stop the text moving down on hover?
Thank you.
Changing the width of the border from 1px to 5px and recalculating the inner parts is not a practical solution. You could use an additional element, which has 5px of transparent border and change it to 5px of colored border on hover.
Another simple solution would be to use outline instead, as it doesn't add to the elements dimensions:
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-container:hover {
outline: 5px solid #2e7ad1;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
.add-day-ico {
opacity: 0;
width: 21px;
height: 21px;
position: absolute;
bottom: 0;
right: 0;
}
.calendarday-container:hover img {
opacity: 1;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" class="add-day-ico">
</a>
</div>
A typical approach to showing a border on hover is to have the non-hover state be transparent or a color that matches the background along with the width matching that of the border when hovered.
In this case, there's an existing 1px border. Here, I would change the gray border blue, then use an inset box-shadow to add the additional 4px of the border.
Note: I also removed some margin for .calendarday-number on hover so the number does not shift.
.calendar-content {
width: 81%;
display: block;
padding: 0;
background: #fff;
float: left;
position: relative;
margin-bottom: 150px;
}
.calendarday-container {
width: 139px;
height: 139px;
float: left;
position: relative;
margin-top: -1px;
margin-left: -1px;
border: 1px solid #ccc;
}
.calendarday-add .calendarday-number {
display: inline-block;
width: 100%;
font-size: 80px;
color: #f1f1f1;
margin: 12px 0px;
text-align: center;
}
/*
.calendarday-number:hover {
margin: 12px 2px;
}
*/
.calendarday-container:hover {
border-color: #2e7ad1;
box-shadow: inset 0 0 0 4px #2e7ad1;
}
.add-day-ico {
display: none;
width: 21px;
height: 21px;
margin: 22px 0px;
float: right;
}
.calendarday-container:hover .add-day-ico {
display: block;
margin: 22px 0px;
}
<div class="calendarday-container" data-day="0" data-dropable="true">
<a href="/autoresponder/create_day.php?day=0" data-action="click" class="calendarday-add">
<span class="calendarday-number">0</span>
<img src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png" sytle="height: 21px; width: 21px;" align="right" style="margin-top: 3px;" class="add-day-ico">
</a>
</div>
Add this:
.calendarday-container {
border: 5px solid transparent;
outline: 1px solid #ccc;
outline: none;
}
.calendarday-container:hover {
outline: none;
}
Remove this:
.calendarday-number:hover {
margin: 12px 2px;
}
You can use a pseudo element like this. I also removed lot of unnecessary css that was fighting each other
* { margin: 0; padding: 0; box-sizing: border-box; }
body { margin: 5%; }
/* Normal */
.calendarday-container {
width: 150px; height: 150px;
position: relative;
display: flex; align-items: center; justify-content: center;
}
.calendarday-container:after {
content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
border: 1px solid #ccc; z-index: -1;
}
.caldndarday-add { text-decoration: none; }
.calendarday-number { font-size: 80px; color: #ccc; }
.add-day-ico { width: 24px; height: 24px; position: absolute; bottom: -8px; right: -8px; }
/* Hover FX */
.calendarday-container:hover:after { border: 10px solid navy; }
.calendarday-container:hover .calendarday-number { color: navy; }
<div class="calendarday-container" data-day="0" data-dropable="true">
<a class="caldndarday-add" href="/autoresponder/create_day.php?day=0" data-action="click">
<span class="calendarday-number">0</span>
<img class="add-day-ico" src="http://www.clker.com/cliparts/u/F/K/J/M/A/add-button-md.png">
</a>
</div>
The text was moving down because, There was increase in border-width from 1px to 5px while hover.
You can either maintain a outline around the box using outline property, and keeping the border: 5px solid transparent to border: 5px solid #2e7ad1 while hovering.
I've created a working fiddle for you, for better understanding: Link to Jsfiddle
I'm trying to recreate this stylized line border behind my header (see: https://www.vox.com's yellow border behind 'Top Stories'). I understand that it's being created using :before but I can't seem to get my header span (projheader_name) to white out some of the border AND I'm getting two of the :before elements created for some reason. One gets inserted after div class="container" and the other after span="projheader_name".
#projheader {
margin-top: 40px;
padding-top: 20px;
}
#projheader .container {
background-color: white;
}
#projheader h3 {
margin-bottom: 10px;
}
.projheader_name {
background-color: white;
position: relative;
z-index: 3;
}
#projheader :before {
border-left: 4px solid #17A2B8;
border-right: 4px solid #17A2B8;
border-top: 4px solid #17A2B8;
content: " ";
height: 40px;
left: 6%;
position: absolute;
right: 6%;
top: 27%;
}
<section id="projheader">
<div class="container">
<span class="projheader_name">
<h3>Landing Page: Sense</h3>
</span>
</div>
</section>
h3 {
text-align: center;
border: 4px solid #17A2B8; border-bottom: 0;
}
h3 span {
position: relative;
top: -0.7em;
background: #fff;
display: inline-block;
padding: 0 0.7em;
}
<h3><span>LANDING PAGE</span></h3>