Position of text within the block element - html

I need to make sure that if the text line is too long, it does not go above the price, but goes to a second line as soon as it approached the block with the price. I hope this makes sense. Please refer to the line 'Green tea with a tiny piece of lemon'. The word 'of' should not go above the line, it should have moved to the second line.
Any ideas how to fix this?
.lst {
font-family: montserrat;
width: 300px;
list-style-type: none;
position: relative;
}
ul.lst li {
position: relative;
}
ul.lst li a {
text-decoration: none;
color: #252525;
display: block;
padding: 5px;
position: relative;
border-bottom: 2px solid #f3f2e8;
z-index: 2;
}
ul.lst li em {
font-style: normal;
float: right;
width: 25%;
color: orange;
}
ul.lst li span {
position: absolute;
top: 0;
left: 0;
display: block;
height: 100%;
text-indent: -9999px;
background: #BFD3EE;
opacity: 0.5;
}
ul.lst li:hover span {
background: #658BBB;
}
ul.lst li:hover a{
color: #61304B;
}
ul.lst li:hover em{
color: #61304B;
}
<ul class="lst">
<li>Americano<em>$2.24</em><span style="width:20%">20%</span></li>
<li>Green tea with a tiny piece of lemon<em>$22.50</em><span style="width: 50%">50%</span></li>
<li>Black Tea<em>$2</em><span style="width: 75%">75%</span></li>
<li>Black coffee<em>$2</em><span style="width: 90%">90%</span></li>
<li>Latte<em>$2</em><span style="width: 50%">100%</span></li>
</ul>

You can set display: flex on a and that should fix the problem.
.lst {
font-family: montserrat;
width: 300px;
list-style-type: none;
position: relative;
}
ul.lst li {
position: relative;
}
ul.lst li a {
text-decoration: none;
color: #252525;
display: flex;
align-items: center;
padding: 5px;
position: relative;
border-bottom: 2px solid #f3f2e8;
z-index: 2;
}
ul.lst li em {
font-style: normal;
margin-left: auto;
width: 25%;
color: orange;
}
ul.lst li span {
position: absolute;
top: 0;
left: 0;
display: block;
height: 100%;
text-indent: -9999px;
background: #BFD3EE;
opacity: 0.5;
}
ul.lst li:hover span {
background: #658BBB;
}
ul.lst li:hover a {
color: #61304B;
}
ul.lst li:hover em {
color: #61304B;
}
<ul class="lst">
<li>Americano<em>$2.24</em><span style="width:20%">20%</span></li>
<li>Green tea with a tiny piece of lemon<em>$22.50</em><span style="width: 50%">50%</span></li>
<li>Black Tea<em>$2</em><span style="width: 75%">75%</span></li>
<li>Black coffee<em>$2</em><span style="width: 90%">90%</span></li>
<li>Latte<em>$2</em><span style="width: 50%">100%</span></li>
</ul>

Change a structure of your HTML a little bit and change your <a> to flexbox i.e. from display: block to display: flex.
Have a look at the snippet below:
.lst {
font-family: montserrat;
width: 300px;
list-style-type: none;
position: relative;
}
ul.lst li {
position: relative;
}
ul.lst li a {
text-decoration: none;
color: #252525;
display: flex;
padding: 5px;
position: relative;
border-bottom: 2px solid #f3f2e8;
z-index: 2;
}
ul.lst li a .text {
flex: 1;
}
ul.lst li em {
font-style: normal;
float: right;
width: 25%;
color: orange;
}
ul.lst li span {
position: absolute;
top: 0;
left: 0;
display: block;
height: 100%;
text-indent: -9999px;
background: #BFD3EE;
opacity: 0.5;
}
ul.lst li:hover span {
background: #658BBB;
}
ul.lst li:hover a{
color: #61304B;
}
ul.lst li:hover em{
color: #61304B;
}
<ul class="lst">
<li>
<a href="#">
<div class="text">Americano</div>
<em>$2.24</em>
</a>
<span style="width:20%">20%</span>
</li>
<li>
<a href="#">
<div class="text">Green tea with a tiny piece of lemon</div>
<em>$22.50</em>
</a>
<span style="width: 50%">50%</span></li>
<li>
<a href="#">
<div class="text">Black Tea</div>
<em>$2</em>
</a>
<span style="width: 75%">75%</span>
</li>
<li>
<a href="#">
<div class="text">Black coffee</div>
<em>$2</em>
</a>
<span style="width: 90%">90%</span>
</li>
<li>
<a href="#">
<div class="text">Latte</div>
<em>$2</em>
</a>
<span style="width: 50%">100%</span>
</li>
</ul>
Hope this helps!

