Add spacing between the <li> text and the before content - css

I want to achieve something like this:
000 Lorem ipsum
dolor
0 Lorem ipsum
dolor
This is the code I'm working with:
<ul>
<li>Lorem ipsum dolor sit amet, sed do eiusmo</li>
<li>Lorem ipsum dolor sit amet elit</li>
</ul>
CSS:
li:before {
content: "0";
}
li:first-child:before {
content: "000";
}
ul {
width:100px;
list-style: none;
}
Can you help me with CSS to have the text stay equally away from the before content?
"Lorem" and "dolor" need to stay in the same "vertical line".
https://jsfiddle.net/ga6r8qsz/
Thank you.

You can do this using absolute positioning on the before elements. This will ensure that your li items will remain vertically in line.
li {
position: relative;
padding-left: 15px;
margin-bottom: 15px;
}
li::before {
content: "0";
position: absolute;
width: 35px;
left: -35px;
}
li:first-child::before {
content: "0000";
}
ul {
width: 100px;
list-style: none;
}
<ul>
<li>Lorem ipsum dolor sit amet, sed do eiusmo</li>
<li>Lorem ipsum dolor sit amet elit</li>
</ul>

make the pseudoelements ::befores like blocks, in that way you can add the width of them and control the view of the list in that way
here example:
li:before {
content: "0";
display:inline-block;
width:35px;
}
li:first-child:before {
content: "000";
display:inline-block;
width:35px;
}
ul {
width:300px;
list-style: none;
}
<ul>
<li>some text</li>
<li>some text more</li>
</ul>

Using the display: flex property on li elements will not only give equal spacing between the :before pseudo elements and the li tags, but will also make the li tags left aligned on new lines as shown below.
li {
display: flex;
}
li:before {
content: "0";
width:70px;
}
li:first-child:before {
content: "000";
}
ul {
width:150px;
list-style: none;
}
<ul>
<li>Lorem ipsum dolor sit amet, sed do eiusmo</li>
<li>Lorem ipsum dolor sit amet, sed do eiusmo</li>
</ul>

Here is an idea where you don't need to use any fixed value for width. Consider a table layout and it will work with any pseudo element content:
li:before {
content: "0";
display:table-cell;
padding-right:5px;
}
li:first-child:before {
content: "000";
}
ul {
width:200px;
list-style: none;
display:table;
}
li {
display:table-row;
}
<ul>
<li>Lorem ipsum dolor sit amet, sed do eiusmo</li>
<li>Lorem ipsum dolor sit amet elit</li>
</ul>

Related

Change a bullet point color within a before selector with CSS

I am trying to change the color of a bullet point. You'll better understand my request with the image below.
So far, I successfully made it, but I can't find a way to change the bullet point to red.
Here's my CSS :
h3#one {
display: flex;
flex-direction: column;
}
h3#one::before {
content: '1.';
font-size: 40px;
margin-right: 24px;
margin-bottom: 8px;
}
<h3 id="one">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3>
Is there a way to make it with CSS?
I don't think that you can achieve this with a pseudo class but you could do something like this.
h3 {
display:block;
}
h3 .red {
font-size: 40px;
margin-right: 24px;
margin-bottom: 8px;
color: red;
}
<h3>1<span class="red">.</span></h3>
<h3> Test</h3>
If you want only the dot red you can do it with a span like this: <h3>Your text<span style="color: red">.</span></h3>
You can. You just shouldn't be doing it with the '1' in the pseudo-class too. Instead, put the value inside the tag and use the ::before only to style the dot.
h3 {
display: flex;
flex-direction: column;}
h3::before {
position: absolute;
top: 0;
margin-left: 10px;
color: red;
content: '.';
font-size: 40px;
margin-right: 24px;
margin-bottom: 8px;}
<html>
<body>
<h3>1</h3>
</body>
</html>
If you don't want this approach, I suggest using the span tag to do the trick.
<h3>1<span style="color: red">.</span></h3>
You could do it with a gradient background and background-clip: text.
h3 {
display: flex;
flex-direction: column;
}
h3::before {
counter-reset: num var(--num);
content: counter(num) '.';
font-size: 40px;
margin-right: 24px;
margin-bottom: 8px;
align-self: start;
background-image: linear-gradient(90deg, red, red), linear-gradient(90deg, black, black);
background-size: 0.25em, auto;
background-position: right;
background-repeat: no-repeat;
background-clip: text;
-webkit-background-clip: text;
color: transparent;
}
<h3 style="--num: 1">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3>
<h3 style="--num: 2">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3>
<h3 style="--num: 3">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3>
<h3 style="--num: 42">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3>
<h3 style="--num: 256">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h3>
But this isn't that reliable. The background-clip: text property is still under a prefix on some browsers. And you need to manually set the gradient cutoff between the number and the dot, depending in the font.

