I am currently playing arround with customizing lists in HTML and CSS, so I tried to use custom images to be used for the li 'dot'.
However, it is not shown. Could someone tell me whats wrong with this code snippet?
body {
margin:0;
}
.container {
display:flex;
flex-wrap:wrap;
flex-direction:row;
height:100vh;
background-color: white;
}
.container > div {
min-height: 100vh;
border: 1px solid black;
box-sizing:border-box;
background-color: inherit;
}
container > div .content{
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width:100%;
}
.half-width {
width:50%;
}
.half-width > .half-width-content{
position: relative;
margin-top: 0;
height: 100%;
width: 100%;
}
list-div {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.list-div ul {
padding: 0;
width: 75%;
}
.list-div li {
position: relative;
margin-bottom: 5px;
padding: 10px;
text-align: left;
visibility: visible;
text-transform: uppercase;
}
.list-div li:nth-child(1){
list-style-image: url('https://fakeimg.pl/30x30/?text=A');
list-style-position: outside;
}
<div class="container">
<div class="half-width">
<div class="half-width-content">
<div class="list-div">
<ul class="items-list" id="list">
<li>List item A</li>
<li>List item B</li>
<li>List item C</li>
<li>List item D</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Use list-style-type: none; and
margin-left:40px; to li
body {
margin:0;
}
.container {
display:flex;
flex-wrap:wrap;
flex-direction:row;
height:100vh;
background-color: white;
}
.container > div {
min-height: 100vh;
border: 1px solid black;
box-sizing:border-box;
background-color: inherit;
}
container > div .content{
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width:100%;
}
.half-width {
width:50%;
}
.half-width > .half-width-content{
position: relative;
margin-top: 0;
height: 100%;
width: 100%;
}
list-div {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.list-div ul {
padding: 0;
width: 75%;
}
.list-div li {
position: relative;
margin-bottom: 5px;
padding: 10px;
text-align: left;
visibility: visible;
text-transform: uppercase;
list-style-type: none;
margin-left:40px;
}
.list-div li:nth-child(1){
list-style-image: url('https://fakeimg.pl/30x30/?text=A');
list-style-position: outside;
}
<div class="container">
<div class="half-width">
<div class="half-width-content">
<div class="list-div">
<ul class="items-list" id="list">
<li>List item A</li>
<li>List item B</li>
<li>List item C</li>
<li>List item D</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Edit to your comment center li with image use as below to .list-div li:nth-child(1)
background: url(https://fakeimg.pl/30x30/?text=A);
list-style-type: none;
margin: 0;
padding: 10px 10px 10px 48px;
vertical-align: middle;
background-repeat: no-repeat;
body {
margin:0;
}
.container {
display:flex;
flex-wrap:wrap;
flex-direction:row;
height:100vh;
background-color: white;
}
.container > div {
min-height: 100vh;
border: 1px solid black;
box-sizing:border-box;
background-color: inherit;
}
container > div .content{
height: 100vh;
width: 100vw;
background-color: inherit;
}
.full-width {
width:100%;
}
.half-width {
width:50%;
}
.half-width > .half-width-content{
position: relative;
margin-top: 0;
height: 100%;
width: 100%;
}
list-div {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.list-div ul {
padding: 0;
width: 75%;
}
.list-div li {
position: relative;
margin-bottom: 5px;
padding: 10px;
text-align: left;
visibility: visible;
text-transform: uppercase;
list-style-type: none;
margin-left:40px;
}
.list-div li:nth-child(1){
background: url(https://fakeimg.pl/30x30/?text=A);
list-style-type: none;
margin: 0;
padding: 10px 10px 10px 48px;
vertical-align: middle;
background-repeat: no-repeat;
}
<div class="container">
<div class="half-width">
<div class="half-width-content">
<div class="list-div">
<ul class="items-list" id="list">
<li>List item A</li>
<li>List item B</li>
<li>List item C</li>
<li>List item D</li>
</ul>
</div>
</div>
</div>
</div>
</div>
Related
I am trying to make this dropdown button using flexbox but it's not working as I want. It's not displaying when I hover around the button using display properties. Can someone edit this code so that the dropdown menu works?
Is this what you want
function Enable(){
x = document.getElementById("Ulist");
if(x.className == "display"){
x.className += " active";
}else{
x.className == "display";
}
}
li{
list-style: none;
}
.Maincover{
display: flex;
flex-direction: column;
align-items: center;
height: 300px;
}
button{
font-family: montserrat;
font-weight: 500;
width: 100px;
border-radius: 5px;
color: white;
border: 0px;
padding: 5px 10px;
text-align: center;
background-color: tomato;
}
.list{
font-family: rubik;
text-align: center;
margin-top: 10px;
}
.display{
padding:0px;
display: none;
}
.display.active{
display: block;
}
.hoverbutton:hover ~ .display{
display: block;
}
<div class="Maincover">
<button class="hoverbutton" onclick="Enable()">Hover Here</button>
<ul class="display" id="Ulist">
<li class="list" id="lists">List item 1</li>
<li class="list" id="lists">List item 2</li>
<li class="list" id="lists">List item 3</li>
</ul>
</div>
Here I have attached the html and css code for hoverable dropdown menu using flex.
.menu-area{
margin: 0;
padding: 0;
box-sizing: border-box;
width:150px;
display:flex;
flex-direction:column;
justify-content:center;
}
.menu-area a{
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background: darkslategrey;
height: 60px;
font-family:Poppins;
font-weight: bold;
text-decoration: none;
}
.menu-area a:hover{
background: tomato;
color: #fff;
}
.menu-area ul{
list-style: none;
display: flex;
}
.menu-area li{
position: relative;
width: 100%;
text-align: center;
}
.menu-area li:hover .dropdown-1 > li{
display: block;
top: 0;
}
.dropdown-1 li{
display: none;
position: relative;
}
.dropdown-1{
position: absolute;
display: flex;
flex-direction: column;
width: 100%;
}
.dropdown-1 li:hover .dropdown-2 li{
display: block;
}
.dropdown-2 li{
display: none;
}
.dropdown-2{
display: flex;
flex-direction: column;
position: absolute;
top: 0;
left: 100%;
width: 100%;
}
.banner-area{
background-image: linear-gradient(rgba(0,0,0,0.5),rgba(0,0,0,0.5)),url(https://i.postimg.cc/Y0YM36yL/aa.jpg);
-webkit-background-size:cover;
background-size:cover;
background-position: center center;
display: flex;
align-items: center;
justify-content: center;
height: calc(100vh - 60px);
}
.banner-area h1 {
text-transform: uppercase;
color: #fff;
font-size: 100px;
font-family: poppins;
letter-spacing: 2px;
}
<div class="menu-area">
<ul>
<li>Dropdown
<ul class="dropdown-1">
<li>service one</li>
<li>service two</li>
<li>service three
</li>
</ul>
</li>
</ul>
</div>
As you can see in the snippet below, if you start resizing the browser, the <div> element with class="cities-list" begins resizing instantly.
What I hope to achieve is have the <div> element with class="cities-list" not shrink down until there is no more empty space on the left and right of it where the margin of the wrapper used to be.
Am I going about this the wrong way?
*, *:after, *:before {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
list-style-type: none;
}
html {
font-size: 16px;
}
body {
background-color: #fafafa;
background-color: #f2f2f2;
font-family: 'Roboto', sans-serif;
height: 100%;
width: 100%;
line-height: 1.8rem;
}
.wrapper {
width: 70%;
margin: 0 auto;
}
.nav {
background: linear-gradient(-45deg, #57cfb0, #2ab5d3);
}
.nav-ul {
display: flex;
}
.nav li {
padding: 11px 30px 11px 0;
color: #ffffff;
cursor: pointer;
font-weight: 500;
}
.nav li:nth-last-child(2) {
margin-left: auto;
}
.nav li:last-child {
padding-right: 0px;
}
.cities-list {
display: flex;
margin-bottom: 10px;
}
.cities-list p {
background-color: #ffffff;
padding: 20px;
margin: 10px 10px 10px 0px;
cursor: pointer;
flex-basis: 49.5%;
text-align: center;
}
<div class="nav">
<div class="wrapper">
<ul class='nav-ul'>
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
</div>
</div>
<div class='wrapper'>
<div class='cities-list'>
<p>Tokyo, Japan</p>
<p>London, United Kingdom</p>
</div>
</div>
You need to set a min-width to your .cities-list and also width: 100% to your wrapper, above some breakpoint like this:
#media (min-width: 1200px) {
.cities-list-wrapper {
width: 100%;
display: flex;
justify-content: center;
}
.cities-list {
min-width: 1180px;
max-width: 1180px;
}
}
(I added class cities-list-wrapper to your wrapper)
*, *:after, *:before {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-decoration: none;
list-style-type: none;
}
html {
font-size: 16px;
}
body {
background-color: #fafafa;
background-color: #f2f2f2;
font-family: 'Roboto', sans-serif;
height: 100%;
width: 100%;
line-height: 1.8rem;
}
.wrapper {
width: 70%;
margin: 0 auto;
}
.nav {
background: linear-gradient(-45deg, #57cfb0, #2ab5d3);
}
.nav-ul {
display: flex;
}
.nav li {
padding: 11px 30px 11px 0;
color: #ffffff;
cursor: pointer;
font-weight: 500;
}
.nav li:nth-last-child(2) {
margin-left: auto;
}
.nav li:last-child {
padding-right: 0px;
}
.cities-list {
display: flex;
margin-bottom: 10px;
}
.cities-list p {
background-color: #ffffff;
padding: 20px;
margin: 10px 10px 10px 0px;
cursor: pointer;
flex-basis: 49.5%;
text-align: center;
}
#media (min-width: 1200px) {
.cities-list-wrapper {
width: 100%;
}
.cities-list {
min-width: 1180px;
max-width: 1180px;
margin: auto;
}
}
<div class="nav">
<div class="wrapper">
<ul class='nav-ul'>
<li>Test 1</li>
<li>Test 2</li>
<li>Test 3</li>
<li>Test 4</li>
</ul>
</div>
</div>
<div class='wrapper cities-list-wrapper'>
<div class='cities-list'>
<p>Tokyo, Japan</p>
<p>London, United Kingdom</p>
</div>
</div>
not shrink down until there is no more empty space on the left and right of it where the margin of the wrapper used to be
Did you mean in the mobile size?
just use media query
#media (max-width: 767px){
.wrapper {
width: 100%;
}
}
How to put the picture in the left side of my navbar?
I can't seem to understand how it works- the picture is going up and the navbar is outside the div.
body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
}
#logo {
width: 50%;
height: 50%;
}
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img class="logo" src="logo.gif">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
use this code
#navbar{
position: absolute;
right: 20px;
display: flex;
flex-direction: row;
justify-content: space-between;
}
In the case you want to use flexbox, you may try this:
favorite body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
/*****************/
display:flex;
justify-content:space-between;
align-items:center;
/*****************/
}
#logo {
width: 50%;
height: 50%;
}
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img width="40" class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/apple.png">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
1-Access class logo by '.'
2-apply positioning to class logo as i applied and set height and width of class
3- set width of also
heres my code
favorite body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
/*****************/
display:flex;
justify-content:space-between;
align-items:center;
/*****************/
}
.logo {
position :relative;
top: 0px;
width: 10%;
height: 27%;
}
ul {
list-style: none;
background-color: red;
width: 90%;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img width="40" class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/apple.png">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
down vote favorite body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
}
#logo {
width: 50%;
height: 50%;
}
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img class="logo" src="logo.gif">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
use this css
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
display: inline-block;
}
I have a row of 3 elements and for some reason I can't get the left side nav list to work with inline-block. It works for the second and I've come across this problem before but don't remember the exact reasoning behind the problem since that was when I first started to learn to build websites.
#nav {
display: block;
clear: both;
width: 100%;
min-width: 1200px;
height: 50px;
margin-right: auto;
margin-left: auto;
}
#nav_left {
display: block;
float: left;
margin-left: auto;
margin-right: auto;
width: 36.5%;
height: 40px;
text-align: left;
}
#nav_left ul {
font-size: 19px;
letter-spacing: 1px;
list-style-type:none;
}
#nav_nav li {
width: 15%;
display: inline-block;
}
#nav_left li a {
text-decoration: none;
}
#center {
display: block;
margin-left: auto;
margin-right: auto;
font-weight: bold;
font-size: 20px;
letter-spacing: 1px;
width: 24%;
height: 40px;
text-align: center;
}
#nav_right {
display: block;
float: right;
margin-top: -44px;
margin-left: auto;
margin-right: auto;
width: 36.5%;
height: 40px;
text-align: left;
}
#nav_right ul {
font-size: 19px;
letter-spacing: 1px;
list-style-type:none;
}
#nav_right li {
width: 15%;
display: inline-block;
}
#nav_right li a {
text-decoration: none;
}
<section id="nav">
<div id="nav_left">
<ul>
<li>item
</li>
<li>item
</li>
<li>item
</li>
</ul>
</div>
<div id="center">
<p>words here</p>
</div>
<div id="nav_right">
<ul>
<li>item
</li>
<li>item
</li>
<li>item
</li>
</ul>
</div>
</section>
I appreciate any help given, thanks.
The reason is you had typo with #nav_left
You have:
#nav_nav li {
width: 15%;
display: inline-block;
}
Change it to:
#nav_left li {
width: 15%;
display: inline-block;
}
Snippet Demo below:
#nav {
display: block;
clear: both;
width: 100%;
min-width: 1200px;
height: 50px;
margin-right: auto;
margin-left: auto;
}
#nav_left {
display: block;
float: left;
margin-left: auto;
margin-right: auto;
width: 36.5%;
height: 40px;
text-align: left;
}
#nav_left ul {
font-size: 19px;
letter-spacing: 1px;
list-style-type: none;
}
#nav_left li {
width: 15%;
display: inline-block;
}
#nav_left li a {
text-decoration: none;
}
#center {
display: block;
margin-left: auto;
margin-right: auto;
font-weight: bold;
font-size: 20px;
letter-spacing: 1px;
width: 24%;
height: 40px;
text-align: center;
}
#nav_right {
display: block;
float: right;
margin-top: -44px;
margin-left: auto;
margin-right: auto;
width: 36.5%;
height: 40px;
text-align: left;
}
#nav_right ul {
font-size: 19px;
letter-spacing: 1px;
list-style-type: none;
}
#nav_right li {
width: 15%;
display: inline-block;
}
#nav_right li a {
text-decoration: none;
}
<section id="nav">
<div id="nav_left">
<ul>
<li>item
</li>
<li>item
</li>
<li>item
</li>
</ul>
</div>
<div id="center">
<p>words here</p>
</div>
<div id="nav_right">
<ul>
<li>item
</li>
<li>item
</li>
<li>item
</li>
</ul>
</div>
</section>
I am working on a simple UL based horizontal navigation. What I would like is for the clickable area to match the height and width of each LI. I have tried a lot of variations on this theme, but this is about the happiest compromise shown below, where I get about half the area within each LI to be clickable when the text is aligned in the middle. Thanks for any input.
body {
background-color: #ffaa00;
}
#main {
width: 1200px;
height: 890px;
margin: 0 auto;
}
#content {
width: 100%;
height: 100%;
border: 1px solid #000;
background-color: #fff;
margin: 0;
padding: 0;
}
#nav {
height: 50px;
width: 100%;
background-color: #ccc;
}
ul {
margin-top: 0;
padding-left: 0;
list-style-type: none;
}
li {
display: table-cell;
height: 50px;
width: 190px;
vertical-align: middle;
text-align: center;
}
li:hover {
background-color: #999;
border-radius: 6px;
}
a {
display: inline-block;
height: 25px;
width: 190px;
}
<div id="main">
<div id="content">
<div id="nav">
<ul>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
</div>
</div>
You have to change height to 100% and use :before to vertical-align text middle.
body {
background-color: #ffaa00;
}
#main {
width: 1200px;
height: 890px;
margin: 0 auto;
}
#content {
width: 100%;
height: 100%;
border: 1px solid #000;
background-color: #fff;
margin: 0;
padding: 0;
}
#nav {
height: 50px;
width: 100%;
background-color: #ccc;
}
ul {
margin-top: 0;
padding-left: 0;
list-style-type: none;
}
li {
display: table-cell;
height: 50px;
width: 190px;
vertical-align: middle;
text-align: center;
}
li:hover {
background-color: #999;
border-radius: 6px;
}
a {
display: inline-block;
height: 100%;
width: 190px;
}
a:before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
}
<div id="main">
<div id="content">
<div id="nav">
<ul>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
</div>
</div>