How about the price with absolute position and some padding for the link text so it doesn't go on the price? something like this:
ul.lst li a {
text-decoration: none;
color: #252525;
display: block;
padding: 5px;
position: relative;
border-bottom: 2px solid #f3f2e8;
z-index: 2;
padding-right: 60px;
}
ul.lst li em {
font-style: normal;
float: right;
color: orange;
position: absolute;
right: 0;
width: auto;
}

Related

Duration for Bottom border using CSS

I'm creating navbar with submenu. The elements of the navbar have a bottom border that becomes visible when hovered on. Further, a submenu is also visible. Currently, the bottom border goes invisible when the cursor is moved to submenu. I want it to be visible as long as the submenu is open.
nav {
display: inline-flex;
width: 100%;
}
.nav-list {
display: flex;
width: 100%;
margin-top: .7rem;
/*Use this to change the postition of dropdown*/
padding-left: 1.1rem;
/*Use this to move the dropdown left and right*/
}
.nav-list li {
position: relative;
}
.nav-list>li>a {
color: black;
display: block;
font-size: 1rem;
padding: 1.3rem 1rem;
text-transform: uppercase;
}
.nav-list>li>a::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 4px;
width: 0;
left: 0;
bottom: -0.5px;
}
.nav-list>li>a:hover:after {
width: 100%;
}
.sub-menu {
display: flex;
position: absolute;
box-sizing: border-box;
background-color: black;
visibility: hidden;
top: 3.89rem;
/*adjust postion */
left: -4rem;
width: 82.5rem;
height: 35rem;
z-index: 5000;
}
.sub-menu a {
position: relative;
top: 2rem;
color: white;
font-size: 1.1rem;
font-weight: 200;
padding: 3rem 40px 0 40px;
}
.sub-menu a:hover {
color: #7e7978;
}
<div class="main" id="navbar">
<nav>
<ul class="nav-list">
<li>
Men
<ul class="sub-menu">
<li>shirts </li>
</ul>
</li>
</ul>
</nav>
</div>
I have added the following code to the .nav-list li:hover .sub-menu block
.nav-list>li:hover .sub-menu {
visibility: visible;
}
This makes sure that the sub-menu is visible as long as the parent element is hovered.
And also added the following code to the .nav-list>li>a:hover:after
.nav-list>li:hover>a::after {
width: 100%;
}
This makes sure that the bottom border is visible as long as the parent element is hovered.
nav {
display: inline-flex;
width: 100%;
}
.nav-list {
display: flex;
width: 100%;
margin-top: .7rem;
/*Use this to change the postition of dropdown*/
padding-left: 1.1rem;
/*Use this to move the dropdown left and right*/
}
.nav-list li {
position: relative;
}
.nav-list>li>a {
color: black;
display: block;
font-size: 1rem;
padding: 1.3rem 1rem;
text-transform: uppercase;
}
.nav-list>li>a::after {
content: "";
position: absolute;
background-color: #ff2a00;
height: 4px;
width: 0;
left: 0;
bottom: -0.5px;
}
.nav-list>li:hover>a::after {
width: 100%;
}
.nav-list>li:hover .sub-menu {
visibility: visible;
}
.sub-menu {
display: flex;
position: absolute;
box-sizing: border-box;
background-color: black;
visibility: hidden;
top: 3.89rem;
/*adjust postion */
left: -4rem;
width: 82.5rem;
height: 35rem;
z-index: 5000;
}
.sub-menu a {
position: relative;
top: 2rem;
color: white;
font-size: 1.1rem;
font-weight: 200;
padding: 3rem 40px 0 40px;
}
.sub-menu a:hover {
color: #7e7978;
}
.nav-list>li:hover .sub-menu {
visibility: visible;
}
.nav-list>li:hover>a::after {
width: 100%;
}
<div class="main" id="navbar">
<nav>
<ul class="nav-list">
<li>
Men
<ul class="sub-menu">
<li>shirts </li>
</ul>
</li>
</ul>
</nav>
</div>

