Make border-bottom span width of center aligned text - css

I want my p text to have a dotted line beneath it that spans the width of the text, I would also like the p to be centered horizontally.
The text never be longer than one line but it will vary in length on that line (if it was totally fixed, I could solve this easily).
I can't quite figure out the solution. I have the following structure:
<div class="container">
<div class="content">
<p>This is the title</p>
</div>
</div>
In my CSS, I have something like this:
.container {
width: 650px;
height: 100px;
}
.content {
text-align: center;
text-transform: uppercase;
font-size: 26px;
color: #4D4D4D;
}
p {
border-bottom: #808080;
border-bottom-width: thin;
border-bottom-style: dotted;
}

Here: http://jsfiddle.net/DqFp7/
HTML
<div class="container">
<div class="content">
<p>This is the title</p>
</div>
</div>
CSS
.container {
width: 650px;
height: 100px;
}
.content {
text-align: center;
text-transform: uppercase;
font-size: 26px;
color: #4D4D4D;
}
p {
border-bottom: #808080;
border-bottom-width: thin;
border-bottom-style: dotted;
display:inline;
}​

You can use text-decoration couples with text-decoration-style, although support for this feature is still somewhat poor (Aug-2018: Not supported in Safari and Edge).
It's in the spec, so it will eventually be supported.
.
Example:
.container,
.content {
width: 100%;
}
.content p {
font-size: 30px;
text-decoration: underline;
text-decoration-style: dotted;
text-decoration-color: red;
text-align: center;
}
<div class="container">
<div class="content">
<p>This is the title</p>
</div>
</div>

Related

How can I preserve height contributed by text, when text set to blank

