Highlighting a tag using CSS - html

I have an HTML tag I created using CSS3. I would like to 'highlight' a particular tab. Ideally, I'd like to have a glow around the tag that shows it is active. I'm using ':after' to create the shape of the tag, but this doesn't allow me to highlight around the actual shape.
Here's a Fiddle:
http://jsfiddle.net/nocztpxv/2/
HTML
<a href="#" class="tag">
InsertHTML
</a>
CSS
.active{
border: 1px solid rgb(246, 255, 0);
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.05) inset, 0px 0px 8px rgba(255, 252, 14, 0.6);
}
As you can see, the highlight is around everything except the arrow/triangle part. Does anyone know how I could have the same highlighted look around the arrow/triangle as well?

There is one solution that I can think of, but requires slight modification to your DOM. The solution is by wrapping the link text within a <span> element, and then instead of using borders for the triangle, we will use a rotated rectangle for that effect. However, since the background has to be higher up in the z-index than the rotated rectangle, nesting is needed (so that we declare the blue background on the <span> element instead.
See fiddle here: http://jsfiddle.net/teddyrised/nocztpxv/6/ For a three-dimensional visualisation of the stack, see here: http://jsfiddle.net/teddyrised/nocztpxv/8/
As there are only two pseudo-elements possible and you are using both ::before and ::after for stylistic purposes already, we can only use an additional level of nesting:
<a href="#" class="tag">
<span>InsertHTML</span>
</a>
<a href="#" class="tag active">
<span>InsertHTML</span>
</a>
<a href="#" class="tag">
<span>InsertHTML</span>
</a>
For the CSS (note: you might want to add vendor prefixes to the CSS transform property):
.tag {
font-family: Helvetica, Arial, sans-serif;
display: inline-block;
color: #fff;
position: relative;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
margin: 0 30px 0 0;
text-decoration: none;
}
/* The rotated square */
.tag::after {
background-color: #588fe5;
display: block;
height: 27px;
width: 27px;
position: absolute;
top: 6px;
right: -13px;
content: "";
transform: rotate(45deg);
z-index: 1;
}
/* Nested span */
.tag > span {
display: inline-block;
background-color: #588fe5;
position: relative;
padding: 10px;
z-index: 2;
}
/* The white dot */
.tag > span::before {
background: #fff;
width: 10px;
height: 10px;
content: "";
display: inline-block;
border-radius: 20px;
margin: 0 5px 0 0;
}
/* Hover effects */
.tag:hover::after, .tag:hover > span {
background-color: #739fe4;
}
/* Active tag */
.tag.active, .tag.active::after {
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.05) inset, 0px 0px 8px rgba(255, 252, 14, 0.6);
}

Related

span in container is breaking border radius rule leveraged in conjunction with first child pseudo selector