Navbar creating empty space down and above when adding logo

I want to make the navbar with logo. but its creating empty space below when adding height or width.
is there any css property I can use?
it does not look good like this.
this is navbar without logo
this is navbar with logo:
html:
<section id="header">
<a class="name" href="#header"
>SYNCC
<img
src="images/logo.png"
alt=""
height="90"
class="logo-png"
/></a>
<div>
<ul id="navbar">
<li><a class="active" href="#hero">Home</a></li>
<li>Features</li>
<li>About Us</li>
<li>Contact</li>
<li>
<a href="#carouselExampleControls"
><i class="fa-solid fa-cart-shopping"></i
></a>
</li>
</ul>
</div>
</section>
css:
#header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 80px;
/* background: #e3e6f3; */
background: #E5E6EE;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.06);
z-index: 999;
position: sticky;
top: 0;
left: 0;
right: 30%;
}
#navbar {
display: flex;
align-items: center;
justify-content: center;
}
#navbar li {
list-style: none;
padding: 0 20px;
position: relative;
}
#navbar li a {
text-decoration: none;
font-size: 16px;
font-weight: 600;
color: #1a1a1a;
}
.name {
font-family: "DynaPuff", cursive;
text-decoration: none;
font-size: 25px;
font-weight: 400;
color: #1a1a1a;
position: relative;
top: 10px;
}
.name:hover,
.name a {
color: #088178;
transition: 0.3s ease;
}
.name a::after,
.name a:hover {
content: "";
width: 30%;
height: 2px;
background: #088178;
position: absolute;
bottom: -4px;
left: 20px;
}
#navbar li a:hover,
#navbar li a.active {
color: #088178;
transition: 0.3s ease;
}
#navbar li a.active::after,
#navbar li a:hover::after {
content: "";
width: 30%;
height: 2px;
background: #088178;
position: absolute;
bottom: -4px;
left: 20px;
}
tried using display : block;
I tried several ways to fix it.
any other way can use to make it correct.
Usally when this happens to me, I will just add top:--px; or bottom:--px; accordingly to make them line up.

There is a small gap after the navigation

I have a navigation bar which is OK, but just underneath that there is a 1px line that I cannot get rid of, it should be flush with the address underneath. This is the code that I have can anyone suggest anything?
There is also some of the html which was so hard formatting on here anyhow they want me to add more text. So it is the address underneath the naviation
address.space {
width: 100%;
background: #FF9900;
font-family: 'Monserrat', sans-serif;
text-align: center;
display: inline-block;
font-size: 1em;
margin-bottom: 20px;
}
/*menu*/
.nav {
background-color: #3333FF;
width: 100%;
height: 40px;
line-height: 40px;
}
.menu {
font-family: Monserrat, sans-serif;
font-size: 20px;
color: white;
list-style-type: none;
padding: 0;
position: relative;
z-index: 1;
}
.menu a {
text-decoration: none;
color: #fff;
line-height: 40px;
height: 40px;
display: block;
}
.menu ul li {
text-align: center;
display: inline-block;
padding: 0 20px 0 20px;
width: 13.5%;
height: 40px;
}
.menu li:visited,
.menu li:active,
.active,
.menu li:hover {
background: #0000EE;
color: #fff;
}
label {
margin: 0 14px 0 0;
font-size: 20px;
display: none;
}
#toggle {
display: none;
}
#media only screen and (max-width: 500px) {
html,
body,
#main,
#firstside,
.firstsidewider,
#second,
.wide {
width: 100%;
font-size: 1em;
}
h1 span {
display: none;
}
label {
cursor: pointer;
display: block;
color: #fff;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu li a {
border-bottom: 1px solid #F4F4F4;
display: block;
background: #3333FF;
margin: -20px;
padding: 0;
}
.active,
.menu li:hover {
color: #fff;
background: 0;
}
#toggle:checked+.menu {
display: block;
}
<header id="banner">
<div class="nav">
<label for="toggle">☰</label><input id="toggle" type="checkbox">
<div class="menu">
<ul>
<li>Home</li>
<li>News</li>
<li>Contacts
</li>
<li>Members
</li>
<li>Policies
</li>
<li>Links</li>
<li class="active">
Volunteer/li>
</ul>
</div>
</div>
<address class="space">
Meeting Address: YMCA -The Lecture Room 29 Rush Green
Road
4.00pm - 6.00pm</address>
<section id="leftheader">
<h1>Hubb <span>support group</span></h1>

