I try to put a line on only one word. With changing its size and its position.
Here the result I would like to have:
I tried to use a span with background-image but no success.
https://jsfiddle.net/XZKS/193u9dam/
And other problem, background-image don't work when using local image.
My website arborescence:
_include
css
style.css
js
img
line.png
background-image: url("../img/line.png");
I hope someone could help me, thanks
Try this:
.myWordWithLine {
position: relative;
}
.myWordWithLine::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: -1;
height: 24px; // your line height
background-color: red; // your line color
}
Method #01:
You can use css linear-gradient() to draw this background:
Steps:
Create background image with linear-gradient().
Adjust its size with css background-size property.
Place it at the bottom position of the element with background-position css property.
Necessary CSS:
.line {
background: linear-gradient(to right, green, green) no-repeat;
background-size: 100% 5px;
background-position: left bottom 5px;
}
h3 {
font-size: 24px;
}
.line {
background: linear-gradient(to right, green, green) no-repeat;
background-size: 100% 5px;
background-position: left bottom 5px;
position: relative;
padding-top: 0;
padding-bottom:0;
}
<h3>MY <span class="line">BLOG</span></h3>
Method #02:
You can use ::before OR ::after pseudo element:
h3 {
font-size: 24px;
}
.line {
position: relative;
}
.line::after {
background: green;
position: absolute;
bottom: 5px;
z-index: -1;
content: '';
left: 0;
right: 0;
height: 5px;
}
<h3>MY <span class="line">BLOG</span></h3>
You can use this
http://codepen.io/B101844/pen/bgLPPb
html
<div class="main">MY
<div class="blog">
BLOG
<div class="underline"></div>
</div>
</div>
Css
.main{
font-size: 30px;
color: #1c3d93;
font-weight: 900;
}
.blog{
display: inline-block;
position: relative;
}
.underline{
position: absolute;
background-color: #91dfcf;
left: 0px;
right: 0px;
bottom: 7px;
z-index: -1;
height: 8px;
}
Related
I'm trying to get a repeating background image over my rebecca-purple background color for my jumbotron. I know I'm doing something wrong, just don't know what it is. Here's the code:
.jumbotron {
background-color: rebeccapurple;
color: white;
width: auto;
height: 350px;
margin-bottom: 100px;
position: relative;
display: block;
font-family: FontAwesome;
}
.jumbotron::after {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(\images\bg_images\maze_white.png) repeat center center;
z-index: -1;
}
All help is appreciated. Thank you.
Your maze is behind the jumbotron due to z-index:-1. What you need to do is swap the backgrounds around, like in this fiddle http://jsbin.com/tekefobive/edit?css,output
.jumbotron {
background-image:url('pattern');
...
}
.jumbotron:after{
background:purple;
z-index:-1;
...
}
// Try This
.jumbotron {
background: url("IMAGE PATH") rebeccapurple repeat center center;
color: white;
width: auto;
height: 350px;
margin-bottom: 100px;
position: relative;
display: block;
font-family: FontAwesome;
}
Is there a way using HTML to add an overlay using an image url in a specific div?
I managed to make something work using CSS :
#myDiv {
width: 100%;
height: 100%;
background: url(image.jpg) no-repeat;
}
#myDiv:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: transparent url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .6;
}
But it is a bit tricky. When I tried to do the same for other divs, it did not work. So for instance I have this CSS code for a div :
.hi-icon-wrap img
{
border-radius: 80px;
width: 153px;
height: 153px;
margin:2%;
}
and I want to add an overlay. I am using this script but with no success:
.hi-icon-wrap img:before {
background: transparent url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .6;
}
and I also tested that :
.hi-icon-wrap img:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: transparent url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .6;
}
UPD:
HTML script:
<div class="hi-icon-wrap" class="hi-icon-wrap img" style="text-align: center">
<img src="image.png">
</div>
You should use overlay on div element and not on img
#myDiv {
position: relative;
display: inline-block;
border-radius: 80px;
overflow: hidden;
}
#myDiv:before {
content: '';
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(http://tympanus.net/Tutorials/CSS3FullscreenSlideshow/images/pattern.png) repeat top left;
opacity: .8;
}
img {
vertical-align: top;
}
<div id="myDiv">
<img src="http://placehold.it/150x150/D6E7FF/ffffff">
</div>
Edit: You can't use :after or :before on img as you can see here Demo because image elements don't contain text or have descendants, so what you can do is wrap img in div for example and then you get this Demo
I have a project where there will be two triangles, one of each side, as the images below shows, I am having difficulty in, first of all, getting each one on correct side, I have been trying using floats but it is not working.
And then making them align with the white zone irrespective of screen size i.e. responsive.
#anim {
position: relative;
height: 100%;
min-height: 100%;
background-image: url("http://i.imgur.com/rxks29H.jpg");
background-image: no-repeat;
background-size: 100%;
}
#anim img {
position: relative;
height: 100%;
width: 100%;
}
.arrow-left {
position: absolute;
width: 0;
height: 0;
width: 200px;
border-top: 200px solid transparent;
border-bottom: 200px solid transparent;
z-index: 3;
top: 30%;
border-left: 200px solid green;
}
.arrow-right {
position: absolute;
width: 200px;
float: right;
z-index: 3;
border-top: 200px solid transparent;
border-bottom: 200px solid transparent;
top: 30%;
border-right: 200px solid blue;
}
<section id="anim">
<img src="http://i.imgur.com/ucQ3ZXl.png">
<div class="arrow-right">
</div>
<div class="arrow-left">
</div>
</section>
Why not make the arrows part of the background image to insure that it's always in place no matter the screen size, and then the content in each arrow can be positioned on top an if it moves a little it wont break the background itself. I created the background really fast to illustrate what I mean, feel free to re-create the image yourself if needed.
to position the text in each arrow change the CSS to this:
float: left or float: right don't work with position: absolute you need to use the left and right properties.
#anim {
position: relative;
height: 100%;
min-height: 100%;
background-image: url("http://i.imgur.com/rxks29H.jpg");
background-image: no-repeat;
background-size: 100%;
}
#anim img {
position: relative;
height: 100%;
width: 100%;
}
.arrow-left {
padding: 2.5% 15px;
text-transform: uppercase;
position: absolute;
width: 13%;
left: 0;
z-index: 3;
top: 36%;
}
.arrow-right {
padding: 2.5% 15px;
text-transform: uppercase;
position: absolute;
width: 13%;
right: 0;
z-index: 3;
top: 36%;
}
.arrow-right h2 {
font-size: 28px;
color: #FFF;
}
.arrow-left h2 {
font-size: 28px;
color: #FFF;
}
<section id="anim">
<img src="http://i.stack.imgur.com/Fbhc4.png">
<div class="arrow-right">
<h2>Scouting For Companies</h2>
</div>
<div class="arrow-left">
<h2>Seeking For Ideas</h2>
</div>
</section>
You will need to add some rules for smaller screens and really large ones if you are making the site responsive.
** Edit **
I added the animation really quick just to illustrate what you need to do and give you a good head start on it.
Here is a JSFIDDLE.
Trying to use sass to position a sprite: CodePen Link. I want to have each card show, but I can only get the visa one to show using the &:before method. Can I not nest .visa/.mastercard/.amex in &:before?
<div class="saved_cc_block">
<div class="saved_cc">
<a class="cc_img visa"></a>
</div>
<div class="saved_cc">
<a class="cc_img mastercard"></a>
</div>
</div>
.cc_img {
position: relative;
height: 26px;
left: 9px;
padding-left: 50px;
&:before {
content: "";
position: absolute;
width: 41px;
height: 26px;
top: 50%;
left: 0;
background: url('http://i.imgur.com/3zRD5fn.png') no-repeat;
.visa {
background-position: 0;
}
.mastercard {
background-position: -51px 0;
}
.amex {
background-position: -102px 0;
}
}
}
:before is a pseudo element, you can't nest other elements within it. I think you probably want to structure your css like this:
.cc_img {
position: relative;
height: 26px;
left: 9px;
padding-left: 50px;
&:before {
content: "";
position: absolute;
width: 41px;
height: 26px;
top: 50%;
left: 0;
background: url('http://i.imgur.com/3zRD5fn.png') no-repeat;
}
}
.visa:before {
background-position: 0;
}
.mastercard:before {
background-position: -51px 0;
}
.amex:before {
background-position: -102px 0;
}
No, you can't.
The elements with those class names are children of the cc_img div, not of the generated pseudo-element that appears before it. Psuedo-elements can't have child nodes.
Look at generating the psuedo-element before the link instead of before the div.
I am wanting to construct navigation items from three (background) images, with the first and last a fixed width, and the central a variable width, depending on the width of the text in the nav item. I have been led to believe that using the pseudo elements before and after would be the best method. When I try this though, the main (central) background image for the nav item is overlapping with the before and after background images.
You can see what I mean on this page.
Here is the CSS:
.box {
background-image: url(nav/images/nav_02.png);
background-repeat: repeat;
height:20px;
position: absolute;
padding: 10px 13px;
}
.box:before {
left: 0;
background-image: url(nav/images/nav_01.png);
}
.box:after {
right: 0;
background-image: url(nav/images/nav_03.png);
}
.box:before,
.box:after {
content: ' ';
width: 13px;
height:40px;
position: absolute;
top: 0;
background-repeat: no-repeat
}
And the HTML:
<div class="box">here is some text</div>
Can I use background-images in this way using pseudo elements?
Thanks,
Nick
Yes, but you will have to use left and right attributes for moving the pseudo elements in the right position. padding is not correct for the main box to position. Better use margin.
.box {
background-repeat-x: repeat;
background-image: url(nav/images/nav_02.png);
background-repeat: repeat;
height: 40px;
position: absolute;
margin: 0 13px;
line-height: 40px;
}
.box:before, .box:after {
content: ' ';
display:block;
width: 13px;
height: 40px;
position: absolute;
top: 0;
background-repeat: no-repeat;
}
.box:before {
left: -13px;
background-image: url(nav/images/nav_01.png);
}
.box:after {
right: -13px;
background-image: url(nav/images/nav_03.png);
}