Consider an inline-block CSS element which can contain text, and which has some nice padding.
Depending on whether or not there's any text in the inline-block, the height of the element will vary:
.text-holder {
display: inline-block;
color: #ffffff;
padding: 10px;
vertical-align: top;
}
.text-holder.black { background-color: #000000; }
.text-holder.grey { background-color: #606060; }
<div class='text-holder black'>I HAVE TEXT</div>
<div class='text-holder grey'></div>
How can I ensure that the height of such elements is the same, whether or not there is any text inside the element, and regardless of the font-size?
At first I considered min-height, but I don't believe that will work for variable font sizes.
Use a zero space character when empty:
.text-holder {
display: inline-block;
color: #ffffff;
padding: 10px;
vertical-align: top;
}
.text-holder.black { background-color: #000000; }
.text-holder.grey { background-color: #606060; }
.text-holder:empty::before {
content:"\200B";
}
<div class='text-holder black'>I HAVE TEXT</div>
<div class='text-holder grey'></div>
You can also keep it for all the element since it has 0 width:
.text-holder {
display: inline-block;
color: #ffffff;
padding: 10px;
vertical-align: top;
}
.text-holder.black { background-color: #000000; }
.text-holder.grey { background-color: #606060; }
.text-holder::before {
content:"\200B";
}
<div class='text-holder black'>I HAVE TEXT</div>
<div class='text-holder grey'></div>
Simply pay attention if have leading spaces:
.text-holder {
display: inline-block;
color: #ffffff;
padding: 10px;
vertical-align: top;
}
.text-holder.black { background-color: #000000; }
.text-holder.grey { background-color: #606060; }
.text-holder::before {
content:"\200B";
}
<div class='text-holder black'>I HAVE TEXT</div><br>
<div class='text-holder black'> I HAVE TEXT</div>
<div class='text-holder grey'></div>
The only way I can think of this working out for you is to use flexbox. See the code below. Basically, have a parent set as display: flex; and that should keep all the heights on each line the same. So if line 2 has only small font sizes then that one line will all be equal heights, but the heights will all be smaller than line 1 for example
.parent {
display: flex;
flex-wrap: wrap;
}
.child {
padding: 10px;
border: 1px dashed #ddd;
display: flex;
align-items: center;
}
.lg {
font-size: 30px;
}
.md {
font-size: 20px;
}
.sm {
font-size: 14px;
}
<div class='parent'>
<span class='child lg'>some text</span>
<span class='child sm'>text more text</span>
<span class='child md'>child asdf</span>
<span class='child lg'>asl;fkj s</span>
<span class='child lg'>asdf</span>
<span class='child md'>asdf 1</span>
<span class='child sm'>alsdfj </span>
<span class='child lg'>asldfkj</span>
<span class='child sm'>asldfkj</span>
</div>

Could browser like tabs made with flex box or css only?

Need tabs to shrink while the main container doesn't fit all items by width.
Here is expected behavior:
http://adamschwartz.co/chrome-tabs/
But could it be done on pure css, flexbox may be?
Solution was pretty simple. Just display: flex; for container, and overflow: hidden; for tab items.
Don't know why my question was downvoted. :(
html {
font-family: sans-serif;
}
.container {
display: flex;
border: 1px solid silver;
padding: 10px 10px 0;
width: 400px;
margin: 0 auto 10px;
}
.tab {
overflow: hidden;
text-overflow: ellipsis;
height: 20px;
border: 1px solid silver;
border-top-right-radius: 8px;
border-top-left-radius: 8px;
padding: 10px;
margin-right: 8px;
border-bottom: none;
}
.tab:last-child {
margin-right: 0;
}
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
</div>
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
<div class="tab">Chrome</div>
<div class="tab">Flexbox</div>
</div>
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
<div class="tab">Chrome</div>
<div class="tab">Flexbox</div>
<div class="tab">Stackoverflow</div>
</div>

Css fixed height content inner beetwen footer and header

First look at the picture:
Like you see my center of page i mean this content with form on small resolution get over the navbar. This content is centered verticaly and horizontal by flex.
here is code and what i try:
html`
<nav>
<div class='row header-inner'>
<div class='col-md-10 col-lg-10 col-lg-offset-2 col-md-offset-2 col-sm-offset-1 col-sm-11 col-xs-12'>
<div class='row logo-inner'>
<img src="assets\static\Logo.png">
</div>
<div class='row menu-inner'>
<a class='menu-item' routerLink="/aboutUs" routerLinkActive="active">about us</a>
<a class='menu-item' routerLink="/skiCams" routerLinkActive="active">skicams</a>
<a class='menu-item' routerLink="/contactUs" routerLinkActive="active">contact</a>
</div>
</div>
</div>
</nav>
<div class='row content-inner'>
<div class='col-md-8 col-lg-8 col-lg-offset-2 col-md-offset-2 col-sm-offset-1 col-sm-10 col-xs-12'>
<router-outlet></router-outlet>
</div>
</div>
<footer>
<div class='row center-block'>
<div class='col-md-offset-5 col-lg-offset-5 col-md-2 col-lg-2 col-sm-offset-5 col-sm-2 col-xs-offset-3 col-xs-6 footer-content'>
Powered by PGS
</div>
</div>
</footer>`
and css
footer {
border-top: 1px solid #40637e;
background-color: #282828;
position: fixed;
left: 0;
bottom: 0;
height: 110px;
width: 100%;
overflow:hidden;
}
.footer-content{
color :#959595;
border-top :1px solid #959595;
text-align: center;
margin-top:30px;
padding: 20px;
font-size: 10px;
}
.logo-inner{
margin: 35px 0px 35px 0px;
}
.header-inner{
border-bottom:1px solid #dbdbdb;
padding-bottom: 13px;
margin: 0;
}
.menu-inner{
margin:0px;
}
.menu-item{
margin-right: 40px;
padding-bottom: 15px;
font-size: 14px;
text-transform: uppercase;
font-weight: bold;
color:#545454;
}
.active{
border-bottom:1px solid #ef6716;
color: #ef6716;
}
a:hover, a:focus {
color: #ef6716;
text-decoration: none;
}
.content-inner{
background-color:#f8f8f8;
margin: 0;
/*margin-bottom:200px;*/
}
#media(max-width : 768px){
.menu-item{
margin-right:30px;
padding-bottom: 14px;
font-size: 14px;
text-transform: uppercase;
}
.menu-inner{
margin:0px;
text-align: center;
}
.logo-inner{
margin: 35px 0px 35px 0px;
text-align: center;
}
}
could you help my do something like this when the height is smaller the page start scrolling ?
It looks like you're missing your flexbox code in your question. Without seeing it all, I'd suggest trying to remove flexbox in the smaller breakpoints and just using display: block; and making sure your <div class='row content-inner'> element is statically positioned (position: static;).

Why the spurious excess separation between divs?

This jsFiddle shows the problem.
The spacing (shown in white) between the innermost divs (shown in blue) should be the same as the outermost div's padding (20px, shown in green), but it's not hard to see that it's greater.
This is can be seen even more clearly in the lower series, in which a translucent 20px outline (in light orange) has been added to the even-numbered innermost divs.
Why is there extra spacing between the innermost divs?
And now, the obligatory code:
<div class="outermost">
<div class="row">
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
</div>
</div>
<div class="outermost">
<div class="row">
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
<div class="innermost"></div>
</div>
</div>
html {
font-family: consolas, monaco, courier, monospace;
font-size: 16px;
}
body {
padding: 5px;
max-width: 530px;
}
div {
margin: 0;
border: 0;
}
div:not(.row) {
display: inline-block;
vertical-align: top;
overflow: auto;
padding: 20px;
cursor: default;
}
.outermost {
background: #c3cd84;
}
.row {
display: block;
padding: 0;
white-space: nowrap;
background: #fff;
}
div.row > :not(:first-child) {
margin-left: 20px;
}
.innermost {
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
background: #90b2c0;
}
.outermost:last-child {
margin-top: 20px;
}
.outermost:last-child .innermost:nth-child(even) {
outline: 20px solid rgba(243, 204, 152, 0.6);
}
Inline elements are sensitive to the white space in your code. One way to deal with this is to simply remove the white space:
</div><div class="innermost">
jsFiddle example
Another option is to use HTML comments:
</div><!--
--><div class="innermost">
jsFiddle example
Yet another way is to set the font size on the parent element to zero:
.row {
display: block;
padding: 0;
white-space: nowrap;
background: #fff;
font-size:0;
}
jsFiddle example

My navbar switches from horizontal to vertical when the screen width is under a certain size

Apologies in advance if the answer to this is fairly obvious, I've been researching an answer but I'm not sure if my phrasing has been correct.
As these pictures illustrate, whenever I resize my window under a certain size my navbar goes from horizontal to vertical.
these images will show what i mean:
as intended... http://imgur.com/lSGqBeU,jN27m0o#0
not quite. . . http://imgur.com/lSGqBeU,jN27m0o#1
HTML:
<div class="navbar" id="navbar">
<nav>
<ul>
<div class="col-md-2">
<li><a>Blog</a></li>
</div>
<div class="col-md-2">
<li><a>Artists</a></li>
</div>
<div class="col-md-2">
<li><a>Shop/Listen</a></li>
</div>
<div class="col-md-2">
<li><a>About/Contact</a></li>
</div>
<div class="col-md-2">
<li><a>Photos/Videos</a></li>
</div>
</ul>
</nav>
</div>
CSS:
#navbar {
background-color: #FFF;
border-bottom: 2px solid #000;
min-width: 800px;
float: clear;
}
#navbar ul {
position: relative;
list-style-type: none;
font-family: 'Amatic SC', cursive;
font-size: 200%;
font-weight: 100;
margin: 0;
padding: 0;
width: 80%;
margin-left: 300px;
}
#navbar li {
margin-left: 10px
display: block;
font-weight: 200;
margin-top: 30px;
margin-bottom: 30px;
list-style-type: none;
position: relative;
-webkit-flex-grow: 1;
border: solid red 2px;
}
#navbar a {
text-decoration: none;
color: #68716A;
font-weight: 200;
top: 20px;
}
Thanks in advance for any assistance.
EDIT: i'm using Bootstrap for the columns
"col-md-2" class is for medium sized screens. "col-xs-2" would be safer if you want it to work also on small screens.

Resources