Horizontal CSS Wizard Navigation

I am trying to build up a horizontal css wizard navigation with a rounded css circle and text on each step. I am stuck on 1 point need to get ride on border from right side. Tried almost all steps. Attaching the code.
Attaching the screenshot of issue as well.
error image
ul {
text-align: justify;
position: relative;
overflow: hidden;
margin: 0;
padding: 0;
}
ul:before {
content: '';
width: 96%;
border: 2px solid #21a2d1;
position: absolute;
top: 1em;
margin-top: -6px;
z-index: -1;
margin-left: 16px;
}
.active:after {
content: '';
width: 100%;
border: 2px solid #b7b7b7;
position: absolute;
top: 1em;
margin-top: -6px;
z-index: -1;
}
ul:after {
content: '';
display: inline-block;
width: 100%;
}
li {
width: 1.5em;
height: 1.5em;
text-align: center;
line-height: 1.7em;
border-radius: 50%;
background: #21a2d1;
margin: 0 1em;
display: inline-block;
}
.marker-number {
font-size: 14px;
}
li.active {
background: #04497b;
}
.active ~ li {
background: #b7b7b7;
}
span.marker-text {
color: #7d7d7d;
font-size: 12px;
line-height: 16px;
width: 70px;
display: block;
margin-left: -21px;
font-family: Arial;
}
<ul>
<li><span class="marker-number"> </span> <span class="marker-text">Select Car</span></li>
<li><span class="marker-number"> </span> <span class="marker-text">Questions</span></li>
<li class="active"><span class="marker-number"> </span> <span class="marker-text">Problems</span></li>
<li><span class="marker-number"> </span> <span class="marker-text">Inspection</span></li>
<li><span class="marker-number"> </span> <span class="marker-text">Solution</span></li>
</ul>
Here is a sample, using flexbox, with a minimal markup, and for the marker the ::before pseudo and the line the ::after pseudo (starting from the 2:nd position)
ul.wizard, ul.wizard li {
margin: 0;
padding: 0;
display: flex;
width: 100%;
}
ul.wizard {
counter-reset: num;
}
ul.wizard li {
flex-direction: column;
align-items: center;
position: relative;
}
ul.wizard li::before {
counter-increment: num;
content: counter(num);
width: 1.5em;
height: 1.5em;
text-align: center;
line-height: 1.5em;
border-radius: 50%;
background: #21a2d1;
}
ul.wizard li ~ li::after {
content: '';
position: absolute;
width: 100%;
right: 50%;
height: 4px;
background-color: #21a2d1;
top: calc(.75em - 2px);
z-index: -1;
}
ul.wizard li.active::before {
background: #04497b;
color: white;
}
ul.wizard .active ~ li::before,
ul.wizard .active ~ li::after {
background: #b7b7b7;
}
ul.wizard span {
color: #7d7d7d;
font-size: 12px;
font-family: Arial;
}
/* updated sample */
ul.wizard li.completed::before { /* number and circle */
background: red;
color: white;
}
ul.wizard li.completed span { /* text */
color: red;
}
ul.wizard li.completed + li::after { /* line after circle */
background: red;
}
ul.wizard li.completed::after { /* line before circle */
background: red;
}
<ul class="wizard">
<li>
<span>Select Car</span>
</li>
<li class="completed">
<span>Questions</span>
</li>
<li class="active">
<span>Problems</span>
</li>
<li>
<span>Inspection</span>
</li>
<li>
<span>Solution</span>
</li>
</ul>
This can also be done without flexbox, if you need to target older browsers
ul.wizard, ul.wizard li {
margin: 0;
padding: 0;
}
ul.wizard {
counter-reset: num;
}
ul.wizard li {
list-style-type: none;
float: left;
width: 20%;
position: relative;
text-align: center;
}
ul.wizard li::before {
display: block;
counter-increment: num;
content: counter(num);
width: 1.5em;
height: 1.5em;
text-align: center;
line-height: 1.5em;
border-radius: 50%;
background: #21a2d1;
margin: 0 auto;
}
ul.wizard li ~ li::after {
content: '';
position: absolute;
width: 100%;
right: 50%;
height: 4px;
background-color: #21a2d1;
top: calc(.75em - 2px);
z-index: -1;
}
ul.wizard li.active::before {
background: #04497b;
color: white;
}
ul.wizard .active ~ li::before,
ul.wizard .active ~ li::after {
background: #b7b7b7;
}
ul.wizard span {
display: inline-block;
color: #7d7d7d;
font-size: 12px;
font-family: Arial;
}
<ul class="wizard">
<li>
<span>Select Car</span>
</li>
<li>
<span>Questions</span>
</li>
<li class="active">
<span>Problems</span>
</li>
<li>
<span>Inspection</span>
</li>
<li>
<span>Solution</span>
</li>
</ul>
Reduce width of pseudo element :befor to 90% and :after to 45% but you have to write it always different width percentages as per the activated li tag and as per screen size. I think If you modify your markup a little bit which will help you more and make the complications less.
============================================================
Changed markup as you required and few tweaks in css
ul {
text-align: justify;
position: relative;
overflow: hidden;
margin: 0;
padding: 0;
display: inline-flex;
justify-content: space-around;
width: 100%;
}
li {
position: relative;
width: 20%;
text-align: center;
display: inline;
padding-bottom: 20px;
}
.marker-number {
width: 1.5em;
height: 1.5em;
text-align: center;
line-height: 1.7em;
border-radius: 50%;
background: #21a2d1;
display: inline-block;
}
.marker-line {
position: absolute;
width: 100%;
height: 4px;
background-color: #21a2d1;
top: 10px;
}
li.active span.marker-number,
li.active span.marker-line {
background: #04497b;
}
.active ~ li span.marker-number,
.active ~ li span.marker-line {
background: #b7b7b7;
}
span.marker-text {
color: #7d7d7d;
font-size: 12px;
line-height: -15px;
font-family: Arial;
position: absolute;
left: 0;
right: 0;
bottom: 0;
}
<ul>
<li>
<span class="marker-number"> </span>
<span class="marker-line"></span>
<span class="marker-text">Select Car</span>
</li>
<li>
<span class="marker-number"> </span>
<span class="marker-line"></span>
<span class="marker-text">Questions</span>
</li>
<li class="active">
<span class="marker-number"> </span>
<span class="marker-line"></span>
<span class="marker-text">Problems</span>
</li>
<li>
<span class="marker-number"> </span>
<span class="marker-line"></span>
<span class="marker-text">Inspection</span>
</li>
<li>
<span class="marker-number"> </span>
<span class="marker-text">Solution</span>
</li>
</ul>

