Problems with css styles - css

I'm working on styling my menu, but I can't get the format I expect, I don't really know what I'm doing wrong, I'm new to this
.customHorizontalList {
list-style: none;
display: flex;
flex-direction: row;
}
.customHorizontalList>li {
margin-right: 1rem;
}
.divmenu{
padding-left: 0 !important;
padding-right: 0 !important;
width: 100% !important;
background-color: white;
font:400 20px/20px sans-serif;
}
.ButtonsMenu{
color: white;
background-color: #001e50;
border:none;
font-family: 'VWHead-Bold';
font-size: 13px;
}
.textTitleSubMenu {
padding-left: 12px;
color: #000000;
font-size: 17px;
font-family: "VWText-Regular";
}
.textSubMenu{
padding-left: 12px;
color: #001e50;
font-size: 15px;
font-family: "VWText-Regular";
}
<div class="scroll-wrapper scrollbar-outer" style="position: relative;">
<div id="menu-mobile-cats" class="scrollbar-outer scroll-content scroll-scrolly_visible">
<div class="panel-group" id="accordion-mbl-menu">
<!-- ===Menu Desktop=== -->
<div id="app" class="large">
<b-button v-b-toggle.collapse-1 class="ButtonsMenu">Accesorios</b-button>
<b-collapse id="collapse-1" class="mt-2">
<ul class="customHorizontalList">
<li>ITEM 1</li>
<li>ITEM 2</li>
<li>ITEM 3</li>
</ul>
</b-collapse>
</div>
Searching the web I tried to fix the problem but so far nothing has worked
I look for this:
I have until now this:
Dropdown menu (white) must be exactly below Div (blue)
The drop-down menu that covers the entire width of the screen
The upper buttons have to be fixed, when I press one the whole main menu moves
the selected menu must be underlined
any help or recommendation?

This can be created using CSS Grid. I will give an example code snippet below.
This styling isn't designed for you to just copy/paste into your project, but rather show you how powerful CSS grid is (It's easy to make completely mobile-responsive as well!)
If you are interested, here is a Youtube video you can watch that I personally found helpful. When getting to learn CSS Grid.
header {
display: grid;
grid-template-columns: repeat(10, 1fr);
background: #001E50;
padding: 20px;
border: 4px solid #C85171;
margin-bottom: 2em;
align-content: center;
}
header > * {
color: white;
}
#b1 {
grid-column: -3/-2;
}
main {
display: grid;
grid-template-columns: repeat(4, 2fr) repeat(2, 1fr);
}
main > * {
width: 100px;
height: 100px;
background: red;
}
<header>
<div id="n1">Lorem Ipsum</div>
<div id="n2">Lorem Ipsum</div>
<div id="n3">Lorem Ipsum</div>
<div id="n4">Lorem Ipsum</div>
<button id="b1"></button>
<button id="b2"></button>
</header>
<main>
<div id="m1"></div>
<div id="m2"></div>
<div id="m3"></div>
<div id="m4"></div>
</main>

Related

How to position elements using css grid

