My desired outcome is a headline element with a thick underline that is slightly offset from the left like so:
I'm getting the underline to work with an inset CSS box-shadow, but I have no idea on how to offset it from the left so that it's not completely inline with the start of the h2 text.
html {
font-family: 'Roboto', sans-serif;
font-size: 62.5%;
// -ms-text-size-adjust: 100%;
// -webkit-text-size-adjust: 100%;
}
body {
word-wrap: break-word;
overflow-x: hidden;
}
h2 {
font-weight: bold;
font-size: 2rem;
line-height: 1.1;
}
h2 span {
box-shadow: inset 0 -1.0rem 0 0 #88DEB2;
padding-right: 1rem;
}
<h2><span>Incredible Pure Castile Soap</span></h2>
Happy for any hints on how to achieve this.
You are almost good, simply add a negative text-indent:
html {
font-family: 'Roboto', sans-serif;
font-size: 62.5%;
}
body {
word-wrap: break-word;
overflow-x: hidden;
}
h2 {
font-weight: bold;
font-size: 2rem;
line-height: 1.1;
padding-left: 1rem;
}
h2 span {
box-shadow: inset 0 -1.0rem 0 0 #88DEB2;
display:inline-block; /* this is needed for the trick */
text-indent: -1rem; /* here */
padding-right: 1rem;
}
<h2><span>Incredible Pure Castile Soap</span></h2>
A multiline solution with gradient
html {
font-family: 'Roboto', sans-serif;
font-size: 62.5%;
}
body {
word-wrap: break-word;
overflow-x: hidden;
}
h2 {
font-weight: bold;
font-size: 2rem;
line-height: 1.1;
padding-left: 1rem;
}
h2 span {
background:
linear-gradient(#88DEB2,#88DEB2)
bottom right/calc(100% - 1rem) 1rem
no-repeat;
padding-right: 1rem;
}
<h2><span>Incredible Pure Castile Soap</span></h2>
You can make use of the pseudo element ::after or ::before and control the offset/positioning using left or right. Code explained in comments.
html {
font-family: 'Roboto', sans-serif;
font-size: 62.5%;
// -ms-text-size-adjust: 100%;
// -webkit-text-size-adjust: 100%;
}
body {
word-wrap: break-word;
overflow-x: hidden;
}
h2 {
font-weight: bold;
font-size: 2rem;
line-height: 1.1;
width: max-content; /* Take the content width */
}
h2 span::after {
content: " "; /* Let us 'activate' the pseudo element */
display: block;
background: #88DEB2;
height: 15px;
position: relative;
top: -10px;
left: 5px; /* Control the misalignment */
z-index: -1; /* So that it appears underneath */
}
<h2><span>Incredible Pure Castile Soap</span></h2>
You can use a linear-gradient to fake an underline which should achieve this (see comments in code for details)
html {
font-family: 'Roboto', sans-serif;
font-size: 62.5%;
// -ms-text-size-adjust: 100%;
// -webkit-text-size-adjust: 100%;
}
body {
word-wrap: break-word;
overflow-x: hidden;
}
h2 {
font-family: serif;
font-weight: bold;
font-size: 2rem;
line-height: 1.1;
}
h2 span {
background-image: linear-gradient(transparent 50%, #88DEB2 50%); /* makes a linear gradient */
background-position: 5px 0; /* offsets it */
background-repeat: no-repeat; /* stops it from repeating */
padding-right: 5px; /* gives more space for the underline offset */
}
<h2><span>Incredible Pure Castile Soap</span></h2>
Related
I made have made my first CSS class, but I have got a little problem, the buttons are centered, but thats not what I want.
View: http://prntscr.com/6i30xg
I would like them so they start at the left side only. But when using float: left;to the .body class it will results in
View: http://prntscr.com/6i327q
But I would like that the buttons are on the edge like the homepage.
#import url(http://fonts.googleapis.com/css?family=Muli:300,400,300italic,400italic);
/* Typography
–––––––––––––––––––––––––––––––––––––––––––––––––– */
h1, h2, h3, h4, h5, h6
{
margin-top: 0;
margin-bottom: 2rem;
font-weight: 300;
}
h1
{
font-size: 4.0rem;
line-height: 1.2;
letter-spacing: -.1rem;
}
h2
{
font-size: 3.6rem;
line-height: 1.25;
letter-spacing: -.1rem;
}
h3
{
font-size: 3.0rem;
line-height: 1.3;
letter-spacing: -.1rem;
}
h4
{
font-size: 2.4rem;
line-height: 1.35;
letter-spacing: -.08rem;
}
h5
{
font-size: 1.8rem;
line-height: 1.5;
letter-spacing: -.05rem;
}
h6
{
font-size: 1.5rem;
line-height: 1.6;
letter-spacing: 0;
}
p
{
margin-top: 0;
}
/* Buttons
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.btn
{
display: inline-block;
height: 38px;
padding: 0 30px;
color: #555;
text-align: center;
font-size: 11px;
font-weight: 600;
line-height: 38px;
letter-spacing: .1rem;
text-transform: uppercase;
text-decoration: none;
white-space: nowrap;
background-color: transparent;
border-radius: 4px;
border: 1px solid #bbb;
cursor: pointer;
box-sizing: border-box;
}
.btn
/* Form
–––––––––––––––––––––––––––––––––––––––––––––––––– */
/* Programming :D
–––––––––––––––––––––––––––––––––––––––––––––––––– */
code {
padding: .2rem .5rem;
margin: 0 .2rem;
font-size: 90%;
white-space: nowrap;
background: #F1F1F1;
border: 1px solid #E1E1E1;
border-radius: 4px;
}
pre > code
{
display: block;
padding: 1rem 1.5rem;
white-space: pre;
}
/* Content
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.content
{
border-width: 20px 20px 0px 20px;
border-radius: 28px 28px 0 0;
box-sizing: border-box;
margin-top: 120px;
max-width: 1280px;
margin-left: auto;
margin-right: auto;
min-height: 100%;
}
.header
{
}
.header span
{
color: #fff;
float: left;
margin-left: 28px;
margin-top: 28px;
font-family: 'Muli', sans-serif;
font-weight: 300;
font-size: 24px;
}
.header ul
{
color: #fff;
float: right;
margin-right: 28px;
margin-top: 28px;
}
.header ul li
{
float: right;
border: 1px solid #fff;
padding: 5px 20px;
border-radius: 11px;
margin-right: 12px;
}
.header ul li a
{
color: #fff;
font-family: 'Muli', sans-serif;
font-weight: 300;
font-size: 11px;
text-decoration: none;
}
.body
{
padding-top: 148px;
}
.footer
{
}
Just remove margin-left: auto; and margin-right:auto; from your content class. OR You can replace auto with any fixed number of pixels like 10px. Setting the margins left and right to auto makes the content to align center of the page. So do not use auto.
You content class should look like,
.content
{
border-width: 20px 20px 0px 20px;
border-radius: 28px 28px 0 0;
box-sizing: border-box;
margin-top: 120px;
max-width: 1280px;
margin-left: <some value in pixels>;
margin-right: <some value in pixels>;
min-height: 100%;
}
Remove text-align: center; from .btn class
I set font-size: 12px on my body element. But on the mobile device some elements have a font-size of more than 12px (for example, element p). Why does this happen? How can this be fixed?
body {
font: normal normal 400 12px/1.5 "Droid Sans", Helvetica, "Helvetica Neue", Arial, sans-serif;
}
.footer {
background: #1d3057;
padding: 15px 30px;
color: #dedede;
width: 100%;
box-sizing: border-box;
}
. footer span {
display: inline-block;
white-space: pre;
float: left;
font-size: 12px;
}
You can use this solution:
* { max-height: 999999px; }
I have built a Ruby on Rails site based off the RailsTutorial. I'm trying to change a few colors, but I can't figure it out.
I would like to change the background color [body of page] and the color of the menu text. Where can I do this?
my current custom.css.scss:
#import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #eaeaea;
#mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
table td {
padding:0px 25px 0px 0px;
}
table th {
text-align: left;
padding:0px 25px 0px 0px;
}
/* bootstrap */
.navbar-inner {
background-color: white; /* background color will be black for all browsers */
background-image: none;
background-repeat: no-repeat;
filter: none;
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $grayLight;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
p2 {
font-size: 1.1em;
line-height:1.7em;
font-weight: bold;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: black;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
background-color: black;
}
}
...
thanks
Bootstrap has a lot of customization by default. You can find all the options here http://getbootstrap.com/customize/
Just use sass variables instead of less.
$body-bg: #fff;
$navbar-default-color: #000;
$navbar-default-link-color: #000;
and so on… You will get what you want
to change color of navbar
.navbar {
background-color: red;
}
to change navbar nav links color
.navbar-nav > li > a {
color: blue;
}
try
div.navbar{
background: red;
color:#fff
}
Change the colors to your needs.
I'm learning rails. I have this problem and I hope you can help me.
HTTP answer code is 500 ... I am learning from a rails tutorial...
Site crashes after adding the style - /* sidebar */
This is my custome.css.scss:
#import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #eaeaea;
/* universal */
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.7em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $grayLight;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: white;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $grayMediumLight;
color: $grayLight;
a {
color: $gray;
&:hover {
color: $grayDarker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 10px;
}
}
}
/* sidebar */
aside {
section {
padding: 10px 0;
border-top: 1px solid $grayLighter;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}
.gravatar {
float: left;
margin-right: 10px;
}
and why the site falls due to renaming the comments? it the syntax language "SASS"?
other files https://gist.github.com/phantomass/7356307
The issue here may be the way you are using SASS comments and are having an issue with the compiled code.
I am not sure of your rails setup but I would take a look at the Rails asset preprocessing section
If you provide more information on your rails app I will try my best to resolve the issue.
Struggling with what seems to be a common problem, but none of the suggestions I've found so far is working. I'm working on a stylesheet for printing, the page contains nothing more then a table and one h1 tag.
The problem is that I'm getting empty white space at the top of the page, about 1/4 of the page in portrait and half the page in landscape - neither is obviously not acceptable for my users.
I've tried zeroing margins on every possible element I can think off, including body, html, table, tr and tr. Pasting the HTML and CSS below (some tags is for other HTML not found below, these are for other pages also using the same CSS for print), hopefully it's a simple fix or missing margin :)
/*Print CSS template */
body, #content, #container {
width: 100%;
margin: 0;
float: none;
background: #fff url(none);
}
#topnav, #navbar, #nav, #sidebar, .ad, .noprint {
display: none;
}
body {
font: 1em Georgia, "Times New Roman", Times, serif;
color: #000;
}
h1,h2,h3,h4,h5,h6 {
font-family: Helvetica, Arial, sans-serif;
color: #000;
}
h1 { font-size: 250%; }
h2 { font-size: 175%; }
a:link, a:visited {
color: #00c;
font-weight: bold;
text-decoration: underline; }
#content a:link:after, #content a:visited:after {
content: " (" attr(href) ") ";
}
/*Print CSS template END */
.r_main
{
width: auto;
padding: 0;
margin: 0;
}
table{
margin: 0;
padding: 0;
}
.r_wrap
{
margin: 0;
width: 100%;
display: block;
min-height: 30px;
float: left;
display: block;
border-bottom: 1px solid #000;
}
.r_left
{
margin: 0;
width: 300px;
color: #000;
display: block;
float: left;
font: 13px Arial, Helvetica,"Lucida Grande", serif; color: #000;
}
.r_right
{
margin: 0;
display: block;
float: left;
color: #000;
font: 13px Arial, Helvetica,"Lucida Grande", serif; color: #000;
}
.r_right p
{
padding: 0;
margin: 7px 0 3px 0;
font: 13px Arial, Helvetica,"Lucida Grande", serif; color: #000;
}
.r_left span, .r_right span
{
display: block;
margin: 0;
padding: 5px 0 0 0;
}
.r_right ul
{
margin: 3px 0 0 15px;
padding: 0;
}
.r_right ul li
{
margin: 0;
padding: 3px 0 0 0;
}
.r_zeb1
{
background-color: #f9f9f9;
}
.r_zeb2
{
background-color: #e9e9e9;
}
HTML
<table>
<tr class="r_wrap r_zeb2">
<td class="r_left"><span>Location</span></td>
<td class="r_right"><span>'.$frm->get_location($selectedE['e_location']).'</span></td>
</tr>
</table>
Assuming that the h1 is before the table, it could be the issue. You might want to zero the margins & padding on it. It could also help to switch to 'pt' for your font-size instead of using a %.
h1{
margin:0;
padding:0;
font-size: 36pt;
}
Agree with user401183, I think its the font size
h1 { font-size: 250%; }
h2 { font-size: 175%; }