Different Li Sizes - html

Could you please assist with how to make one of my Lis Could you please assist with how to make one of my LisCould you please assist with how to make one of my LisCould you please assist with how to make one of my Lis
<div id="pageTop">
<nav>
<ul>
<li><img src="images/headerConSize.png" alt="" /><br>Home
<li><img src="images/headerConSize.png" alt="" /><br>Home
</ul>
</nav>
</div>
body {
margin: 0px;
background-repeat: no-repeat;
}
#pageTop {
height: 172px;
}
nav {
margin: 0px auto;
overflow: scroll;
width: auto;
height: 95px;
}
nav ul {
margin: 0px auto;
overflow: scroll;
}
nav ul li {
display: inline-block;
height: 70px;
text-align: center;
float:left;
overflow: hidden;
}

Hmmm, I think you could make use of the nth-child CSS selector here.
I assume you want the fourth <li> to take up the width of three normal <li> elements (as defined in your existing CSS), so the width we want will be: 10.66666667% * 3 = 32%.
Delete the extra 2 <li> elements in your HTML, and use nth-child(4), like so:
nav ul > li:nth-child(4){
width: 32%;
}
Now, the fourth <li> element will be three times the width of the other ones. Here's a JSFiddle to show you what this achieves. (I set a temporary background colour so you can see the fourth one.) If you have any questions, let me know!

Related

html css full width, images only, resizable horizontal menu

I' trying to make a horizontal menu with special conditions
these are the rules I have to stick with:
html + css
menu should resize to the width of the container (100% of container).
so the wider the container the bigger (height, width) the menu
menu elements are images with different width
every image(menu element) is close to the next and previous (no gaps in between)
all dimensions should be expressed in % (no fixed size)
the code:
<div id="menu-container">
<ul>
<li><img src="myImg01"></li>
<li><img src="myImg02"></li>
<li><img src="myImg03"></li>
</ul>
</div>
css
#menu-container{
width:100%;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: table;
}
li {
display: table-cell;
}
li img{
width:100%;
}
this works in firefox and safari
does not in chrome and similar... (it seems like all images are scaled in different %)
I've searched and did not found a similar issue
could you help please?
Will try to clarify.
I need that all images retain their aspect ratio even after scaling
you should add max-width in your div , and make display flex wrap
hay I hope this example will be helpful, so try like this:
CSS
#menu-container{
width:100%;
border: 1px solid red;
}
ul {
margin: 0;
padding: 0;
display: flex;
align-items: center;
flex-wrap: nowrap;
list-style-type: none;
}
li {
width: 10%;
height: 0;
padding-bottom: 10%;
background-repeat: no-repeat;
/*background-size: contain;*/
background-size: cover;
background-position: center center;
}
li a {
display: block;
width: 100%;
height: 0;
padding-bottom: 100%;
}
HTML
<div id="menu-container">
<ul>
<li style="background-image: url(https://static.scientificamerican.com/sciam/cache/file/4E0744CD-793A-4EF8-B550B54F7F2C4406_source.jpg);">
</li>
<li style="background-image: url(https://www.afd.fr/sites/afd/files/styles/visuel_principal/public/2019-01-07-16-19/mangrove%20couv.jpg);">
</li>
<li style="background-image: url(https://blog.nationalgeographic.org/wp-content/uploads/2020/05/May-11_Dorset-heathland_shutterstock_1332881306_sml-1140x450.jpg);">
</li>
</ul>
</div>
You can CSS grid.
#menu-container {
width:100%;
}
ul.menu {
display: grid;
grid-template-columns: 1fr 25% 2fr; // You can use percentages or the fr unit It represents a fraction of the available space in the grid container (works like Flexbox’s unitless values).
list-style-type: none;
margin: 0;
padding: 0;
}

Style a vertical li navigation menu with each li having an image and text