I am new to css grid and I just understood how exactly positioning the grid elements works. What I don't understand is how to put an item that's resizing inside this grid element.
I will explain it this way:
This is my site's layout
and this is my code:
<div class="container">
<div class="header">Header</div>
<div class="content1">Content1</div>
<div class="content2">Content2</div>
<div class="footer">footer</div>
</div>
.container {
width: 100vw;
height: 100vh;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: 80px 1fr 1fr 120px;
gap: 10px;
padding: 10px;
box-sizing: border-box;
}
.container div {
padding: 10px;
border: 1px solid #000000;
}
.header {
grid-column: 1 / 5;
}
.content1 {
row-gap: 200px;
grid-column: 1 / 5;
grid-row: 2 / 3;
}
So now what I would love to do is in that header box an actual navigation menu but I want somehow to be only inside this box and resize automatically when I change the size of that box. Right now this is what I have done:
2nd picture
code:
<div class="header">
<nav>
<ul>
<li> <a text-white asp-area="" asp-page="/main">Home</a></li>
<li><a text-white asp-area="" asp-page="/pc">Games</a>
<ul>
<li><a text-white asp-area="" asp-page="/pc">PC</a></li>
<li><a text-white asp-area="" asp-page="/xbox">XBOX</a></li>
<li><a text-white asp-area="" asp-page="/ps">PS</a></li>
</ul>
</li>
<li><a text-white asp-area="" asp-page="/devices">Devices</a></li>
<li><a text-white asp-area="" asp-page="/pcparts">PC Parts</a></li>
</ul>
</nav>
</div>
.header {
grid-column: 1 / 5;
}
nav p {
float: left;
color: white;
font-size: 20px;
line-height: 40px;
}
nav ul {
float: left;
background-color: #222;
z-index: 998;
}
nav ul li {
float: left;
list-style: none;
padding: 0px 15.50px;
}
nav ul li a {
display: block;
font-family: arial;
background-color: #222;
color: #fff;
font-size: 16px;
padding: 26px 14px;
text-decoration: none;
}
nav ul li ul {
display: none;
position: absolute;
background-color: #222;
outline-color: #f92525;
padding: 0px 2px;
padding-left: 0vh;
left: 2px;
width: 35px;
border-radius: repeat (5, 4px);
}
and this is so wrong that I don't really have an idea how it should be. I am sorry if this question exists but I tried to find a solution and I could not resolve the problem with anything I got from the Internet, nor understood how it should be.
Some general tips:
Don't define your site layout using both grid template rows and grid template columns.
Instead: If you have Sidebar, use grid-template-columns, if you have stacked content (like you), just use display:grid; This will force the content to stack ontop of each other.
Don't define static heights for your header and footer
Instead: Work with the spacing of the elements inside (margin and padding) to make your container responsive.
Get familiar with Flexbox and Grid a bit more to easily get started modelling your site, for example spacing out your menu items and much more.
Resources:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
https://css-tricks.com/snippets/css/complete-guide-grid/
Here is an example of those tricks:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 1rem;
}
.main {
display: grid;
}
.nav, .content {
display: flex;
justify-content: center;
align-items: center;
border: 2px solid black;
}
.nav {
padding: 2rem;
}
.content {
padding: 5rem;
}
<div id="main">
<header class="nav">Header</header>
<div class="content">Content 1</div>
<div class="content">Content 1</div>
<footer class="nav">Footer</footer>
</div>

h3 s with spaces between and same line

Hi i have three h3 (masthead-brand 0-2)
now i saw on the internet that display inline block makes them on the same line, but my idea was having them in the same line AND having spaces between that: masthead is on the left corner of the website, masthead1 is in the center, and masthead2 is in the right corner of the website.
How could i do it?
.masthead-brand {
text-align: left;
font-size: 50px;
margin-right: 30px;
margin-top: 10px;
margin-bottom: 10px;
color: #3434f3;
}
.masthead-brand1 {
text-align: center;
font-size: 50px;
margin-right: 30px;
margin-top: 10px;
margin-bottom: 0px;
}
.masthead-brand2 {
text-align: right;
font-size: 50px;
margin-top: 10px;
margin-bottom: 10px;
color: crimson;
}
h3 {
display: inline-block;
}
<div class="background">
<div>
<h3 class="masthead-brand">Held </h3>
<h3 class="masthead-brand1"> oder</h3>
<h3 class="masthead-brand2"> Schurke?</h3>
</div>
<nav>
<ul class="nav masthead-nav">
<li class="active"><a [routerLink]="['/dashboard']">Dashboard</a></li>
<li><a routerLink="/heroes">Heroes</a></li>
<li><a routerLink="/villains">Schurken</a></li>
</ul>
</nav>
<p class="lead">
Kämpfe jetzt!
</p>
<router-outlet></router-outlet>
</div>
Just add any class to h3' wrapper div:
<div class="wrapper">
<h3 class="masthead-brand">Held</h3>
<h3 class="masthead-brand1">oder</h3>
<h3 class="masthead-brand2">Schurke?</h3>
</div>
and make it flex:
.wrapper {
display: flex;
justify-content: space-between;
}
It's semantically wrong to use 3 seperate headlines.
You should rather use one headline and format its contents.
Here I did it with the help of span elements.
The positioning is done with the help of flex. Flex offers the property to justify its contents just as you need it:
.masthead-brand {
color: #3434f3;
}
.masthead-brand1 {
}
.masthead-brand2 {
color: crimson;
}
h3 {
display: flex;
justify-content: space-between;
}
h3 span {
display: block;
}
<h3>
<span class="masthead-brand">Held</span>
<span class="masthead-brand1">oder</span>
<span class="masthead-brand2">Schurke?</span>
</h3>

