Vote I want the rectangular less wide - html

Please check the below link to check the code in HTML and CSS and check the result. Please, I need the rectangular in the result to be less wide.
https://jsfiddle.net/Ahmed_abdelmeguid/6L8vbutw/5/
[enter image description here][1]
this is CSS code
.tictac_3 > ul {
width: 50%;
height: 20px;
display: flex;
flex-wrap: wrap;}
.tictac_3 > li {
width: 30%;
height: 30px;
font-size: 30px;
font-family: sans-serif;
background-color:lightblue;
margin: 5px;
list-style: none;
text-align: center;
float: left;
}
and below the HTML code
<ul class="tictac_3">
<li class=".tictac_3">X
<li class=".tictac_3">
<li class=".tictac_3">O
<li class=".tictac_3">
<li class=".tictac_3">X
<li class=".tictac_3">O
<li class=".tictac_3">X
<li class=".tictac_3">O
<li class=".tictac_3">
</ul>
you can check the code and the result that I want to modify it in the below link That I provided it in the start of my question
https://jsfiddle.net/Ahmed_abdelmeguid/6L8vbutw/5/

Problems
"Please, I need the rectangular in the result to be less wide"
OK, there are some problems with OP code that are at fundamental level:
Every <li> end tag </li> is missing
The selector: .tictac_3 > ul does not exist
height: 20px is assigned to the previously mentioned selector. If it referenced the <ul> as was intended, it would make very little sense since all of it's <li> are height: 30px
Changes
All of the classes on the <li> is removed, a single class on the <ul> is sufficient.
Added max-width: 12rem; to the <ul>
Each <li>
Changed height from an absolute value 30px to a relative value 2rem.
Changed font-size exactly as height was changed.
Decreased the margin from 5px to 1px
Added a little padding-bottom: 0.25em
.tictac {
display: flex;
flex-flow: row wrap;
width: 50%;
max-width: 12rem;
list-style: none;
}
.tictac li {
width: 30%;
height: 2rem;
font-size: 2rem;
font-family: sans-serif;
text-align: center;
margin: 1px;
padding-bottom: 0.1em;
background-color: lightblue;
}
<ul class="tictac">
<li>X</li>
<li></li>
<li>O</li>
<li></li>
<li>X</li>
<li>O</li>
<li>X</li>
<li>O</li>
<li></li>
</ul>

Related

How do I center a UL/LI in the same row as left-aligned text?

