I am trying to create a simple structure of blocks using only HTML and CSS. In the center I have one main block from which other blocks branch off to the left and right.
All of them should be connected by lines to other blocks, but how to create these lines is a question...
I have some code:
.chapter {
display: flex;
align-items: center;
justify-content: center;
max-width: 900px;
margin: 0 auto;
padding: 0;
gap: 2rem;
}
.main {
position: relative;
padding: 1rem 2rem;
background-color: rgb(224, 224, 224);
border: 1px solid black;
}
.main::before,
.main::after {
content: "";
position: absolute;
top: 50%;
display: block;
width: 1rem;
height: 1px;
background-color: #000;
}
.main::before {
left: -1rem;
}
.main::after {
right: -1rem;
}
.right,
.left {
list-style-type: none;
margin: 0;
padding: 0;
}
.elem {
position: relative;
padding: 0.3rem 2rem;
background-color: rgb(224, 224, 224);
border: 1px solid black;
margin-bottom: 0.5rem;
}
.elem:last-child {
margin-bottom: 0px;
}
.elem::after {
content: "";
position: absolute;
top: 50%;
display: block;
width: 1rem;
height: 1px;
background-color: #000;
}
.left>.elem::after {
right: -1rem;
}
.right>.elem::after {
left: -1rem;
}
<div class="chapter">
<ul class="left">
<li class="elem">elem</li>
<li class="elem">elem</li>
<li class="elem">elem</li>
<li class="elem">elem</li>
<li class="elem">elem</li>
</ul>
<div class="main">root</div>
<ul class="right">
<li class="elem">elem</li>
<li class="elem">elem</li>
<li class="elem">elem</li>
<li class="elem">elem</li>
<li class="elem">elem</li>
</ul>
</div>
And what I get and what I want:
Is it possible to achieve this arrangement of lines?
Or perhaps there is another more elegant way to do it?
Related
Above is a mockup of the content that I am trying to replicate.
Here is what I have right now:
below are my <ul> and <li> with CSS but I cannot exactly replicate what is in the mockup even if I use padding or margin:
ul {
padding: 0;
list-style: none;
}
#b1::before {
content: "• ";
color: #B1B1B1;
}
#b2::before {
content: '|';
color: #B1B1B1;
margin-bottom: 20px;
}
<ul>
<li id="b1">Introduction</li>
<li id="b2"></li>
<li id="b1">Disclaimers</li>
<li id="b2"></li>
<li id="b1">Preservation of Immunities</li>
<li id="b2"></li>
<li id="b1">General</li>
</ul>
looking for another way to edit the CSS that is not padding or margin to get the design I need. Any help would be appreciated.
#import "https://cdn.jsdelivr.net/gh/KunalTanwar/normalize/css/normalize.inter.min.css";
body {
height: 100%;
display: grid;
place-items: center;
}
ul {
display: flex;
row-gap: 16px;
flex-direction: column;
}
li {
display: flex;
line-height: 1;
padding-left: 8px;
align-items: center;
}
li::before {
content: "";
position: absolute;
left: -12px;
width: 8px;
height: 8px;
border-radius: 50%;
aspect-ratio: 1/1;
background-color: gray;
box-shadow: 0 0 0 2px white;
}
li:not(:last-child)::after {
content: "";
z-index: -1;
position: absolute;
top: calc(100% - 6px);
left: -8px;
width: 1px;
height: 32px;
background-color: #CCCCCC;
}
<ul>
<li id="b1">Introduction</li>
<li id="b1">Disclaimers</li>
<li id="b1">Preservation of Immunities</li>
<li id="b1">General</li>
</ul>
I have a dropdown menu consists of ul nested in another ul's list item position absolute.
indeed I want the child ul that represents the dd menu to take its parent li width but it takes its grandparent's ul width instead.
changing the position to relative will disrupt the li style/order don't know why.
nav {
position: relative;
display: flex;
width: 100%;
margin: 0 auto;
justify-content: space-between;
}
nav>ul.nav_list {
position: relative;
display: flex;
justify-content: space-around;
align-items: flex-start;
height: 40px;
}
nav>ul>li {
height: 100%;
margin: 0px 4px;
padding: 0px 8px;
font-size: 18px;
}
nav>ul>li>div {
border-bottom: 2px solid #D88B1D;
padding: 8px 9.5px 2px;
transition: border-bottom .1s;
line-height: 22px;
}
nav>ul>li>div:hover {
border-bottom: 4px solid #D88B1D;
}
.first {
display: flex;
justify-content: center;
width: 242px;
}
li.dropdown {
font-size: 18px;
font-weight: bold;
}
.dropdown:hover {
display: flex;
justify-content: center;
background-color: #42526e;
border-radius: 5px 5px 0px 0px;
}
.dropdown:hover>div.first {
border: none;
}
nav>ul>li>ul.dropdown-content {
position: absolute;
top: 100%;
left: 0;
width: 100%;
display: none;
background-color: gold;
z-index: 99;
}
li.dropdown:hover>ul.dropdown-content {
display: block;
}
.dropdown:hover>div.first>a {
color: white;
}
<nav>
<ul class="nav_list">
<li class="dropdown">
<div class="first">
All Catgories
</div>
<ul class="dropdown-content">
<li> Link1</li>
<li> Link2</li>
<li> Link3</li>
</ul>
</li>
<li>
<div>Shop by brand</div>
</li>
<li>
<div>Online Exclusive</div>
</li>
</ul>
</nav>
When you need to position: absolute an element relatively to its parent, you need the parent to have it's own stacking context. So the parent becomes an offsetParent -- its offset boundaries will be used for positioning.
In your case, you have to set position: relative to li.dropdown.
Then, on ul.dropdown-content, set left: 0; right:0; to stretch it between left and right boundaries so it takes 100% of parent's width:
nav>ul.nav_list {
display: flex;
justify-content: space-around;
align-items: flex-start;
height: 40px;
}
nav>ul>li {
height: 100%;
margin: 0px 4px;
padding: 0px 8px;
font-size: 18px;
}
nav>ul>li>div {
border-bottom: 2px solid #D88B1D;
padding: 8px 9.5px 2px;
transition: border-bottom .1s;
line-height: 22px;
}
nav>ul>li>div:hover {
border-bottom: 4px solid #D88B1D;
}
.first {
text-align: center;
width: 242px;
}
li.dropdown {
font-size: 18px;
font-weight: bold;
position:relative;
}
.dropdown:hover {
background-color: #42526e;
border-radius: 5px 5px 0px 0px;
}
.dropdown:hover>div.first {
border: none;
}
nav>ul>li>ul.dropdown-content {
position: absolute;
top: 100%;
right:0; left: 0;
display: none;
background-color: gold;
}
li.dropdown:hover>ul.dropdown-content {
display: block;
}
.dropdown:hover>div.first>a {
color: white;
}
<nav>
<ul class="nav_list">
<li class="dropdown">
<div class="first">
All Catgories
</div>
<ul class="dropdown-content">
<li> Link1</li>
<li> Link2</li>
<li> Link3</li>
</ul>
</li>
<li>
<div>Shop by brand</div>
</li>
<li>
<div>Online Exclusive</div>
</li>
</ul>
</nav>
I am trying to use HTML and CSS instead of images to show some arrows -- Here is the image:
I'm trying to make these arrows with before and after pseudo-elements, but I have got problems.
Here's my code:
HTML:
<ul class="steps-list">
<li class="step-item">
Contact us
</li>
<li class="step-item">
Consult with RCIC
</li>
<li class="step-item">
Apply via your pathway
</li>
<li class="step-item">
Settle in Canada
</li>
</ul>
SASS:
.steps-list {
display: flex;
.step-item {
display: inline-block;
text-align: center;
width: 25%;
.step-link {
font-weight: bold;
background: #e2e3e4;
width: 100%;
display: inline-block;
padding: 2rem 1rem;
&:hover {
#include gradient(left, $gradientList2);
}
}
}
}
I have followed this article by the way:
https://css-tricks.com/snippets/css/css-triangle/
[Edit] After looking at your image again, I failed to account for the first element being flat. I have updated my answer.
Using before,after, and nth-child selectors, you can achieve what you showed in your image. The before and after pseudo elements are used to create the top and bottom half of the arrows while the nth-child selectors are used to make the arrows appear to be progressively closer together.
.steps-list {
display: flex;
list-style: none;
}
.steps-list .step-item {
position: relative;
display: flex;
align-items:center;
text-align: center;
width: 25%;
}
.steps-list .step-item .step-link {
font-weight: bold;
width: 100%;
display: inline-block;
padding:10px 5px;
box-sizing:border-box;
}
.step-link::before {
content: "";
display: block;
position: absolute;
transform: skew(-40deg, 0);
background: #e2e3e4;
height: 50%;
bottom: 0;
z-index: -1;
left:5px;
}
.step-link::after {
content: "";
display: block;
position: absolute;
transform: skew(40deg, 0);
background: #e2e3e4;
height: 50%;
top: 0;
z-index: -1;
left:5px;
}
.step-item:nth-child(1){
overflow:hidden;
}
.step-item:nth-child(1) .step-link::after {
width:95%;
left:-15px;
}
.step-item:nth-child(1) .step-link::before {
width: 95%;
left:-15px;
}
.step-item:nth-child(2) .step-link::after {
width: 90%;
}
.step-item:nth-child(2) .step-link::before {
width: 90%;
}
.step-item:nth-child(3) .step-link::after {
width: 95%;
}
.step-item:nth-child(3) .step-link::before {
width: 95%;
}
.step-item:nth-child(4) .step-link::after {
width: 100%;
}
.step-item:nth-child(4) .step-link::before {
width: 100%;
}
<ul class="steps-list">
<li class="step-item">
Contact us
</li>
<li class="step-item">
Consult with RCIC
</li>
<li class="step-item">
Apply via your pathway
</li>
<li class="step-item">
Settle in Canada
</li>
</ul>
Check this site
.clearfix:after {
clear: both;
content: "";
display: block;
height: 0;
}
.container {
font-family: 'Lato', sans-serif;
width: 1000px;
margin: 0 auto;
}
.wrapper {
display: table-cell;
height: 400px;
vertical-align: middle;
}
.nav {
margin-top: 40px;
}
.arrow-steps .step {
font-size: 14px;
text-align: center;
color: #666;
cursor: default;
margin: 0 3px;
padding: 10px 10px 10px 30px;
min-width: 180px;
float: left;
position: relative;
background-color: #d9e3f7;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
transition: background-color 0.2s ease;
}
.arrow-steps .step:after,
.arrow-steps .step:before {
content: " ";
position: absolute;
top: 0;
right: -17px;
width: 0;
height: 0;
border-top: 19px solid transparent;
border-bottom: 17px solid transparent;
border-left: 17px solid #d9e3f7;
z-index: 2;
transition: border-color 0.2s ease;
}
.arrow-steps .step:before {
right: auto;
left: 0;
border-left: 17px solid #fff;
z-index: 0;
}
.arrow-steps .step:first-child:before {
border: none;
}
.arrow-steps .step:first-child {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.arrow-steps .step span {
position: relative;
}
<div class="container">
<div class="wrapper">
<div class="arrow-steps clearfix">
<div class="step current"> <span> Step 1</span> </div>
<div class="step"> <span>Step 2 some words</span> </div>
<div class="step"> <span> Step 3</span> </div>
<div class="step"> <span>Step 4</span> </div>
</div>
</div>
</div>
I made a multiple levels menu by ul and li,but the second level text breaks in 2 lines like below picture :
Note : I can't use static width for second level menu (li2 class),because texts size is dynamic in this level and it can be 1 word or many words.
HTML :
<body>
<div class="top">
<ul class="ul1">
<li class="li1">home</li>
<li class="li1">accessories
<ul class="ul2">
<li class="li2">cases and protectors
<ul class="ul3">
<li class="li3">case 1</li>
<li class="li3">case 2</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</body>
CSS :
body {
direction: rtl;
margin: 0;
}
.top {
position: fixed;
top: 0;
right: 0;
left: 0;
height: 48px;
}
.ul1 {
padding: 0;
margin: 0 auto 0 auto;
display: table;
height: 48px;
list-style: none;
background-color: #bdbdbd;
}
.li1 {
padding: 0 20px 0 20px;
margin: 0;
line-height: 48px;
float: right;
border: solid 1px #FFF;
position: relative;
}
.li1:hover .ul2 {
display: block;
}
.ul2 {
padding: 0;
margin: 0;
list-style: none;
background-color: #ffd800;
display: none;
position: absolute;
top: 49px;
right: 0;
width: auto;
}
.li2 {
padding: 0;
margin: 0;
height: 48px;
width: auto;
line-height: 48px;
background-color: #808080;
display: block;
}
.ul3
{
display:none;
}
and here is a live demo,what am I doing wrong?
One quick solution is to add white-space: nowrap; to element with class .li2:
nowrap
Collapses whitespace as for normal, but suppresses line breaks
(text wrapping) within text.
body {
direction: rtl;
margin: 0;
}
.top {
position: fixed;
top: 0;
right: 0;
left: 0;
height: 48px;
}
.ul1 {
padding: 0;
margin: 0 auto 0 auto;
display: table;
height: 48px;
list-style: none;
background-color: #bdbdbd;
}
.li1 {
padding: 0 20px 0 20px;
margin: 0;
line-height: 48px;
float: right;
border: solid 1px #FFF;
position: relative;
}
.li1:hover .ul2 {
display: block;
}
.ul2 {
padding: 0;
margin: 0;
list-style: none;
background-color: #ffd800;
display: none;
position: absolute;
top: 49px;
width: auto;
left: 0;
overflow: hidden;
}
.li2 {
padding: 0;
margin: 0;
height: 48px;
width: auto;
line-height: 48px;
background-color: #808080;
display: block;
white-space: nowrap;
}
.ul3 {
display: none;
}
<div class="top">
<ul class="ul1">
<li class="li1">home</li>
<li class="li1">accessories
<ul class="ul2">
<li class="li2">cases and protectors
<ul class="ul3">
<li class="li3">case 1
</li>
<li class="li3">case 2
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
You can fix the issue with the align adding left: 0 and overflow: hidden and remove right: 0
Reference
white-space
I am trying to adjust the width of the drop down menu, to match the width of the horizontal menu divider, under "Internship Program"
Any assistance would be greatly appreciated, thank you in advance.
Website is as following: http://amchaminternship.org/testimonials.html
a {
color: white;
}
.menu {
background: url(http://amchaminternship.org/images/menu-tail.gif) repeat-x 0% 0%;
margin: 0; padding: 0;
width: 100%;
height: 43px;
position: relative;
z-index: 1;
top: 175px;
right: 0;
}
.menu-item {
background: url(http://amchaminternship.org/images/menu-divider.gif) no-repeat 0% 50%;
display: block;
line-height: 40px;
float: left;
font-size: 1.083em;
padding: 0em 2em;
}
.menu-item:nth-of-type(1) {
background: none;
}
.menu-submenu {
margin: 0;
padding: 0;
position: absolute;
left: -9999em;
top: -9999em;
background-color: #123f69;
border-radius: 5px 5px 5px 5px;
border: 1px solid white;
}
.menu-item:hover > .menu-submenu {
left: auto;
top: auto;
}
.menu-submenu-item {
display: block;
}
.menu:after {
content: "";
display: table;
clear: both;
}
<ul class="menu">
<p style="margin-top: 0pt; margin-bottom: 0pt;"></p>
<li class="menu-item">Home</li>
<li class="menu-item">Internship Program
<ul class="menu-submenu">
<li class="menu-submenu-item">FAQ</li>
<li class="menu-submenu-item">Testimonials</li>
</ul>
</li>
<li class="menu-item">Alumni</li>
<li class="menu-item">Donations</li>
<li class="menu-item"><a href="who_we_are.html">Who
We Are</a></li>
<li class="menu-item"><a href="photo_gallery.html">Photo
Gallery</a></li>
<li class="menu-item"><a href="contact_us.html">Contact
Us</a></li>
</ul>
just try it.
.menu-submenu{
min-width: 140px;
max-width: 140px;
width: auto;
margin-left: -5px;
text-indent: 5px;
}
I hope it will full fill your requirement.
Try giving width to the submenu item e.g.
.menu-submenu {
width: 140px;
}
Add this two lines in your .menu-submenu class
width: 140px;
padding-left: 10px;
Please Refer the given code :
.menu-submenu {
margin: 0;
padding: 0;
position: absolute;
left: -9999em;
top: -9999em;
background-color: #123f69;
border-radius: 5px 5px 5px 5px;
border: 1px solid white;
width: 140px;
padding-left: 10px;
}
I hope it may help you to get the idea. Now you can adjust width according your requirements
Thanks.
what you have to change is as
.menu-submenu {
margin: 0;
margin-left:-2em;
padding: 0 3em;
width:inherit;
}
by negative margin we shift the box and by inheriting width we give same width as parent
a {
color: white;
}
.menu {
background: url(http://amchaminternship.org/images/menu-tail.gif) repeat-x 0% 0%;
margin: 0; padding: 0;
width: 100%;
height: 43px;
position: relative;
z-index: 1;
top: 175px;
right: 0;
}
.menu-item {
background: url(http://amchaminternship.org/images/menu-divider.gif) no-repeat 0% 50%;
display: block;
line-height: 40px;
float: left;
font-size: 1.083em;
padding: 0em 2em;
}
.menu-item:nth-of-type(1) {
background: none;
}
.menu-submenu {
margin: 0;
margin-left:-2em;
padding: 0 3em;
width:inherit;
position: absolute;
left: -9999em;
top: -9999em;
background-color: #123f69;
border-radius: 5px 5px 5px 5px;
border: 1px solid white;
}
.menu-item:hover > .menu-submenu {
left: auto;
top: auto;
}
.menu-submenu-item {
display: block;
}
.menu:after {
content: "";
display: table;
clear: both;
}
<ul class="menu">
<p style="margin-top: 0pt; margin-bottom: 0pt;"></p>
<li class="menu-item">Home</li>
<li class="menu-item">Internship Program
<ul class="menu-submenu">
<li class="menu-submenu-item">FAQ</li>
<li class="menu-submenu-item">Testimonials</li>
</ul>
</li>
<li class="menu-item">Alumni</li>
<li class="menu-item">Donations</li>
<li class="menu-item"><a href="who_we_are.html">Who
We Are</a></li>
<li class="menu-item"><a href="photo_gallery.html">Photo
Gallery</a></li>
<li class="menu-item"><a href="contact_us.html">Contact
Us</a></li>
</ul>
Add below code.
.menu-submenu{
width:120px !important;
padding-left:10px;
}