I'm trying to create a badge, containing a hexagon with a number in it. The badge/list-item itself would contain some info/name.
this is what I have so far:
.item {
display: block;
background-color: blue;
}
.item > span {
color: white;
display: inline-block;
}
.hexagon {
position: relative;
width: 65px;
height: 65px;
line-height: 65px;
text-align: center;
color: white;
}
.hexagon span {
position: absolute;
color: white;
z-index: 2;
left: 30;
}
.hexagon:before {
color: #ef473a;
position: absolute;
content: "\2B22";
font-size: 65px;
z-index: 1;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
<div class="item">
<div class="hexagon"><span>1</span></div>
<span class="title">TEST test</span> <!-- maximum width? > new line -->
<span class="info">something darkside</span>
</div>
This is what I'm trying to achieve:
As you can see, the "blue" background should only start at the tip of the hexagon. Width and height of it, aren't going to change. So now I'm wondering whether it would be easier to use an image or if someone could help me recreate the image, would be fine too :)
Thanks in advance!
Try the flexbox way, it's made for your case since you have three items (medal, title, description) that you want to have vertically aligned in the middle next to each other.
Below is a starting point, you can probably extend that to your needs by yourself.
Please note that I also changed the way the hexagon is created, it's not using an UTF8 character now but simply colored borders. This gives you more control about the size of the actual hexagon shaped medal.
Standing on one of its tips, the height of this hexagon is equivalent with its diameter (d) which in turn is twice as long as one of the six lines (s) forming the hexagon. The width (w) of this hexagon is then: s * sqrt(3) or .5 * d * sqrt(3).
.badge {
height: 64px;
margin-left: 35px;
color: white;
font-family: sans-serif;
background: blue;
border: 1px solid transparent;
display: flex;
align-item: middle;
}
.medal {
position: relative;
margin-left: -30px;
min-width: 75px;
}
.count {
position: absolute;
width: 58px;
text-align: center;
line-height: 64px;
font-size: 30px;
top: -16.74px;
}
h3 {
max-width: 40%;
margin-right: 30px;
font-size: 14px;
}
p {
font-size: .875em;
}
.hexagon {
position: relative;
width: 58px;
height: 33.49px;
background-color: #ff2600;
margin: 14.74px 0 16.74px 0;
}
.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
width: 0;
border-left: 29px solid transparent;
border-right: 29px solid transparent;
}
.hexagon:before {
bottom: 100%;
border-bottom: 16.74px solid #ff2600;
}
.hexagon:after {
top: 100%;
width: 0;
border-top: 16.74px solid #ff2600;
}
<div class="badge">
<div class="medal">
<div class="hexagon">
<div class="count">1</div>
</div>
</div>
<h3>The HEXAGON Badge Quest</h3>
<p>You successfully posted a valid question on Stack Overflow and received an answer.</p>
</div>
Try the following. I haven't tested on mobile. Just chrome at this point, but it should get you close. You'll need to play around with the text somewhat to handle the wrapping and sizing inside the blue bar, but your question was in regards to the badge. The corner effects are clipping the shape by about 10px. So setting a fixed height on the bar and a 10px taller height on the hexagon did the trick. Then just some positioning and margin to move things into position. Good luck.
.item {
display: block;
background-color: blue;
height: 66px;
position: relative;
left: 35px;
width: 100%;
}
.item > span {
color: white;
display: inline-block;
}
.hexagon {
display: inline-block;
position: relative;
width: 66px;
height: 66px;
line-height: 66px;
text-align: center;
color: white;
top: 0;
left: -35px;
}
.hexagon span {
position: absolute;
color: white;
z-index: 2;
width: 66px;
height: 66px;
line-height: 66px;
text-align:center;
left: -0;
}
.hexagon:before {
color: #ef473a;
position: absolute;
content: "\2B22";
font-size: 76px;
z-index: 1;
width: 66px;
height: 66px;
left: 0;
top: -5px;
}
.title {
position: absolute;
font-size: 1.75rem;
top: 12px;
left: 33px;
margin: 0;
text-align:center;
display:block;
height: 66px;
width: 20%;
line-height: 18px;
}
.info {
position: absolute;
top: 0px;
left: 20%;
margin: 0;
text-align:center;
display:block;
height: 66px;
width: 70%;
line-height: 66px;
vertical-align: center;
}
<div class="item">
<div class="hexagon"><span>1</span></div>
<span class="title">TEST test</span> <!-- maximum width? > new line -->
<span class="info">something darkside</span>
</div>
Related
I am trying to position a div over another by using position: relative; & position: absolute;. I have made use of this successfully previously in the project, however it isn't given the desired outcome/working on the second use of it. All it is doing is displaying the second div under the first.
HTML
<header>
<img class="header-img" src="https://i.pinimg.com/222x/ec/c6/f2/ecc6f20889bba2976601a3abb029183c.jpg">
<div class="header-text left"> ToKa Fitness</div>
</header>
<div>
<div class="offer"></div>
<div class="sign-in"></div>
</div>
CSS
header {
width: 100%;
height: 120px;
position: relative;
border: 2px black solid;
}
img.header-img {
width: 122px;
height: 122px;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
}
div.header-text {
width: 100%;
position: absolute;
padding-top: 42px;
font-family: articulat-cf, sans-serif;
font-style: normal;
font-weight: 700;
font-size: 30px;
text-align: center;
}
div.offer {
width: 100%;
height:30px;
position: relative;
border: 2px green solid;
}
div.sign-in {
width: 120px;
height: 30px;
position: absolute;
top: 132px;
right: 4px;
border:2px red dashed;
}
I am aiming for the smaller red div to go on top of the green div above it to the far right. I have tried using top and right to assist with positioning it but to no obvious effect on the program.
position absolute places an element relative to its parent's position. if you want to set the position of div.sign-in absolute, it should have a parent with "relative" position
<header>
<img
class="header-img"
src="https://i.pinimg.com/222x/ec/c6/f2/ecc6f20889bba2976601a3abb029183c.jpg"
/>
<div class="header-text left"> ToKa Fitness</div>
</header>
<div>
<div class="offer"><div class="sign-in"></div></div>
</div>
and CSS file:
header {
width: 100%;
height: 120px;
position: relative;
border: 2px black solid;
}
img.header-img {
width: 122px;
height: 122px;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
text-align: center;
}
div.header-text {
width: 100%;
position: absolute;
padding-top: 42px;
font-family: articulat-cf, sans-serif;
font-style: normal;
font-weight: 700;
font-size: 30px;
text-align: center;
}
div.offer {
width: 100%;
height:30px;
position: relative;
border: 2px green solid;
}
div.sign-in {
width: 120px;
height: 30px;
position: absolute;
right: 0;
border:2px red dashed;
}
can you add screenshot of how it looks like?
How can I make a dot under text using only CSS as shown in below picture?
The picture needs to be always in middle with any length of string.
Probably I need to use :before OR :after? I've tried but result was awful.
A transformed pseudo element can be used to create this:
body { text-align: center; }
.text {
display: inline-block;
vertical-align: top;
padding-bottom: 10px;
position: relative;
text-align: center;
padding: 20px 10px;
line-height: 24px;
min-width: 100px;
background: #333;
font-size: 20px;
color: #fff;
}
.text::before {
transform: translateX(-50%);
border-radius: 100%;
position: absolute;
background: blue;
bottom: 10px;
height: 8px;
content: '';
width: 8px;
left: 50%;
}
<div class="text">about</div>
.char {
display: inline-block;
position: relative;
}
.char::before {
content: '.';
display: inline-block;
position: absolute;
bottom: -0.5em;
left: 0;
text-align: center;
width: 100%;
}
After writing this question on stack i come up with idea:) Its works excatly like I want :)
I would like to design a border like below picture. But I am running out of ideas about how to do it.
https://codepen.io/szn0007/pen/VRGPyE
div.about-me h2{
color: #000;
border-bottom: 1px solid #efefef;
width: 20%;
margin: 0 auto;
padding: 20px;
}
THank you in advance.
Luckily with CSS you have access to two pseudo elements on every container. I added the Asterix to one of the pseudo elements :after and the line to another :before.
For example:
.fancy-underline {
position: relative;
display: inline-block;
}
.fancy-underline:before {
content: '';
position: absolute;
top: calc(100% + 10px);
left: 0;
width: 100%;
height: 1px;
background: grey;
}
.fancy-underline:after {
content: '*';
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
background: #fff;
}
<h2 class="fancy-underline">About Me</h2>
try this out:
<div class="about-me">
<h2>About Me</h2>
<p>*</p>
</div>
css:
div.about-me{
width: 100%;
text-align: center;
}
div.about-me h2{
color: #000;
border-bottom: 1px solid #efefef;
width: 20%;
margin: 0 auto;
padding: 20px;
}
p {
font-size: 50px;
transform: translatey(-72px);
}
How can I make a dot under text using only CSS as shown in below picture?
The picture needs to be always in middle with any length of string.
Probably I need to use :before OR :after? I've tried but result was awful.
A transformed pseudo element can be used to create this:
body { text-align: center; }
.text {
display: inline-block;
vertical-align: top;
padding-bottom: 10px;
position: relative;
text-align: center;
padding: 20px 10px;
line-height: 24px;
min-width: 100px;
background: #333;
font-size: 20px;
color: #fff;
}
.text::before {
transform: translateX(-50%);
border-radius: 100%;
position: absolute;
background: blue;
bottom: 10px;
height: 8px;
content: '';
width: 8px;
left: 50%;
}
<div class="text">about</div>
.char {
display: inline-block;
position: relative;
}
.char::before {
content: '.';
display: inline-block;
position: absolute;
bottom: -0.5em;
left: 0;
text-align: center;
width: 100%;
}
After writing this question on stack i come up with idea:) Its works excatly like I want :)
In my first div container, I added a heading 1 tag, gave a border bottom a color of my desire, and added font awesome icon in the middle.
As you can see I had to give a background color on the font awesome to make it appear transparent. but now I have a background image on the second box so I am struggling to achieve the same thing.
How can I do the same on my other div box without affecting the background image
visibility as well as the border bottom from the heading 1?
div.container{
background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
background-size: cover;
background-position: 50%;
}
div{
height: 100px;
}
h1.widget_title_1{
font-size: 25pt;
display: inline-block;
margin: 0;
margin-top: 35px;
padding-bottom: 9px;
border-bottom: 1px solid #898989;
position: relative;
}
h1.widget_title_1:after {
position: absolute;
font-family: fontawesome;
display: block;
margin-left: 58px;
margin-top: -7px;
padding: 0 5px;
font-size: 24pt;
color: black;
content: '\f107';
font-weight: 300;
background-color: white;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container-1">
<h1 class="widget_title_1">
heading 1
</h1>
</div>
<div class="container">
<h1 class="widget_title">
heading 1
</h1>
</div>
I suggest you to use font-awesome icons along-with tag as here I have used i tag, it get's easy to align icon i.e. at center of that div tag, just by using text-align:center. Then you can use pseudo selector :before and :after on h1 tag and add that border. Scale to and fro on this jsFiddle and see border doesn't get's attached at certain screen resolution.
.container-1 {
height: 100px;
display: inline-block;
overflow: hidden;
}
.container-1 > .widget_title_1 {
font-size: 25pt;
margin: 0;
display: inline-block;
position: relative;
}
.container-1 > .fa {
font-size: 24px;
display: block;
height: 30px;
text-align: center;
}
.container-1 > .widget_title_1:before {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
left: 0;
margin-left: -10px;
}
.container-1 > .widget_title_1:after {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
margin-right: -10px;
right: 0;
}
.container {
background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
background-size: cover;
background-position: 50%;
height: 100px;
overflow: hidden;
}
.container > .widget_title {
font-size: 25pt;
margin: 0;
display: inline-block;
position: relative;
}
.container > .fa {
font-size: 24px;
display: block;
height: 30px;
width: 138px;
text-align: center;
}
.container > .widget_title:before {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
left: 0;
margin-left: -10px;
}
.container > .widget_title:after {
content: "";
position: absolute;
width: 50%;
height: 2px;
background: #111;
bottom: -38%;
margin-right: -10px;
right: 0;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container-1">
<h1 class="widget_title_1">
heading 1
</h1>
<i class="fa fa-angle-down"></i>
</div>
<div class="container">
<h1 class="widget_title">
heading 1
</h1>
<i class="fa fa-angle-down"></i>
</div>
Use :before :after for div for the line.
Create a span tag with the font awesome as shown below.
div.container{
background-image: url(http://az616578.vo.msecnd.net/files/2016/04/09/6359580807140768861266757027_Never-Study-Hard-The-Art-of-Studying-Smart.jpg);
background-size: cover;
background-position: 50%;
}
div{
position: relative;
height: 100px;
}
h1.widget_title_1{
font-size: 25pt;
display: inline-block;
margin: 0;
margin-top: 35px;
padding-bottom: 9px;
border-bottom: 1px solid #898989;
position: relative;
}
span:after {
position: absolute;
font-family: fontawesome;
display: block;
margin-left: 58px;
margin-top: -7px;
top:40px;
padding: 0 5px;
font-size: 24pt;
color: black;
content: '\f107';
font-weight: 300;
background-color: transparent;
}
div.container:after{
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid black;
top: 45px;
width: 60px;
}
div.container:before{
content: "";
position: absolute;
height: 5px;
border-bottom: 1px solid black;
top: 45px;
left:90px;
width: 60px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="container-1">
<h1 class="widget_title_1">
heading 1
</h1>
</div>
<div class="container">
<h1 class="widget_title">
heading 1
</h1>
<span></span>
</div>