When using text-decoration on a link, the child element (span) is not included, so then the underline doesn't extend:
a {
font-size: 36px;
text-decoration: underline dotted rgb(221, 221, 221);
color: #000;
}
a:hover {
text-decoration: none;
color: #000;
}
.badge-dark {
font-size: 9px;
margin-left: 2px;
position: relative;
text-align: center;
top: -5px;
}
<a href="#">
My title is here
<span class="badge badge-dark">Special</span>
</a>
See fiddle
Is it possible for the span to be included or is text-decoration ignoring spans by design?
https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration:
The text-decoration shorthand CSS property sets the appearance of decorative lines on text.
This means that the underline will be directly under the text in question and not under the element. If you zoom in enough, you will see the underline is actually under the word special
If you want to continue the line under special, perhaps you could use a pseduo element for your badge and add some non-breaking spaces for it to sit in:
a {
font-size: 36px;
text-decoration: underline dotted rgb(221, 221, 221);
color: #000;
}
a:hover {
text-decoration: none;
color: #000;
}
.badge {
display: inline-block;
position: relative;
text-decoration: underline dotted rgb(221, 221, 221);
}
.badge-dark:after {
content: 'Special';
display: inline-block;
color: #ffffff;
background: #555555;
padding: 3px 5px;
border-radius: 5px;
font-size: 9px;
position: absolute;
text-align: center;
right: 5px;
top: 50%;
transform: translateY(-50%);
margin-top: -5px;
}
<a href="#" class="badge badge-dark">
My title is here
</a>
You can apply text-decoration to your span, however it will appear just under the span text and not inline with the preceding text. To make it inline you will need to make your span the same height as its parent container. Alternatively you can likely use a pseudo element (:before or :after) to put the line where you want it.
This happens because of the CSS specification that basicly say, you can't have text-decoration in inline block elements. If you span to also be affected by text-decoration, you must change the display:inline-block. Further information can be found in this question .
Just to show you , how it would work, if the span was being effected by the text-decoration, here is an example:
a {
font-size: 36px;
text-decoration: underline dotted rgb(221, 221, 221);
color: #000;
}
a:hover {
text-decoration: none;
color: #000;
}
.badge-dark {
font-size: 20px;
margin-left: 2px;
position: relative;
text-align: center;
top: -5px;
}
<a href="#">
My title is here
<span class="badge badge-dark">Special</span>
</a>
Also, in the code you posted in SO, the text-decoration property is working properly, just not in the fiddle. If you want it to be equal through the whole link, try using border instead.
You can use border-bottom property instead of text-decoration.
also see that I have changed the a to an inline-block element.
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
padding: 10px;
}
.title-link {
display: inline-block;
font-size: 36px;
border-bottom: 4px dotted rgb(221, 221, 221);
color: #000;
text-decoration: none;
}
.title-link:hover {
border-bottom: none;
color: #000;
text-decoration: none;
}
.badge-dark {
font-size: 9px;
margin-left: 2px;
position: relative;
text-align: center;
top: -5px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col">
<a class="title-link" href="#">My title is here
<span class="badge badge-dark">Special</span></a>
</div>
</div>
</div>
The font size of the content in the badge is different from the other link text and you also have an alignment of top:-5px. These two break the line and even without using the bootstrap badge you would get the text-decoration broken. Yes it would extend to the span text but be broken and it would not be what you want. And bootstrap badge also has the style of text-decoration: none...
Another way of getting the dotted underline to extend the badge is removing the text-decoration and using border-bottom like this below:
a {
font-size: 36px;
border-bottom: 3px dotted rgb(221, 221, 221);
color: #000;
}
a:hover {
color: #000;
border-bottom: none;
}
Related
I've been attempting to build the following (figma):
As it stands i've tried padding, margins, psudeo elements, whitespaces and I'm pretty stuck on what to do. You can see its possible to have the underline styles on the icon, but when I create distance from 'ID', the underline gap appears. I need the icon to stay as far away as it is here but also keep the underline crossing.
HTML: Please note 'input-row' cannot be styled in this instance as it's used across other elements
<div class="input-row">
<a class="link" href="#">Acceptable Forms of ID <i class="fas fa-share-square"></i></a>
</div>
.fa-share-square{
font-size: 0.75rem;
cursor: pointer;
color: $secondary-five;
font-size: 1rem;
text-decoration: underline dotted $secondary-five;
text-underline-offset: .5rem;
text-decoration-thickness: 2px;
}
.link{
color: $secondary-five;
font-size: 1rem;
text-decoration: underline dotted $secondary-five;
text-underline-offset: .5rem;
text-decoration-thickness: 2px;
}
Thanks for your help.
You have a input-row container around these 2 elements,
Add the underline to the container, use margin and or padding to get it right under the text.
Revised Answer
It appears that I had misunderstood your original request. I now understand that you want the underlined (dots) to appear uniformly for the anchor including the space between the text and the Font Awesome icon.
This is more simple than the previous answer.
You will first need to remove the default text-under line from HTML anchors, this is done in the a.link CSS below.
Then you style the anchor as an inline-block/block level element (which it is by default), and style a border rather than text-underline, because text-underline won't (and symantically shouldn't) activate on a lack of text (whitespace). You can also customise the gap between the text and the underline using padding.
So:
HTML:
<div class="input-row">
<a class="link" href="#">Acceptable Forms of ID <i class="fas fa-share-square"></i></a>
</div>
And then you set your CSS styling thus:
CSS:
.fa-share-square{
font-size: 0.75rem;
cursor: pointer;
color: $secondary-five;
font-size: 1rem;
}
a.link {
color: #900;
font-size: 1rem;
text-decoration: none;
padding-bottom: 2px;
border-bottom: 2px dotted #00F;
}
Full example:
.fa-share-square{
font-size: 0.75rem;
cursor: pointer;
color: #900;
font-size: 1rem;
}
a.link {
color: #900;
font-size: 1rem;
text-decoration: none;
padding-bottom: 3px; /* Set the border distance from the text */
border-bottom: 3px dotted #00F; /* Set the border style */
}
.fa-share-square {
width: 3rem;
height: 1rem;
padding-left:1rem;
}
<p>(Extra CSS put in place to show the Font Awesome Icon part)</p>
<div class="input-row">
<a class="link" href="#">Acceptable Forms of ID
<i class="fas fa-share-square">ICON</i></a>
</div>
Manual Reference for CSS Border-bottom.
I had a stroke of genius in the shower. Line spacing.
At first I tried this on the Icon, but the spacing moved the underline to the right, so I needed to apply it to the letter beforehand.
Here you can see my changes and result.
<div class="input-row">
<a class="link" href="#">Acceptable Forms of I<span>D</span> <i class="fas fa-share-square"></i></a>
</div>
.link{
color: $secondary-five;
font-size: 1rem;
text-decoration: underline dotted $secondary-five;
text-underline-offset: .5rem;
text-decoration-thickness: 2px;
font-weight: bold;
}
span{
letter-spacing: 12px;
}
Some minor issues with the dots overlapping each other at certain spacing values, but this is a lot closer to a solution than anything else
You can simply remove text-decoration from your css and update as follows. Also set text-decoration:none for the .link class. Finally set border-bottom for the class input-row and width:fit-content. I am using color:red, you can use of your own choice.
HTML code:
<div class="input-row">
<a class="link" href="#">Acceptable Forms of ID <i class="fas fa-share-square"></i></a>
</div>
Updated CSS:
.fa-share-square {
font-size: 0.75rem;
cursor: pointer;
color: red;
font-size: 1rem;
/*text-decoration: underline dotted red;
text-underline-offset: .5rem;
text-decoration-thickness: 2px;*/
}
.link {
color: red;
font-size: 1rem;
text-decoration: none;
/*text-decoration: underline dotted red;
text-underline-offset: .5rem;
text-decoration-thickness: 2px;*/
}
.input-row {
border-bottom: 2px dotted red;
width: fit-content;
}
I'm using this drop-down menu and it comes down aligned with the button on the left but I want it to come down the opposite way because it's going off the screen on mobile. I attached pictures to show what it is doing vs what I am trying to make it do.
<div class='dropdown'>
<button class='dropbtn'>Hi, Anthony ▼</button>
<div class='dropdown-content'>
<a href='index.php?c=my-profile'>My Golfer Profile</a>
<a href='index.php?c=my-schedule'>My Schedule</a>
<a href='index.php?c=account-settings'>Account Settings</a>
<div style='width:100%;border-bottom: 1px #000 dotted;'> </div>
<a href='actions/logout.php'>Logout</a>
</div>
</div>
.dropbtn {
background-color: #3D5C7F;
color: white;
padding: 12px;
font-size: 14px;
border: none;
cursor: pointer;
border-radius: 3px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3D5C7F;
}
what it does
what I need it to do
As you do not posted your HTML code I don't know which class is applied on your dropdown's starting element. If dropdown-content class is applied on the dropdown's starting element add the following styles along with the styles you already applied on the class dropdown-content:
.dropdown-content {
right: 0;
left: auto;
}
If you will post your HTML as well we could better help.
I am not sure which class that is so I will give you an idea. The way I do it is that I position the dropdown absolute and position the parent element relative. When you do this , you can give it top and sides. In order to achive your position .. If you put the relative position to your whole navigation and dropdown will be absolute, you can give the dropdown something like top: 40px , right: -30px ... Hope this makes sense , if not , post some HTML and we will make it work.
I am working on a navbar in HTML. I don't understand why the elements do not line up nicely within the navbar.
body {
background-color: #ECEFF1; /* Blue Gray 50 */
font-family: 'Roboto', sans-serif;
margin: 0;
}
#header {
background-color: #ba68c8; /* Purple 300 */
color: #ffffff; /* White */
height: 24px;
padding: 8px;
}
.header-link {
font-size: 24px;
text-decoration: none;
}
<div id="header">
<a class="header-logo" href="#">
<img src="http://www.sigmacubes.com/img/logo_h.svg" height="24" />
</a>
<a class="header-link" href="#">
Text
</a>
</div>
Although the svg is aligned vertically, the text does not stay aligned vertically. Why is this happening?
What you can do is reduce the header-link font size to 20px and give it position absolute
.header-link {
font-size: 20px;
text-decoration: none;
position: absolute;
}
Or if you want to keep the size 24px you better give it margin-top: -5px too
.header-link {
font-size: 24px;
text-decoration: none;
position: absolute;
margin-top: -5px;
}
Is vertical-align:middle; an option for your header-link class?
Maybe add display: table-cell; in conjunction with vertical-align:middle; if that further matches the look that you wanted.
I want to create an icon that looks like a circle with a "plus" icon inside and right below it a descriptive p tag.
For I reason I cannot figure out doing this completely breaks the whole block. What am I doing wrong?
jsfiddle
Here's the HTML:
<div class="follow-single">
<div class="follow-wrapper">
<a class="follow" id="#follow_4" rel="nofollow" data-method="put" href="/jessie/follow">
<span class="glyphicon glyphicon-plus"></span>
<p class="title">Unfollow</p>
</a>
</div>
</div>
And the CSS:
follow-single {
max-width: 360px;
margin: 0 auto;
border-top: 1px solid #ddd;
margin-top: 20px;
padding-top: 20px;
}
.follow-single .follow-wrapper {
text-align: center;
}
.follow-single .follow-wrapper .follow {
color: #3c763d;
background-color: #dff0d8;
border: 1px solid #d6e9c6;
padding: 10px 17px;
border-radius: 4px;
}
.follow-single .follow-wrapper a {
text-decoration: none;
}
.follow-single .follow-wrapper .title {
font-size: 12px;
display: block;
}
Set the display on the achor tag to be inline-block.
.follow {
display: inline-block;
}
Fiddle
Additionally, an unrelated to the original question, your definition of follow-single is missing a leading dot character: .follow-single
I would like to be able to adjust the position of the map type control. I have it set to top right however I need to drop it by about 50 pixels. I read on custom controls you can pad the DIV, what about non custom controls? Can I extend the control?
Below is the HTML generated by the API for the control:
<div class="gmnoprint" style="margin: 5px; z-index: 11; position: absolute; cursor: pointer; text-align: left; top: 0px; right: 0px;">
<div style="width: 80px; position: relative; overflow: hidden; border: 1px solid black;">
<div style="color: black; font-family: Arial,sans-serif; -moz-user-select: none; font-size: 12px; background-color: white; padding: 0px 5px; font-weight: bold; border-width: 1px; border-style: solid; border-color: rgb(112, 112, 112) rgb(208, 208, 208) rgb(208, 208, 208) rgb(112, 112, 112);" title="Change map style">Map<img style="position: absolute; right: 4px; top: 4px; display: block;" src="http://maps.gstatic.com/intl/en_us/mapfiles/down-arrow.gif"></div>
</div>
<div style="border: 1px solid black; width: 80px; display: none;">
<div style="color: black; font-family: Arial,sans-serif; -moz-user-select: none; font-size: 12px; background-color: white; padding: 1px 5px;" title="Show street map">Map</div>
<div style="color: black; font-family: Arial,sans-serif; -moz-user-select: none; font-size: 12px; background-color: white; padding: 1px 5px;" title="Show satellite imagery">Satellite</div>
<div style="color: black; font-family: Arial,sans-serif; -moz-user-select: none; font-size: 12px; background-color: white; padding: 1px 5px;" title="Show imagery with street names">Hybrid</div>
<div style="color: black; font-family: Arial,sans-serif; -moz-user-select: none; font-size: 12px; background-color: white; padding: 1px 5px;" title="Show street map with terrain">Terrain</div>
</div></div>
As an interim solution I am using the following jquery code to alter the padding of this specific control:
$('[title="Change map style"]').parent().css('padding-top', '36px');
Far from ideal, but does the job in this case :/
One way to do it would be with JQuery, like Mat.E said over there, but instead of searching the Control by specific css style, an easy way would be to search the element with a class gmnoprint which has a child div containing the text 'Map' (which is the MapTypeControl that you're looking for)
$('.gmnoprint>div>div:contains("Map")').parent().parent().css('margin-left','35px');
We hacked this. With the help of jQuery we label elements with a class or id based on their custom style elements when the map is first created. This allows us to do stuff like ('.zoom_controls').css('top', '50px') to move the zoom controls down.
It's a hack that could break at any time but it works for us at v3.4. We'll revisit when it becomes an issue. I don't know why Google just don't put IDs in there.
Classes: https://gist.github.com/887917
IDs: https://gist.github.com/887918
Seems like you should be able to move this using some CSS (and maybe some JS). I visited http://maps.google.com and it looks like these controls have an ID ('lmc3d' in my case) and are positioned absolutely. Have you tried something like this in your style sheet:
#lmc3d{
top: 50px; /* adjust these two to move */
left: 50px;
}
You can do it with CSS only. Padding top only example:
#your_map_id_container .gm-style .gmnoprint{
margin-top: 100px! important;
}
#your_map_id_container .gm-style .gmnoprint .gmnoprint{
margin-top: 0px !important;
}