I have two anchor tags that have border radius rules, but they're applied with the parameters first-child and last child pseduo selectors, so that the both of them together look kind of like a "pill"
See an example below:
.tc__timezone-toggle {
display: flex;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui:first-child {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
Now, what I need to now is add in some next to the left of this pill shaped UI that says a message - what I'm finding is for some reason it renders the border radius on the first child broken.
See below:
.tc__timezone-toggle {
display: flex;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui:first-child {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
Border-radius doesn't affect inner elements
The way that I understood this question, having elements next to border radiuses can have impacts.
So from the answer I tried:
#outer { overflow: hidden; }
In context of my problem this is the result:
.tc__timezone-toggle {
display: flex;
/* from answer */
overflow: hidden;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui:first-child {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
This did not work.
CSS Flexbox Border Radius with text-overflow: Ellipsis
This implies that you can;'t use span in conjunction with border radius.
Since the link above talks about li, I tried div and p with no luck.
I tried to find the problem (I think I'm having with the span inside a flexbox and a border radius) I'm having here but couldn't find any helpful resources relevant to what I'm dealing with:
Perfectly rouded border-radius for flexbox items
Border radius issue with div
Why is the span tag breaking my border radius?
So pretty sure your issue is that you are using the :first-child selector on an element that is not the first child among it's siblings. When you remove that first-child psuedo-class everything works. Alternatively if you want to be very specific you can instead use first-of-type which would be true for that first element. To clarify, the span is the first child in the .tc_timezone_toggle div.
.tc__timezone-toggle {
display: flex;
/* from answer */
overflow: hidden;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
.tc__timezone-toggle-ui {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>
When you add in the span element it becomes the first child, the first part of the 'pill' is no longer the first child so it doesn't receive the border radius settings.
To get round this and remain fairly general you could use first-of-type, the type being a.
.tc__timezone-toggle {
display: flex;
/* from answer */
overflow: hidden;
}
.tc__timezone-toggle-ui {
display: block;
font-weight: 700;
color: var(--tc-blue) !important;
background-color: #E3E3E3;
padding: 10px;
}
a.tc__timezone-toggle-ui:first-of-type {
border-radius: 22px 0px 0px 22px;
}
.tc__timezone-toggle-ui:last-child {
border-radius: 0px 22px 22px 0px;
}
<div class="tc__timezone-toggle">
<span>TimeZone</span>
<a class="tc__timezone-toggle-ui" href="#">PT</a>
<a class="tc__timezone-toggle-ui" href="#">ET</a>
</div>

How to make a border left with custom bullet for my list, in a gradient style?

This is what I want to achieve:
Items with white background are my list items. On the left side I want to have a border, with custom bullets (custom, since we cannot change the default list bullet color -black- AFAIK). The upper part of the border should have a gradient color, from transparent to grey color for instance. As you also see in the pic, the length of the border should be longer than the actual list height (until the plus button, not till the last item ends.)
I have actually achieved some parts but i would like to know a better, cleaner way of doing it.
This is what I have so far: https://jsfiddle.net/6esLm8q1/
.list {
list-style: none;
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(179,179,179)) 0 0 0 1;
}
.item {
margin-bottom: 1em;
margin-left: -1.7em;
}
.item::before {
content: "\2022";
color: grey;
font-weight: bold;
display: inline-block;
width: 1em;
margin-left: -1em;
}
<ul class="list">
<li class="item">
Test1
</li>
<li class="item">
Test2</li>
</ul>
<button>Plus
</button>
Problems are still: Aligning of bullets to item text, even if I align the bullets on the border, when I resize the window, the bullets slides to left or right slightly.
The gradient line is far more transparent at the beginning, not actually like in the "Target" pic. And the border ends where the list items end, so it does not reach until the button.
I appreciate any help till I get something close to my target pic!
You got yourself 99% there. For the linear-gradient, if you define the end-point to be lower than 100%, then you get it to fade earlier. Otherwise, it calculates the end point to be 100% and thus half of your border looks faded.
For the before psuedo-element, since in your markup you put a p tag within each li, you should put the pseudo-element on the p tag itself.
See the snippet below.
.list {
list-style: none;
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(179,179,179) 40%) 0 0 0 1; /* add % to have gradient end earlier than end */
}
/* add before pseudo-element on p tag (since you include it in your markup */
.item>p:before {
content: "\2022";
color: grey;
font-weight: bold;
margin-left: -2.7em;
}
<ul class="list">
<li class="item">
<p>
Test1
</p>
</li>
<li class="item">
<p>
Test2
</p>
</li>
</ul>
<button>Plus</button>
I think your solution is already pretty good. I would create the circles with border-radius, as you have more control over the sizing and position.
Here is an example:
.list {
list-style: none;
border-width: 2px;
border-style: solid;
border-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(179, 179, 179)) 0 0 0 1;
margin: 0 0 0 1em;
}
.item {
position: relative;
}
.item:before {
position: absolute;
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background-color: grey;
left: -2.75em;
top: .4em;
}
button {
display: inline-block;
width: 2em;
height: 2em;
margin: -.2em 0 0 .25em;
border-radius: 50%;
background: #c00;
color: white;
border: none;
}
<ul class="list">
<li class="item">
<p>Test1<br>test with line break</p>
</li>
<li class="item">
<p>Test2<br>test with<br>two line breaks</p>
</li>
</ul>
<button>+</button>
<ul class="list">
<li class="item">
<p>Test1</p>
</li>
<li class="item">
<p>Test2</p>
</li>
</ul>
<button>+</button>
Is it critical to be plain css? From my point of view you're trying to solve the issue with the wrong instruments.
What if you split the element, making the line on the left and the bullet with separate elements, positioned absolutely in the padding region of the container, and the content in subcontinent?
Something like this:
body {
background-color: #ededed;
}
.tail {
border-left-style: solid;
border-left-width: 2px;
border-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(179,179,179)) 0 0 0 1;
height: 20px;
margin-left: 20px;
}
.list {
font-size: 20px;
color: rgba(179,179,179);
list-style: disc;
border-left: 2px solid rgba(179,179,179);
margin: 0 0 0 20px;
box-sizing: border-box;
padding-bottom: 20px;
padding-left: 15px;
}
.item {
margin-bottom: 5px;
}
.item > div {
color: #555;
background-color: white;
padding: 5px;
font-size: 14px;
font-family: sans;
border-radius: 5px;
}
button {
border-radius: 50%;
background-color: #b30920;
border: none;
color: white;
box-sizing: border-box;
padding: 0;
width: 40px;
height: 40px;
overflow: hidden;
vertical-align: top;
font-size: 33px;
margin: 0;
}
<div class="tail"></div>
<ul class="list">
<li class="item"><div>Test1</div></li>
<li class="item"><div>Test2<br>test</div></li>
</ul>
<button>+</button>

How to enable a css tag only during hover?

I'm creating a badge notification using css, but I want to show it only during hovering of the outer element. It that possible?
<img src..><span class="badge">5</span></img>
The badge is created as follows from css:
/*#see http://cssdeck.com/labs/menu-with-notification-badges*/
img .badge {
display: block;
position: absolute;
top: -12px;
right: 3px;
line-height: 16px;
height: 16px;
padding: 0 5px;
font-family: Arial, sans-serif;
color: white;
text-shadow: 0 1px rgba(0, 0, 0, 0.25);
border: 1px solid;
border-radius: 10px;
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.08);
box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 1px rgba(0, 0, 0, 0.08);
background: #67c1ef;
border-color: #30aae9;
background-image: -webkit-linear-gradient(top, #acddf6, #67c1ef);
background-image: -moz-linear-gradient(top, #acddf6, #67c1ef);
background-image: -o-linear-gradient(top, #acddf6, #67c1ef);
background-image: linear-gradient(to bottom, #acddf6, #67c1ef);
}
Question: how can I show the badge only when hovering the specific img where the badge class is applied at?
For starters the img element is a standalone self-closing element and doesn't doesn't allow children elements. With that markup most browsers will convert your code to:
<img src... />
<span class="badge">5</span>
Some may also treat that </img> tag as a second img element.
Separating the img element from the span as shown above is what we firstly want to do anyway, so adjust your HTML to reflect that. Then we can implement the adjacent sibling combinator (+) so select our span element when the img element is being overed over:
img:hover + .badge {
...
}
Remember to hide the .badge element by default.
.badge {
display: none;
}
img:hover + .badge {
display: block;
}
<img src="http://placehold.it/320x140&text=Hover%20Here" />
<span class="badge">Hello, world!</span>
jQuery .hover() function can also do this, remember $(".badge").hide() when load the page.

Button with a bigger text centering issue

I´m trying to do some buttons with image and text, and I already did this work.
But now I´m studying a diferente hypothesis, If I have a text bigger I´m trying to center the text in the button but I´m not having sucess put this right. I´m not having succeess putting my very big is not good align-center just below the 1st text.
Have you ever had a case like this? How we can solve this?
I have this Html for two buttons:
<button class='btn'>
<img class="big_btn" src="icon1.png" width="40" height="40"/>
Big button so big <span> very big is not good</span>
</button>
<button class='btn'>
<img src="icon1.png" width="40" height="40">
2button big
</button>
And I have this css file:
.btn {
position: relative;
width: 180px;
height: 60px;
margin-top:7%;
padding: 0 10px 0 10px;
line-height: 37px;
text-align: left;
text-indent: 10px;
font-family: 'bariol_regularregular';
font-size: 15px;
color: #333;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
background: #f1f1f1; /* button background */
border: 0;
border-bottom: 2px solid #999; /* newsletter button shadow */
border-radius: 14px;
cursor: pointer;
-webkit-box-shadow: inset 0 -2px #999;
box-shadow: inset 0 -2px #999;
}
.btn:active {
top: 1px;
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
}
.btn img { float: left;}
.btn .big { margin-top:10px;}
.btn:hover { background-color: #f7f7f7;}
Here's the Fiddle: http://jsfiddle.net/3F9pu/
My image updated:
Your problem is your line-height attribute. If you set that to be 37px, each new line of text will be separated by 37px. Remove `line-height:37px and the text will wrap around the image.
line-height: 37px
I also removed your text-indent and replaced it with a margin on your floated image to make the text all align properly.
.btn img{
float:left;
margin-right: 10px;
}
text-indent: 10px
JSFiddle
Use a CSS background image.
Have a fiddle - Fiddle Link!
HTML
<button class='btn'>Big button so big very big is not good</button>
<button class='btn'>2button big</button>
CSS
.btn {
background: url("http://lorempixel.com/output/cats-q-c-40-40-3.jpg") #CCC 10px no-repeat;
border: none;
padding: 10px 10px 10px 60px;
width: 200px;
text-align: left;
vertical-align: top;
min-height: 60px;
cursor: pointer;
}
.btn:hover {
background-color: #F00;
}

CSS Tooltip has different position in different browsers. How can I account for this?

I have adjusted my bottom attribute to display how I want it in Firefox, but the spacing is all warped in Chrome and Safari. Is there a way to sett a different "top" attribute for each browser?
HTML
<a class="tooltip" href="#"> <!-- this tag activates my tool tip -->
<div class="handsevent" > <!-- this div contains everything that activates the tool tip when hovered over-->
<div class="handswrapper">
<div class="handshour" >
<h3>8:00am-noon</h3>
</div>
<div class="handsspeaker">
<h3>Speaker 3</h3>
</div>
</div>
<div class="handstitle">
<p>Description</p>
</div>
</div>
<span class="classic"> <!-- this span contains everything that pops up in the tool tip -->
<h3>Title Bar</h3>
<br />lots of descriptive text
</span>
</a>
CSS
/* HOVER WINDOW */
.tooltip {
color: #000000; outline: none; font-style:bold;
cursor: help; text-decoration: none;
position: relative;
}
.tooltip span {
margin-left: -999em;
position: absolute;
}
.tooltip:hover span {
border-radius: 30px 30px; -moz-border-radius: 30px; -webkit-border-radius: 30px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
font-family: Arial, Tahoma, Helvetica, sans-serif;
position: auto; left: 1em; top: 2em; z-index: 99; <!-- the 'top' attribute on this line is where I have been adjusting the display position it affects the position differently in different browsers -->
margin-left: 0; width: 700px; margin-top:-10px;
}
.tooltip:hover img {
border: 0; margin: -30px 0 0 90px;
float: right; position:fixed;
z-index: 99;
}
.tooltip:hover em {
font-family: Arial, Tahoma, Helvetica, sans-serif; font-size:14px; font-weight: bold; color:005DA4;
display: block; padding: -0.2em 0 0.6em 0;
}
.classic { padding: 0.8em 1em; }
* html a:hover { background: transparent; }
.classic {background: #ffffff; border: 1px solid #ffffff; }
I have tried pixels, em, and percentage. None of these have been consistent. Are there browser specific settings I could use?
here is a demo link for reference.
Using a CSS Reset will help to eliminate differences between browsers.
I switch the top attribute in ".tooltip:hover span" to "auto" and that seems to be working.