How would / could I the center text, with out the ugly formatting?

How would / could I the center text, with out the ugly formatting?
I've tried different margins, but so far no luck...
Basically, I'm looking for a left aligned text, that's centered. (Though it still has to be responsive.
Left-ish Aligned, but not centered.
Centered, But not aligned properly, still has the ugly centered format.
1
section{
line-height:1.5em;
font-size: 1.2em;
padding:35px;
width:50%;
margin: 0 auto;
color:#FFF;
background: rgba(176,224,230,.3);
text-align:center;
}
2
section{
line-height:1.5em;
font-size: 1.2em;
padding:35px;
width:50%;
margin: 0 auto;
color:#FFF;
background: rgba(176,224,230,.3);
}
Any advice / help would be awesome, thanks!!
Inner content (p) has display: inline-block or inline, the parent element's content is centered.
<div>
<p>
Lorem ipsum dolor sit amet, consec<br>
Lorem ipsum dolor sit amet<br>
Lorem ipsum dolor sit amet aaa<br>
Lorem ipsum dolor sit amet bfds<br>
Lorem ipsum dolor sit amet
</p>
</div>
<style>
div {background: lightblue; text-align: center;}
p {display: inline-block; text-align: left; margin: 0 auto;}
</style>
http://jsfiddle.net/2x5kwy7n/1/
I am aligning text in centre by this css code, which has background image and centred Text align.
.footer{
background: url(../images/footer/footer.png) no-repeat;
background-position: center;
padding: 30px 0px 70px 0px;
color: #ffffff;
text-align: center;
margin-left: -2%;
margin-right: -2%;
}

How to make sidebar with same height as the content div?

the code is the following:
(CSS)
#container {
border:1px dashed #000;
overflow:hidden;
}
#content, #sidebar {
float:left;
width:50%;
}
#content {
background:yellow;
}
#sidebar {
background:grey;
}
#sidebar {
height:100%;
}
(HTML)
<div id="container">
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
</div>
<div id="sidebar">
<p>Few words</p>
</div>
</div>
I would like to see a #sidebar div with same height, like the #content div, is it possible without absolute position? Online version: http://jsfiddle.net/yJbUW/
You can do that by displaying the #container as table and displaying #content and #sidebar as table-cells:
#container {
border:1px dashed #000;
display: table;
width: 100%;
}
#content, #sidebar {
display: table-cell;
width:50%;
}
Check your updated Fiddle.
You can also try below code
CSS goes here
#container {
border:1px dashed #000;
overflow:hidden;
}
#content, #sidebar {
float:left;
width:50%;
}
#content {
background:yellow;
}
#sidebar {
background:grey;
}
#Container
{
height: auto;
width: auto;
}
and update HTML as follows,
<div id="Container">
<span id="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
</span>
<span id="sidebar">
<p>Few words</p>
</span>
</div>
It can be solved with
#content, #sidebar {
display: table-cell;
width:50%;
}
.table {
display:table;
}
.row {
display:table-row;
}
.one {
width:200px;
border:1px solid #333;
display:table-cell
}
<div class="table">
<div class="row">
<div class="one">gfhgfhgfhgf</div>
<div class="one">gfhgfhgfhgf</div>
</div>
</div>
Just use this code before the container closing Div, works for me!
<p style="clear:both;"></p>
Here's the simplest and most elegant solution:
#container {
display:grid;
grid-auto-flow: column;
}

vertical align pseudo element in list navigation