I'm working on a project and I've got a problem where I can't think of how to style my vertical navigation properly. I want it to be covering the whole height and look the following way (vertical from up to down): DIV element for logo with the same height as the list items and no margin, navigation list items with image in the middle and text beneath them, with a little margin on top and bottom.
Here's my current code -
HTML:
<div className="Dashboard">
<nav className="SideBox">
<img className="SideLogo" src={Logo}></img>
<ul>
<li><img src={Logo}/><p>Accounts</p></li>
<li><img src={Logo}/><p>Transactions</p></li>
<li><img src={Logo}/><p>Documents</p></li>
<li><img src={Logo}/><p>Wallet</p></li>
<li><img src={Logo}/><p>Calendar</p></li>
<li><img src={Logo}/><p>Settings</p></li>
</ul>
</nav>
</div>
CSS:
.Dashboard {
width: 100%;
height: 100%;
}
.Dashboard * {
width: 150px;
height: calc(100vh / 7);
background-color: blue;
}
.SideLogo {
margin: 0 0;
padding: 0 0;
display: block;
}
.Dashboard ul {
text-align: center;
list-style: none;
margin: 0 0;
padding: 0 0;
}
.Dashboard li {
text-align: center;
margin: 10px 0;
}
.Dashboard img {
display: block;
height: 90%;
}
I hope this will help you a lot
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_mobile_navbar
If you just want a vertical menu... The only you have to add is an <img> tag with appropriate image
BTW, you shouldn't repeat your code which has the same values such as margin and padding in different classes

Cannot fit image to navigation bar

I'm trying to add an image to my navigation bar, and fit the image to the navigation bar, however I could not manage to resize the image for this purpose; no matter what I did the image just extends to the whole page. I am quite new to HTML & CSS, could you please explain how to fit the image to the navigation bar?
#profile-image {
height: auto;
width: auto;
float: left;
padding-left: 2%;
margin: 0 auto;
padding: 10px 0;
}
<div class="top-padding">
<nav>
<div id="profile-image"><img src="profile-image.jpg"></div>
<ul class="menu">
<li>About Me!</li>
<li>My Blog Posts!</li>
<li>My Projects!</li>
</ul>
</nav>
</div>
try with this
#profile-image{
height:auto;
width:auto;
float: left;
padding-left: 2%;
margin: 0 auto;
padding: 10px 0;
}
#profile-image img{
object-fit:cover;
}
nav{
overflow:hidden;
}
I just added the rule for nav and the cover for th eimage
How large do you want this image to be on the navbar? Let's say you want it to be 100px by 100px.
First you need to set the height and width of the parent element of the image. I just gave the div with id profile-image a height: 100px and width: 100px.
Next you need to tell the <img /> tag to conform to these dimensions. We can do that by giving it a style of height: 100% and width: 100%.
#profile-image {
height: 100px;
width: 100px;
float: left;
padding-left: 2%;
margin: 0 auto;
padding: 10px 0;
}
#profile-image img {
height: 100%;
width: 100%;
}
<div class="top-padding">
<nav>
<div id="profile-image"><img src="profile-image.jpg"></div>
<ul class="menu">
<li>About Me!</li>
<li>My Blog Posts!</li>
<li>My Projects!</li>
</ul>
</nav>
</div>
I'm not sure what you're trying to achieve so this is something of a guess:
nav {
display: flex;
align-items: center;
background: #eeeeee;
}
#profile-image {
flex-basis: 20%;
font-size: 0;
}
#profile-image img {
width: 100%;
}
ul.menu {
display: flex;
margin: 0;
justify-content: space-around;
flex-grow: 1;
list-style-type:none;
padding:0;
}
ul.menu li {
padding:10px;
}
<nav>
<div id="profile-image"><img src="http://placekitten.com/150/150" /></div>
<ul class="menu">
<li>About Me!</li>
<li>My Blog Posts!</li>
<li>My Projects!</li>
</ul>
</nav>
If you want to "fit the image to the navbar" then you need to give the nav bar a size for the image to fit into.
You can probably get rid of the profile-image div if you wish, unless you want to add special styles to the image area.
I am assuming that you want the image to be like an icon on the left (because you added the float: left style), as opposed to an image that covers the entire nav bar like a background image would.
If that's the case:
nav {
height: 150px; or whatever you want the image and the nav bar to be
}
#profile-image {
height: 100% or you can use the same height as the nav style
width: auto; That will keep the image proportions correct
float: left;
padding-left: 2%;
margin: 0 auto; <== not sure what you are doing here. Try deleting it as it won't help.
padding: 10px 0;
}