CSS: Bootstrap media: wrapping + ellipsis

I am designing a messenger-like layout with Bootstrap 4.0.0-alpha.6.
Right now I am having trouble with media object. It should break-word and show ellipsis, but that's not what happens.
Just .most-recent-message should show ellipsis.
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Live: https://jsfiddle.net/f55huf3j/
Ps: I found a similar issue, but the given workaround didn't work for me.
You can add the overflow property to the parent, in this case .media-body
fiddle
body {
background: #f4f4f4;
padding: 1rem;
}
.conversation {
display: block;
padding: 0.75rem 1rem;
}
.avatar {
width: 50px;
height: 50px;
border-radius: 4px;
}
.media-body {
overflow: hidden;
}
h6 {
margin-bottom: 0.15em;
}
.most-recent-message {
color: rgba(#000, 0.5);
font-size: 0.85em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<!-- Sidebar - begin -->
<div class="col-12 col-md-3">
<div class="card">
<!-- Recent conversation - begin -->
<a href="#" class="conversation">
<div class="media">
<img class="d-flex align-self-center mr-1 avatar" src="http://i.imgur.com/CEtZcrC.jpg">
<div class="media-body">
<h6>
Sarah Martins Smit dfd df df dfh
</h6>
<div class="most-recent-message">
We can track errors for this kind of bug
</div>
</div>
</div>
</a>
<!-- Recent conversation - end -->
</div>
</div>
<!-- Sidebar - end -->
<!-- Chat - begin -->
<div class="col-12 col-md-9">
<div class="card">
Content
</div>
</div>
<!-- Chat - end -->
</div>
You need to move the overflow rules to the parent div which is .media-body and the .most-recent-message div needs to be displayed as inline. Also you have some CSS errors like an extra close bracket. Here's what your css should be:
body {
background: #f4f4f4;
padding: 1rem;
}
.media-body{
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}
.conversation {
display: block;
padding: 0.75rem 1rem;
&:hover {
background: rgba(#000,0.05);
text-decoration: none;
}
}
.avatar {
width: 50px;
height: 50px;
border-radius: 4px;
}
.media {
}
h6 {
margin-bottom: 0.15em;
}
.most-recent-message {
color: rgba(#000,0.5);
font-size: 0.85em;
display:inline;
}
I think you need to define the width of the parent container.
https://jsfiddle.net/7x93ofzm/2/
.media-body {
width: calc(100% - 54px);
}
Should only need:
.media-body {
display: inline-grid;
}
Fiddle

display: webkit-flex Pushes inline-block div to next line in Safari

I´m trying to learn HTML/CSS and find that when I add
display: -webkit-flex; to the CSS, the last div in the nav is pushed to the next line. When I disable flex box by simply deleting the line the div jumps back up to the (inline-block) nav. I'm currently testing in safari
The page looks as it should in Firefox, though not in Safari, any suggestions as to why?
Here's the code:
<body>
<header>
<div class="logo">
<h1>Guitar site</h1>
</div>
<nav>
<div class="leftMenu">
Home
</div>
<div class="centerMenu">
<div>
Beginner
</div>
<div>
Advanced
</div>
<div>
Tips
</div>
</div>
<div class="rightMenu">
Contact
</div>
</nav>
</header>
<h1> test</h1>
</body>
This is the all the CSS I've written, there is also a CSS reset section that I haven't included.
.leftMenu,
.rightMenu,
.centerMenu {
text-align: center;
display: inline-block;
border-bottom: solid .1em;
display: -webkit-flex;
}
.leftMenu,
.rightMenu {
background-color: #454ed6;
height: 2em;
padding-top: 1em;
width: 17.5%;
-webkit-justify-content: space-around;
}
.leftMenu {
float: left;
}
.rightMenu {
float: right;
}
.centerMenu a {
display: block;
height: 2em;
}
.centerMenu {
width: 65%;
height: 6em;
background-color: #86acbe;
-webkit-flex-direction: column;
-webkit-justify-content: space-around;
}
The main idea behind the flex layout is to give the container the ability to alter its items' width/height (and order) to best fill the available space.
So the main container in your case is nav element; and you have to define display:flex property for nav element. And your navigation HTML structure is not in proper format.
Check the Demo and here is your modified CSS Code.
nav{display: -webkit-flex;
display: -webkit-box; /*for older safari version*/
display: flex;}
.leftMenu,
.rightMenu,
.centerMenu {
text-align: center;
border-bottom: solid .1em;
justify-content: space-around;
/*display: inline-block;
display: -webkit-flex;*/
}
.leftMenu,
.rightMenu {
background-color: #fbfbfb;
height: 2em;
padding-top: 1em;
width: 17.5%;
/*-webkit-justify-content: space-around;*/
}
/*.leftMenu {
float: left;
}
.rightMenu {
float: right;
}*/
.centerMenu a {
display: block;
height: 2em;
}
.centerMenu {
width: 65%;
height: 6em;
background-color: #86acbe;
/* -webkit-flex-direction: column;
-webkit-justify-content: space-around;*/
}
<header>
<div class="logo">
<h1>Guitar site</h1>
</div>
<nav>
<div class="rightMenu">
Home
</div>
<div class="rightMenu">
Beginner
</div>
<div class="rightMenu">
Advanced
</div>
<div class="rightMenu">
Tips
</div>
<div class="rightMenu">
Contact
</div>
</nav>
</header>
<h1> test</h1>

Is this a valid html5 markup approach?

I am designing a video site and just wanna ask some suggestions, ideas and improvements of my current html5 base layout.
I read a lot of articles from google but it's confusing. I need some straightforward suggestions.
I am new to css so please be gentle :)
Fiddle here
body {
background: #2b2b2b;
font: normal 12px Arial, Helvetica, sans-serif;
color: #777;
overflow-x: hidden
}
a {
color: #888;
}
a:active {
color: #444;
}
header .wrap,
nav,
.contentwrapper,
footer .wrap {
width: 1000px;
margin: 0 auto
}
header,
nav,
section,
aside .wrap,
footer {
background: #333;
margin-bottom: 10px;
padding: 10px;
border: 1px solid #222
}
section {
border: 1px solid #222
}
header {
width: 100%;
line-height: 30px
}
nav li {
display: inline-block;
}
main {
float: right;
width: 820px;
}
aside {
float: left;
width: 170px
}
footer {
line-height: 30px;
}
footer ul {
font-size: 14px;
}
footer li {
float: right;
display: inline-block;
}
footer li.cr {
float: left
}
.group:before,
.group:after {
content: "";
display: table;
}
.group:after {
clear: both;
}
.group {
*zoom: 1;
}
<header>
<div class="wrap">
<h1>Site title</h1>
</div>
</header>
<nav>
<ul class="menu">
<li>menu1
</li>
<li>menu2
</li>
</ul>
</nav>
<div class="contentwrapper group">
<main>
<section>
<div class="head">
<h1>Featured Videos</h1>
</div>
</section>
<section>
<h1>Latest Videos</h1>
</section>
</main>
<aside>
<div class="wrap">
category list here
</div>
<div class="wrap">
ads here
</div>
</aside>
</div>
<footer>
<div class="wrap group">
<ul>
<li class="cr">website.com © 2014</li>
<li>Contact
</li>
<li>Rss
</li>
<li>Sitemap
</li>
<li>Webmaster$
</li>
</ul>
</div>
</footer>
All of your syntax is valid, and your CSS looks fine. Just be sure to keep you code clean and simple throughout your project, so that you don't have 50 stylesheets for who-knows-what (speaking from experience XD).
Best of luck to your project.
No.
From the HTML5 spec :: DIV
Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.
You should not use DIV elements where there are not necessary, especially <div class="wrap"> inside HEADER, <div class="contentwrapper group"> as parent of MAIN, and <div class="wrap group"> inside bottom FOOTER from your code, are redundant.

Resources