CSS Drop-down menu: second level positioning?

So I'm working on a CSS drop down menu where the div container is revealed by a radio button and I have that working as I'd like.
However, I'd like to add a second level to my drop-down just like it (same width, positioning beneath parent, ect..) I have it revealing the second level when you click on the input, however, If the input is in the middle (in between two links) my first level's links move beneath my first level of sub-menu. Please help? I can't figure out how to keep it looking the same way it's just if that input has another sub menu I would like for it to drop down below the first.
My code:
/*CSS for Menu */
.menu {
position: fixed;
top: 0;
left: 0;
height: 20px;
width: 100%;
z-index: 10000;
display: inline-block;
background-image: black url(../images/glossyback.gif);
background-color: #0066CC;
text-align: center;
font-family: Arial, Geneva, sans-serif;
}
/*CSS for main menu labels */
input + label {
color: #FFFFFF;
display: inline-block;
padding: 6px 8px 10px 24px;
background-image: black url(../images/glossyback2.gif);
height: 8px;
margin: 0;
line-height: 12px;
position: relative;
}
input:hover + label:hover {
background: #3385D6;
}
input + label + div {
margin: 0;
margin-top: 2px;
padding: 16px;
border: 1px solid;
width: 100%;
height: auto;
position: absolute;
top: 20px;
display: none;
}
input:checked + label + div {
display: block;
}
/*CSS for main menu labels within menu class*/
.menu input {
display: none;
opacity: .3;
margin-right: -.7em;
margin-left: 0em;
overflow: visible;
}
.menu a {
text-decoration: none;
color: #FFFFFF;
}
.menu label span {
z-index: 1000;
font-size: 12px;
line-height: 9px;
padding: 6px 1em 12px 1em;
display: block;
margin-top: -1px;
background-image: url(../images/glossyback.gif) repeat-x bottom left;
}
.menu label span a:hover {
background-image: black url(../images/glossyback2.gif);
}
.menu input:checked + label {
background-color: #AFCEEE;
border-color: #6696CB;
z-index: 1000;
}
div.menu input + label {
z-index: 1000;
padding: 0;
border-color: #ccc;
border-width: 0 1px;
height: 19px;
margin: 0 -.23em;
}
/*CSS for submenu container */
.menu input + label + div {
position: absolute;
border: 1px solid #808080;
right: 0;
background: #F0F6FC;
text-align: center;
width: 100%;
margin: 0 auto;
}
.menu input + label + div > div {
z-index: 1000;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 1px solid #ABABAB;
padding: 16px;
padding-top: 5px;
}
/*CSS for sub menu items*/
.sub-menu {
font-size: 14px;
display: inline-block;
}
.sub-menu a {
text-decoration: none;
color: #EEEEEE;
}
.sub-menu ul {
list-style-type: none;
}
.sub-menu li {
width: 175px;
color: #F0F0F0;
background-color: #9CB9D7;
display: inline-block;
}
.sub-menu li:hover {
color: #FFFFFF;
text-decoration: none;
background-color: #3385D6;
}
/*CSS for sub-menu second level */
.sub-menu input[type=radio] {
display: none;
}
.sub-menu input[type=radio]:checked ~ .remove-check {
display: none;
}
.sub-menu input[type=radio]:checked ~ #second-level {
display: block;
}
#second-level {
display: none;
}
/* The styling of items, ect...*/
.sub-menu input[type=text] {
width: 225px;
padding: 12px 14px;
}
.sub-menu div {
border: 1px solid #808080;
right: 0;
background: #F0F6FC;
text-align: center;
width: 100%;
margin: 0 auto;
}
.sub-menu div div {
top: 90%;
z-index: 1000;
position: absolute;
border: 1px solid #ABABAB;
padding: 16px;
padding-top: 5px;
}
.sub-menu .second-level-items {
width: 175px;
color: #F0F0F0;
background-color: #9CB9D7;
display: inline-block;
}
<div class="menu">
<input type="radio" name="UItab" id="tabf">
<label for="tabf"><span>Styles</span>
</label>
<div>
<div>
<ul class="sub-menu">
<a href="">
<li id="linkj">First Link</li>
</a>
<label for="reveal-email">
<li>Tab in submenu</li>
</label>
<input type="radio" id="reveal-email">
<div id="second-level">
<div>
<a href="">
<li>Links2.0</li>
</a>
</div>
</div>
<label for="reveal-email">
<li>Tab in submenu</li>
</label>
<input type="radio" id="reveal-email">
<div id="second-level">
<div>
<a class="second-level-items" href="">
<li>Links2.0</li>
</a>
</div>
</div>
<a href="">
<li id="linkj">First Link</li>
</a>
</div>
</div>
</div>