* {
font-size: 14px;
box-sizing: border-box;
}
.wrapper {
padding: 2rem;
}
.text--bigtitle {
text-transform: uppercase;
font-size: 2rem;
}
.border--short {
position: relative;
}
.border--short::after {
content: "";
display: block;
position: absolute;
height: 2px;
width: 40%;
bottom: 0;
left: 50%;
color: red;
margin-left: -20%;
}
<div class="wrapper">
<p class="border--short text--bigtitle">Short Border</p>
</div>
I want to achieve a short bottom border instead of a full-width bottom border under a title using CSS and HTML.
I have tried using position:absolute to position the after element under the title text with the width desired. However, the bottom border is not showing at all. My code is as shown below:
Can anyone help me to solve this problem, thank heaps.
change color property to background-color property of .border--short::after. color property is used to change the font color of the text. background-color is used to change the background color. thanks
* {
font-size: 14px;
box-sizing: border-box;
}
.wrapper {
padding: 2rem;
}
.text--bigtitle {
text-transform: uppercase;
font-size: 2rem;
}
.border--short {
position: relative;
}
.border--short::after {
content: "";
display: block;
position: absolute;
height: 2px;
width: 40%;
bottom: 0;
left: 50%;
background-color: red;
margin-left: -20%;
}
<div class="wrapper">
<p class="border--short text--bigtitle">Short Border</p>
</div>
I hope this is how you need..
* {
font-size: 14px;
box-sizing: border-box;
}
.wrapper {
padding: 2rem;
}
.text--bigtitle {
text-transform: uppercase;
font-size: 2rem;
}
.border--short {
position: relative;
padding-bottom: 10px;
}
.border--short::after {
content: "";
display: block;
height: 2px;
width: 40%;
background-color: red;
}
<div class="wrapper">
<p class="border--short text--bigtitle">Short Border</p>
</div>
try this once it will work and if you don't want text center remove text-align: center form class .wrapper.
* {
font-size: 14px;
box-sizing: border-box;
}
.wrapper {
padding: 2rem;
text-align: center;
}
.text--bigtitle {
text-transform: uppercase;
font-size: 2rem;
position: relative;
display: inline-block;
}
.text--bigtitle::after {
content: "";
display: block;
height: 2px;
width: 40%;
background-color: red;
margin: auto;
}
<div class="wrapper">
<p class="text--bigtitle">Short Border</p>
</div>
Thank You...
* {
font-size: 14px;
box-sizing: border-box;
}
.wrapper {
padding: 2rem;
}
.text--bigtitle {
text-transform: uppercase;
font-size: 2rem;
}
.border--short {
position: relative;
display: inline-block;
}
.border--short::after {
content: "";
display: block;
position: absolute;
height: 2px;
width: 40%;
bottom: 0px;
left: 30%; /* 50 % minus half the width */
background-color: red;
}
<div class="wrapper">
<p class="border--short text--bigtitle">Short Border</p>
</div>
Related
I'm trying to overlap the text over the div below it. The problem is that I need it all in the bottom right of the page so it already has position: absolute.
This is what I currently have.
And this is what I'm trying to make it look like:
https://jsfiddle.net/7ow5p192/
body {
background-color: black;
}
.title {
color: white;
text-align: left;
}
.artist {
color: black;
font-size: 60px;
line-height: 60px;
}
.artist-container {
text-align: left;
width: 100%;
background-color: white;
display: block;
}
.nameContain {
font-weight: bold;
position: absolute;
display: block;
right: 0;
bottom: 0;
max-width: 50%;
font-size: 50px;
}
.nameContain2 {
position: relative;
}
<div class="nameContain">
<span class="title">Smells Like Teen Spirit</span>
<div class="artist-container"><span class="artist">Nirvana</span></div>
</div>
A simple text-align: right should do the trick.
body {
background-color: black;
}
.title {
color: white;
}
.artist {
color: black;
font-size: 60px;
line-height: 60px;
}
.artist-container {
width: 100%;
background-color: white;
display: block;
}
.nameContain {
font-weight: bold;
position: absolute;
display: block;
right: 0;
bottom: 0;
max-width: 50%;
font-size: 50px;
text-align: right;
}
<div class="nameContain">
<span class="title">Smells Like Teen Spirit</span>
<div class="artist-container"><span class="artist">Nirvana</span></div>
</div>
I've created a card that is showcasing an article.
For some reason, two of the elements have additonal height that's causing weird behaviour. At first I thought it was the image but giving it a diplay:block hasn't solved the issue.
I've been messing around with it a lot so it's a bit of a mess at this point. SO here's the weird extra height between the white part of the card and the image:
Because it's happening to two elements, I have a feeling that it's something important that I am fundamentally missing.
The two affected elements are:
articleCard_image, a <div>
articleCard_container, a <section>
The issue only occurs for the <secction> when the 'Read Article' anchor is displayed. (I've commmented out the display:none which is changed to block on hover)
I'm using Gulp to compile the scss to css.
Any help would be greatly appreciated. Thank you! Code shown below:
SCSS:
.articleCard_container {
width: 55.7rem;
height: auto;
.articleCard_image {
width: 100%;
height: auto;
box-sizing: border-box;
display: block;
.articleCard_category {
position: relative;
bottom: 4rem;
left: 3rem;
display: flex;
align-items: center;
text-transform: uppercase;
font-size: 1.4rem;
color: var(--white);
width: 100%;
p {
font-weight: 600;
}
.thumbtack {
margin-right: 1rem;
margin-bottom: 1rem;
}
.purpleRose {
width: 100%;
display: block;
}
}
}
.articleCard_textContent {
box-sizing: border-box;
padding: 1rem 3rem 5rem 3rem;
width: 100%;
margin: 0;
background-color: var(--white);
.articleCard_date {
color: var(--articleDate);
text-transform: uppercase;
font-size: 1.2rem;
}
.articleCard_title {
margin-top: 1rem;
font-size: 1.6rem;
width: 100%;
color: var(--articleTitle);
font-weight: 700;
}
}
.articleCard_readMore {
text-transform: uppercase;
color: var(--buttonPrimary);
font-size: 1.2rem;
font-weight: 600;
position: relative;
bottom: 2rem;
left: 3rem;
// display: none;
}
}
.articleCard_container:hover {
.articleCard_readMore {
display: block;
box-sizing: border-box;
text-decoration: none;
}
}
HTML:
<div class="carouselle_container">
<section class="articleCard_container">
<div class="articleCard_image">
<img class="purpleRose" src="./assets/purpleRose.jpg" alt="purple rose">
<div class="articleCard_category">
<img class="thumbtack" src="./assets/thumtack.svg" alt="thumbtack icon">
<p>featured news / category</p>
</div>
</div>
<div class="articleCard_textContent">
<time date="2020-03" class="articleCard_date"> march 20th 20xx</time>
<h3 class="articleCard_title">This is an example of a really long heading that needs to span over multiple lines.</h3>
</div>
<a class="articleCard_readMore" href="/">read article</a>
</section>
</div>
you have to give the .articleCard_image position relative to make sure that the category does not overflow and then give the .articleCard_category absolute position and give a full width and height and display block to the img in order to take the entire space
.articleCard_container {
width: 55.7rem;
height: auto;
.articleCard_image {
width: 100%;
height: auto;
position: relative;
img{
display: block;
height: 100%;
width: 100%;
}
.articleCard_category {
position: absolute;
bottom: 4rem;
left: 3rem;
display: flex;
align-items: center;
text-transform: uppercase;
font-size: 1.4rem;
color: var(--white);
width: 100%;
p {
font-weight: 600;
}
.thumbtack {
margin-right: 1rem;
margin-bottom: 1rem;
}
.purpleRose {
width: 100%;
display: block;
}
}
}
.articleCard_textContent {
box-sizing: border-box;
padding: 1rem 3rem 5rem 3rem;
width: 100%;
margin: 0;
background-color: var(--white);
.articleCard_date {
color: var(--articleDate);
text-transform: uppercase;
font-size: 1.2rem;
}
.articleCard_title {
margin-top: 1rem;
font-size: 1.6rem;
width: 100%;
color: var(--articleTitle);
font-weight: 700;
}
}
.articleCard_readMore {
text-transform: uppercase;
color: var(--buttonPrimary);
font-size: 1.2rem;
font-weight: 600;
position: relative;
bottom: 2rem;
left: 3rem;
// display: none;
}
}
.articleCard_container:hover {
.articleCard_readMore {
display: block;
box-sizing: border-box;
text-decoration: none;
}
}
I'm trying to create a horizontal/scrollable nav with gradient fades on each end. Setting the parent to overflow: auto almost solves my problem but hides my active link border, which I position absolute as a :before pseudo above its parent link. I was wondering if there was a way for me to keep the overflow while having my pseudo border break out of it? For the sake of this question, the gradient really doesn't matter per se but this structure needs to remain in tact.
ul {
margin: 0;
}
li {
display: inline-block;
}
.vertical-title {
height: 55px;
margin-bottom: 13px;
border-bottom: 3px solid #dceaec;
font-size: 22px;
line-height: 57px;
color: #111;
text-align: center;
text-transform: uppercase;
}
.vertical-title-wrapper {
padding: 0;
z-index: 0;
position: relative;
}
.hub-nav {
display: block;
padding: 0 15px;
width: 100%;
z-index: 1;
white-space: nowrap;
overflow: auto;
}
.hub-nav-link {
position: relative;
}
.hub-nav-link.active-path:before {
content: "";
display: block;
height: 3px;
width: 100%;
left: 0;
position: absolute;
top: -16px;
background-color: #007eff;
}
<div class="hub-wrapper">
<div class="vertical-title">
Page Title
</div>
<nav class="hub-nav">
<ul class="hub-nav-list">
<li class="hub-nav-list-item">
<a class="hub-nav-link active-path" href="">
There's supposed to be a border above me!
</a>
</li>
</ul>
</nav>
</div>
<div>
Content Below
</div>
Negative margins will do the trick:
ul {
margin: 0;
}
li {
display: inline-block;
}
.vertical-title {
height: 55px;
margin-bottom: 13px;
border-bottom: 3px solid #dceaec;
font-size: 22px;
line-height: 57px;
color: #111;
text-align: center;
text-transform: uppercase;
}
.vertical-title-wrapper {
padding: 0;
z-index: 0;
position: relative;
}
.hub-nav {
display: block;
padding: 0 15px;
width: 100%;
z-index: 1;
white-space: nowrap;
overflow: auto;
padding-top: 16px;
margin-top: -16px;
}
.hub-nav-link {
position: relative;
}
.hub-nav-link.active-path:before {
content: "";
display: block;
height: 3px;
width: 100%;
left: 0;
position: absolute;
top: -16px;
background-color: #007eff;
}
<div class="hub-wrapper">
<div class="vertical-title">
Page Title
</div>
<nav class="hub-nav">
<ul class="hub-nav-list">
<li class="hub-nav-list-item">
<a class="hub-nav-link active-path" href="">
There's supposed to be a border above me!
</a>
</li>
</ul>
</nav>
</div>
<div>
Content Below
</div>
So that you don't have to look for too long - I added these two lines into your snippet:
.hub-nav {
padding-top: 16px;
margin-top: -16px;
}
So I am styling this horizonal line with the idea of image and text in the middle and got stuck. How could I align the image on the left side of "TEXT" and not under it? Here's the link to demonstrate the current state:
http://codepen.io/anon/pen/MJWJad
Appreciate all the help.
.horizontal__rule--modified {
line-height: 1em;
position: relative;
border: 0;
color: #666666;
text-align: center;
height: 1.5em;
opacity: 0.7;
letter-spacing: 1px;
font-size: 16px;
&:before {
content: url(http://www.metalguitarist.org/forum/images/mgtwitter.png);
background: red;
position: absolute;
left: 0;
top: 50%;
width: 100%;
height: 2px;
}
&:after {
content: attr(data-content);
position: relative;
display: inline-block;
color: black;
padding: 0 .5em;
line-height: 1.5em;
color: red;
background-color: #fcfcfa;
}
}
<hr class="horizontal__rule--modified" data-content="TEXT">
Actually you don't need a <hr /> at all here. You can just use pseudo elements and make it possible:
* {
font-family: 'Segoe UI';
font-weight: normal;
}
h1 {
text-align: center;
}
h1 span {
background-color: #fff;
padding: 15px;
}
h1::after {
display: block;
content: "";
border: 1px solid #ccc;
margin-top: -0.5em;
}
<h1><span>Hello</span></h1>
If an image is needed for this like having a twitter icon, you can use: Source:
* {
font-family: 'Segoe UI';
font-weight: normal;
vertical-align: middle;
}
h1 {
text-align: center;
font-size: 14pt;
}
h1 span {
background-color: #fff;
padding: 15px;
}
h1::after {
display: block;
content: "";
border: 1px solid #ccc;
margin-top: -0.5em;
}
<h1>
<span>
<img src="http://www.metalguitarist.org/forum/images/mgtwitter.png" alt="" />
Hello
</span>
</h1>
Preview
Another solution apart from Praveen's is to use flex-box.
HTML
<div class="wrapper">
<div class="line"></div>
<div class="text">
Test
</div>
<div class="line"></div>
</div>
CSS
.wrapper {
display: flex;
justify-content: space-between;
align-items: center;
}
.line {
height: 10px;
background: black;
width: 100%;
}
.text {
padding: 0 10px;
}
fiddle: https://jsfiddle.net/jdgqmmv5/
I am trying to hover a text in an image. If I set a background color for the text it is not working. It will work if I use position: absolute; but it is hovering my header too.
.comimg {
width: 100%;
height: 75%;
}
.tren {
margin-top: -250px;
margin-bottom: -300px;
text-align: center;
margin-left: auto;
margin-right: auto;
background-color: aqua;
overflow: none;
}
.trust p {
margin-top: -19;
font-size: 10px;
font-weight: bolder;
color: #424242;
}
.comimg p {
font-family: 'Open Sans', sans-serif;
width: auto;
height: auto;
font-size: 2em;
color: aliceblue;
background-color: aqua;
font-weight: 900;
}
.comimg img {
width: 100%;
height: 100%;
}
<div class="comimg">
<img src="img/6042013705_eb32ce58fa_o.jpg" />
<div class="tren">
<p>#trending</p>
</div>
</div>
Based on my understanding you can achieve that effect using CSS and HTML.
I'm using :hover selector on the .wrapper div, in order to apply different styles based on the result I want to achieve.
EXAMPLE
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font-family: Helvetica, sans-serif;
}
main {
width: 600px;
margin: 0 auto;
}
.wrapper {
height: 100vh;
width: 100%;
background: url('http://lorempixel.com/500/500/abstract') no-repeat;
background-size: cover;
display: table;
}
.wrapper:hover {
background: #fda;
}
.wrapper:hover p {
background: #345;
display: block;
}
p {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
font-size: 2.4em;
display: none;
}
<main>
<div class="wrapper">
<p>
#trending
</p>
</div>
</main>