I've been trying to write a menubar that has two groupings in the same row across the top of a webpage: on the left is the site name and in the center should be the menu options (a ul/li). So far, following similar issues, I've written the following, which appears on first glance to do exactly what I'm seeking.
HTML:
<div class="menubar">
SITE NAME
<ul class="ul">
<li>MENU 0</li>
<li>MENU 1</li>
<li>MENU 2</li>
<li>MENU 3</li>
</ul>
</div>
CSS:
.menubar {
width: 100%;
height: 50px;
line-height: 50px;
vertical-align: middle;
background-color: #fff;
border-bottom: 1px solid #f5f5f5;
position: fixed;
top: 0;
display: flex;
flex-flow: row nowrap;
}
.logo {
width: 33.33%;
float: left;
margin-left: 20px;
font-size: 24px;
}
.ul {
font-size: 18px;
list-style: none;
padding: 0;
margin: 0;
}
.ul li {
margin-left: 15px;
margin-right: 15px;
display: inline-block;
}
However, if you look carefully in the JSFiddle (more apparent when widening browser windows or shrinking the window down just before the items begin wrapping), the 'centered' ul/li is not actually centered—it's closer to the left side of the browser window than the right. How do I fix this so that the ul/li remains truly centered in the menubar (as if the site name doesn't exist) with the left-aligned site name, regardless of what the browser window's width is? (I'm assuming within non-wrapping reason, since I plan to adjust sizes and behavior for smaller devices.)
JSFiddle
You're using a lot of margins, width and stuff. Check out flex here and you can get the same thing, properly aligned using flex and directions.
<!-- NEW CODE -->
<nav>
<div class="logo">
<span>Your Company</span>
</div>
<ul class="nav-items">
<li class="nav-item"> Menu 1 </li>
<li class="nav-item"> Menu 2 </li>
<li class="nav-item"> Menu 3 </li>
<li class="nav-item"> Menu 4 </li>
</ul>
</nav>
<!-- OLD CODE -->
<nav>
<div class="logo">
<img src="https://placehold.it/200x200" alt="logo">
</div>
<div class="menu-items">
<div class="menu-item"> Menu 0 </div>
<div class="menu-item"> Menu 1 </div>
<div class="menu-item"> Menu 2 </div>
<div class="menu-item"> Menu 3 </div>
</div>
</nav>
and the css
// MORE PROPERTIES
nav {
align-items: center;
}
nav div.logo {
position: absolute;
}
// OLD-NEW CSS
nav {
display: flex;
border: 1px solid pink;
}
nav div.logo {
border: 1px solid green;
display: flex;
align-items: center;
}
nav div.logo span {
padding: 0 0.5rem;
}
ul.nav-items {
border: 1px solid red;
display: flex;
flex-direction: row;
list-style-type: none;
margin: 0 auto;
padding: 0;
}
ul.nav-items li {
margin: 0 0.25rem;
padding: 0.5rem;
border: 1px solid blue;
}
// OLD CSS
nav {
display: flex;
}
nav div.menu-items {
display: flex;
flex-direction: row;
margin: 0 auto;
}
nav div.menu-items div.menu-item {
margin-left: 0.25rem;
margin-right: 0.25rem;
}
Fiddle:
NEW: https://jsfiddle.net/vzgn0Lju/1/
OLD: https://jsfiddle.net/kp9nsmah/1/
I added some margins between menu options and you can tweak a little bit more but flex is way easier than using lists and lots of things. You could use spans instead of div.menu items, can remove the container for items and such. But the general idea is there.

Align image to left and navbar to right

I need to have image on left side and navbar on right side... but the navbar must be vertically centered with image.. On jsfiddle I made it up to set navbar vertically to center but I am not able to put it on the right side... I will be glad for any help.
JSFiddle: https://jsfiddle.net/polluxik/0Lqubpe6/20/
ul {
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-items: center;
}
ul img {
height: 100px;
}
li a {
display: block;
color: #262353;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
<ul>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/640px-Google_Images_2015_logo.svg.png">
<li><a class="active" href="#">test</a></li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
*in jsfiddle I used random image from google as a placeholder
One approach is below, with corrected HTML (the only valid child of a <ul> or <ol> is an <li>, so the <img> is now appropriately wrapped):
ul {
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-items: center;
/* aligning the content of the <ul> to the end
of the inline axis: */
justify-content: end;
}
ul img {
height: 100px;
}
li a {
display: block;
color: #262353;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li:first-child {
/* setting the margin of the inline-end of the
first-child <li> element to 'auto', in order
to push the first-child away from the rest of
the content: */
margin-inline-end: auto;
}
<ul>
<!-- wrapped the <img> in another <li> element for validity: -->
<li><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/640px-Google_Images_2015_logo.svg.png"></li>
<li><a class="active" href="#">test</a></li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
JS Fiddle demo.
References:
justify-content.
margin-inline-end.
We can define the image and navbar items in different div and then using flexbox we can align the two div horizontally using justify-content:space-between.
ul {
display: flex;
justify-content: space-between;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-items: center;
}
.nav {
display: flex;
gap: 10px;
}
ul img {
height: 50px;
}
<ul>
<div class='logo'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/640px-Google_Images_2015_logo.svg.png">
</div>
<div class='nav'>
<li><a class="active" href="#">test</a></li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</div>
</ul>

List hovering messing with the whole nav div

im very very new to coding, like days in and theres this problem thats been driving me crazy.
Whenever i hover links or anything for some reason the whole parent of that list or other elements of the list kinda like twitch and change positions. Either way what can i do to make it so when i hover one element doesnt effect other elements.
<nav id="firstnav">
<ul class="firstList">
<li Purple Buzz</li>
<li Home</li>
<li About</li>
<li Work</li>
<li Pricing</li>
<li Contact</li>
</ul>
</nav>
#firstnav{
width: 100%;
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.firstList{
list-style: none;
display: inline-flex;
}
.firstList{
margin-left: 35%;
}
li{
margin-right: 30px;
margin-left: 30px;
}
li:hover{
border: solid 1px purple;
border-radius: 80px;
padding: 10px;
}
First: you forgot the closing rafter > of the li.
The problem is the padding and the border added on hover.
The padding and hover change the initial size of your html element which causes the other elements to shift and the parent to grow in your case. To fix this, you can already set the padding initially. the border you set with a transparent color. then on hover, you simply change the color of the border.
like here below.
#firstnav{
width: 100%;
box-shadow: 0 .5rem 1rem rgba(0,0,0,.15);
}
.firstList{
list-style: none;
display: inline-flex;
}
.firstList{
margin-left: 35%;
}
li{
margin-right: 30px;
margin-left: 30px;
padding: 10px;
border: solid 1px transparent;
}
li:hover{
border-color: purple;
border-radius: 80px;
}
<nav id="firstnav">
<ul class="firstList">
<li> Purple Buzz</li>
<li> Home</li>
<li> About</li>
<li> Work</li>
<li> Pricing</li>
<li> Contact</li>
</ul>
</nav>