<ul> Background colour won't work. I'm trying to add a background for my page breadcrumbs

I'm trying to add my website breadcrumbs to a list and change the list background to #0765de, i have tried as seen below, only the <li> background will change colour.
I have to change the width of li so the text is in the page so the background cuts off. that's why I need it in ul.
Heres the HTML:
<ul class="breadcrumb_unli">
<li class="breadcrumb_unli">{ include'breadcrumb' }</li>
</ul>
Heres the CSS:
.breadcrumb_unli ul {
width: 100%;
overflow: hidden;
background-color: #0765de;
}
.breadcrumb_unli li {
width: 60%;
color: white;
margin: auto;
margin-top: -30px;
padding: 10px 10px 10px 0px;
}
Any help would be appreciated.
to select a ul with a specific class you should do this:
ul.breadcrumb_unli {
width: 100%;
overflow: hidden;
background-color: #0765de;
}
if it didn't work, try adding display: block or display: inline-block to the ul

Styling List Buttons

Using a list, I want to create a list of links as in the image
<div id="toolbarbottom" class="toolbar" style="position: fixed; clear: both; overflow: visible; bottom: 0px; left: 0px; width: 100%;">
<ul>
<li id="active"><span><a id="current" href="#add" class="button">News</a></span></li>
<li><span> Updates</span> </li>
<li><span>Contact Us</span></li>
<li><span>Website </span></li>
<li><span>Refresh</span> </li>
</ul>
</div>
I am kind of stuck on the CSS (button) and probably the spacing between the list elements. to make the list appear in this form. Anyone with an idea of how I can tackle this please?
or another way is to use floats, and make the ul display: inline-block to contain the floated li's
you need to slightly change the HTML so the span is inside the a - this is so you can hide the spanned text, but keep the image background and clickable area for the a elements, also I'd give each link a unique reference (class or ID) so the backgrounds can be applied separately.
example HTML:
<div id="toolbarbottom" class="toolbar" style="position: fixed; top: 0px; left: 0px; width: 100%;">
<ul>
<li class="active"><span>News</span></li>
<li><span> Updates</span></li>
<li><span>Contact Us</span></li>
<li><span>Website </span></li>
<li><span>Refresh</span> </li>
</ul>
</div>
you can then put the whole background on the ul and put the individual images on each link.
#toolbarbottom ul {
list-style: none;
margin: 0;
padding: 0;
display: inline-block;
width: 100%;
background: #ff0;
}
#toolbarbottom li {
float: left;
width: 80px;
height: 80px;
border: 1px solid #000; /* not required, just to show where individual links are */
}
#toolbarbottom li a { /* make link fill the li element */
display: block;
height: 80px;
}
#toolbarbottom li span { /* hide the text */
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
clip: rect (1px 1px 1px 1px);
}
/* couple examples of where to put individual backgrounds */
#toolbarbottom #mupdates {background: #dad;}
#toolbarbottom #mcontact {background: #0f0;}
fiddle: http://jsfiddle.net/YaS9J/
css
#toolbarbottom li {
display:inline-block;
padding:0 10px;
}
/* if you have one */
#toolbarbottom li img {
display:block;
}
You should first set up your css as an external style sheet rather than hard code it into your html. (See http://www.w3.org/TR/html4/present/styles.html for more on this). To add spacing between the li elements you can use the css cascade to add some bottom padding as follows:
#toolbarbottom ul li {
padding-bottom:4px;
}
To make the list appear inline you would use:
#toolbarbottom ul{
list-style: none;
display: inline;
padding-left: 0;
margin-left: 0;
}
Those button look like images, so to achieve that you'd just include them within each li element:
<li><img src="/path/to/image.jpg"></li>