I've created a list style navigation and each hyperlink can be multiple lines, after each hyperlink element I added a pseudo element 'arrow' after, would it be possible to align the pseudo element vertically regardless of the hyperlink height?
The requirement would be for this to work in IE8 & above.
The Mark-up:
<ul>
<li>
<a href="#">
<h3 class="title">Cover</h3>
<p class="subtitle">Lorem ipsum dolor sit</p>
</a>
</li>
<li class="current">
<a href="#">
<h3 class="title">Lorem ipsum dolor sit amet</h3>
<p class="subtitle">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maiores cum!</p>
</a>
</li>
<li>
<a href="#">
<h3 class="title">Lorem ipsum dolor sit amet, consectetur</h3>
<p class="subtitle">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis.</p>
</a>
</li>
<li>
<a href="#">
<h3 class="title">Lorem ipsum dolor sit amet, consectetur adipisicing Lorem ipsum dolor sit.</h3>
</a>
</li>
</ul>
The CSS:
body {
background: #666;
padding: 5em;
}
ul {
background: #fff;
list-style: none;
}
li {
border-bottom: 1px solid #ccc;
position relative;
}
.current a {
border-color: #000;
}
a {
border-left: 8px solid #ccc;
overflow: hidden;
display: block;
line-height: 1.3;
padding: .75em;
position: relative;
text-decoration: none;
color: #000;
}
a:after {
content: '>';
color: #ce4300;
float: right;
font-size: 1.125em;
line-height: 1;
position: absolute;
right: 1em;
}
h3 {
float: left;
font-size: .875em;
margin: 0 1em 0 0;
}
.subtitle {
color: #555;
clear: left;
float: left;
font-size: .875em;
font-style: itatlic;
}
The current prototype:
http://jsfiddle.net/yVJbL/
Here you go:
a:after {
content:'>';
color: #ce4300;
font-size: 1.125em;
position: absolute;
line-height: 0;
right: 1em;
top: 50%;
bottom: 50%;
}
Surprisingly simple :D
I thing best solution to make all browsers happy is to use a background-image (this little arrow won't be so big image) and background-position: right center (or so). You are open to hover efect with this solution as well. Background image can be placed also in padding area so there won`t be any overflow.
Hope this helps you.

Align 2 div without size

Is possible auto align in line 2 div without size?
The goal is to get something like the image attached.
I can't set percentages (80% and 20%) because the content is dynamic. I can't use tables. Any idea?
Example: http://jsfiddle.net/hKRyG/
<html>
<head>
<style type="text/css">
.navbar {
width: 500px;
background: #ccc;
display:table;
}
.navbar .breadcrumb {
float:left;
}
.navbar .breadcrumb ul {
margin: 0;
padding: 0;
}
.navbar .breadcrumb li {
list-style: none;
display: inline;
}
.navbar .navbutton {
float: right;
}
</style>
</head>
<body>
<div class="navbar">
<div class="breadcrumb">
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
</ul>
</div>
<div class="navbutton">
<input type="button" value="BUTTON" />
</div>
</div>
</body>
</html>
Thank you!
There you go! To align without defined size you must use table display properties
.navbar {
width: 500px;
background: #ccc;
display:table;
}
.navbar .breadcrumb ul {
margin: 0;
padding: 0;
}
.navbar .breadcrumb li {
list-style: none;
display: inline;
}
.navbar ul{
display: table-cell;
}
.navbutton {
display: table-cell;
vertical-align: middle;
}
Use the following:
<html>
<head>
<style>
.navbar {
width: 500px;
background: #ccc;
display:table;
float: left;
}
.navbar .breadcrumb {
float:left;
}
.navbar .breadcrumb ul {
margin: 0;
padding: 0;
}
.navbar .breadcrumb li {
list-style: none;
display: inline;
}
.navbar .navbutton {
float: right;
}
</style>
</head>
<body>
<div class="navbar">
<div class="breadcrumb">
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
</div>
</div>
<div class="navbutton">
<input type="button" value="BUTTON" />
</div>
<body>
</html>
If you move the button to the top of the markup and give it a float: right;, then add overflow: hidden; to the <div class="breadcrumb"> the button should be flush right and the breadcrumb will take up whatever room remains on the left.
jsFiddle
HTML:
<div class="navbar">
<div class="navbutton">
<input type="button" value="BUTTON" />
</div>
<div class="breadcrumb">
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>-></li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
</ul>
</div>
</div>​
CSS
.navbar {
width: 500px;
background: #ccc;
}
.navbar .navbutton {
float: right;
}
.navbar .breadcrumb {
overflow: hidden;
}
.navbar .breadcrumb ul {
margin: 0;
padding: 0;
}
.navbar .breadcrumb li {
list-style: none;
display: inline;
}​

Resources