css html ul menu with separator aligned with the container

for now i have generated the menu in this way:
nav{
width:1024px;
margin: 0 auto;
}
ul{
display: flex;
justify-content: space-between;
}
li {
border-right: 1.1px solid #333333;
margin: 0 auto;
padding: 0 1em;
text-align: center;
flex-grow: 1;
flex-basis: initial;
text-align: center;
}
the html is:
<nav id="menu">
<ul>
<li>Home</li>
<li>Training & Support</li>
<li>Templates & Forms</li>
<li>Policy Documents</li>
<li>Payment Administration</li>
<li>Tax Compliance</li>
<li>News</li>
</ul>
</nav>
The result is:
But i want that the first and last child are aligned at the start and at the end of the ul container like in the image below
How can i do this?
Have you tried removing text-align: centre; ???Or in li try something like padding-right: 0;Tell me how it works out.

Grid with irregular item sizes and pinned elements

I have to make a tag cloud. It should be looking like it shown in the picture below:
The red box here is the "show more" button which should be always sticked to the top right corner. Amount of tags (the tags are blue boxes here) is unknown, so as amount of rows.
I tried to do it with grid, but it seems it's impossible to make a non-rectangular cell. I tried to make the wrapper for blue boxes by the shape attribute, but it seems it's not an option as well.
Don't use grid for that because you don't really want a grid. Instead try flex with row-reverse - it will work if you don't care about the order of the tags (because they will be sorted in reversed horizontal order).
ul {
list-style:none;
}
li {
display: inline-block;
padding: 3px 10px;
}
.show-more,
.tag {
flex-basis: auto;
flex-grow: 1;
margin: 0 10px 10px;
text-align: center;
}
.show-more {
background-color: tomato;
color: white;
}
.tag {
background-color: beige;
color: black;
}
.tag:nth-child(2) { width: 100px; }
.tag:nth-child(4) { width: 120px; }
.tag:nth-child(6) { width: 75px; }
.container {
max-width: 400px;
}
.tag-list {
display: flex;
flex-flow: row-reverse wrap;
justify-content: space-between;
}
<div class="container">
<ul class="tag-list">
<li class="show-more">Show more</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
<li class="tag">...</li>
</ul>
</div>