Align boxes with flexbox and center them 2 by 2 - html

I almost finish my website but I have one more issue,
At 745px the filter boxe is looking wrong.
I would like to have it like this
#media screen and (max-width: 768px) {
.bloc-filtres {
flex-direction: column;
}
.bloc-filtres ul {
display: flex;
gap: 1rem;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="bloc-filtres">
<p id="titre-filtre">Filtres</p>
<ul>
<li class="filtres">
<i class="fa-solid fa-money-bill-wave"></i>
<input type="checkbox" id="eco" name="filtre-possible" value="eco" />
<label for="eco">Économique</label>
</li>
<li class="filtres">
<i class="fa-solid fa-person"></i>
<input type="checkbox" id="famille" name="filtre-possible" value="famille" />
<label for="famille">Familial</label>
</li>
<li class="filtres">
<i class="fa-solid fa-heart"></i>
<input type="checkbox" id="romantique" name="filtre-possible" value="romantique" />
<label for="romantique">Romantique</label>
</li>
<li class="filtres">
<i class="fa-solid fa-dog"></i>
<input type="checkbox" id="animaux" name="filtre-possible" value="animaux" />
<label for="animaux">Animaux autorisés</label>
</li>
</ul>
</div>

Just add a few lines to your CSS rule:
#media screen and (max-width: 768px)
.bloc-filtres ul {
display: flex;
gap: 1rem;
max-width: 70%;
margin: 0 auto;
}

Flexbox is great! But in this case i would prefer gridsystem. Why? Because you have already a fix structure and dont need the advantages from flexsystem (flex!). Below you can see a grid example.
.listing {
max-width: 768px;
width:100%;
margin: 0 auto;
overflow:hidden;
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
}
.listing div {
background-color: yellow;
}
<div class="listing">
<div>Box A</div>
<div>Box B</div>
<div>Box C</div>
<div>Box D</div>
</div>

Related

Why is my outline top not showing in CSS?

Im styling multiple boxes, it's only the first box whose top outline is not working. Here's my code. I'm using bootstrap in React. Border works. I have attached the relevent css.
EDIT: I hacked it by setting my outline-offset to negative the amount of pixels. so -3. Worked fine for me, and am wondering how it happened and how to avoid it.
.savedMeme--card {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: 100%;
padding: 10px;
}
.savedMeme--card:hover {
background-color: #e3e3e3c4;
outline: 3px solid var(--blue);
}
<div className="offcanvas offcanvas-end" tabIndex="-1" id="sidebar" aria-labelledby="sidebar--header">
<div className="offcanvas-header">
<h2 className="offcanvas-title" id="sidebar--header">Your saved memes</h2>
<button className="btn-close" data-bs-dismiss="offcanvas" type="button" aria-label="Close"></button>
</div>
<div className="offcanvas-body p-0">
<div className="savedMeme--card">
<!-- this is an imported component -->
<div className="savedMeme--header">
<span className="bi bi-bookmark-x-fill"></span>
<img src={props.url} style={{ width: "80px", height: "80px" }} alt="meme" />
</div>
<div className="savedMeme-body">
<p>
{props.topText}...
</p>
<p className="savedMeme--view-meme">view meme</p>
</div>
</div>
</div>
</div>
</div>
</div>
I have fixed your closing div tag issue and changed className to class and just defined css variable
:root {
--blue: blue;
}
Everything seems to works fine on hover.
:root {
--blue: blue;
}
.savedMeme--card {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: 100%;
padding: 10px;
}
.savedMeme--card:hover {
background-color: #e3e3e3c4;
outline: 3px solid var(--blue);
}
<div class="offcanvas offcanvas-end" tabIndex="-1" id="sidebar" aria-labelledby="sidebar--header">
<div class="offcanvas-header">
<h2 class="offcanvas-title" id="sidebar--header">Your saved memes</h2>
<button class="btn-close" data-bs-dismiss="offcanvas" type="button" aria-label="Close"></button>
</div>
<div class="offcanvas-body p-0">
<div class="savedMeme--card">
<!-- this is an imported component -->
<div class="savedMeme--header">
<span class="bi bi-bookmark-x-fill"></span>
<img src={props.url} style={{ width: "80px" , height: "80px" }} alt="meme" />
</div>
<div class="savedMeme-body">
<p>
{props.topText}...
</p>
<p class="savedMeme--view-meme">view meme</p>
</div>
</div>
</div>
</div>

How can i create this type of html layout

I want to create something like this in a layout where the icon line themselves up with html, how can i get this done?
Layout i would like to create
I Tried the following without flexbox, but when the width gets to narrow it messes up. guess i should try the flexbox instead., hope that will work.
good version
messed up version
.pageColumnMid{
margin-right:20px;
float : left;
clear : none;
height : auto;
width : auto;
}
.pageColumnLeft{
text-align:left;
float : left;
clear : none;
height : auto;
width : auto;
}
.pageColumnRight{
margin-left:20px;
float : left;
clear : none;
height : auto;
width : auto;
}
.lineheight50{
line-height: 40px!important;
}
<body>
<div><div>
<div class="pageColumnMid"><span class="fas fa-user lineheight50" ></span> <br> <span class="fas fa-user lineheight50" ></span> <br> <span class="fas fa-user lineheight50" ></span> <br>
</div>
<div class="pageColumnLeft lineheight50" >View, manage and publish your personal data <br> View, manage and store your Contacts <br> View your technicaldata* <br>
</div>
<div class="pageColumnRight"></span><span class="fas fa-info lineheight50" ></span> <br> <span class="fas fa-info lineheight50" ></span> <br> <span class="fas fa-info lineheight50" ></span> <br>
</div>
</div>
</body>
To achieve your design this is what you can do as shown below.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.d-flex {
display: flex;
flex-wrap: wrap;
padding: 1rem;
flex-direction: column;
width: 100%;/*can edit as per requirement*/
}
.d-flex .col .child {
display: flex;
flex-wrap: wrap;
}
.d-flex .col {
display: flex;
flex-wrap: wrap;
padding: 1rem 0;
justify-content: space-between;
}
.d-flex p {
padding: 0 1rem;
}
<!--ADD THIS LINE TO GET FONTAWESOME ICONS IN HEAD TAG-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<div class="d-flex">
<div class="col">
<div class="child">
<span class="fas fa-user"></span>
<p>View, manage and publish your personal data</p>
</div>
<span class="fas fa-info"></span>
</div>
<div class="col">
<div class="child">
<span class="fas fa-user"></span>
<p>View, manage and store your Contacts</p>
</div>
<span class="fas fa-info"></span>
</div>
<div class="col">
<div class="child">
<span class="fas fa-user"></span>
<p>View your technicaldata*</p>
</div>
<span class="fas fa-info"></span>
</div>
</div>
You should learn about Flex in CSS
By using these attributes you'll get what you want...
display: flex; //Flexible Box Layout
flex-wrap: wrap; // box automatically go to next line
flex-direction: column; // boxes are arranged int column order.
To play with these attributes and other also make you more clear about flex.
Thanks

Restrict html input box to max width of a border around it

I have the following html code, with several instances of a border surrounding an input field and two labels. What I'd like to have happen is that all of these are restricted to being within the border surrounding them; what's actually happening though is that the input field are effectively ignoring the border, drawing over it when the input field extends beyond where the border line is. Is there a way to accomplish this? I know I could set the width of the input field, and that should accomplish the goal, but that's not exactly responsive or (in my opinion at least) good UI design. The first time the window is resized it would likely throw off the measurements.
I expect this is probably a rather simple fix, but when I tried to google this for a solution, every result I found was for restricting (or in some cases removing) the border of the input box itself, not an enclosing border.
I would greatly appreciate any help someone could give on this...
(BTW, bonus points to anyone that can guess what this is for, since it's so obscure :p ~sarcasm~)
section, h1 {
padding: 0 1em;
}
.grid {
display: grid;
grid-template-columns: repeat(3, 150px);
grid-template-rows: repeat(3, 150px);
grid-gap: 50px 30px;
}
.grid-item {
border: thin #566d7e solid;
padding: 10px;
}
.grid-item > label {
text-align: center;
}
.grid-item > input {
margin: 2px;
word-wrap: true;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css\abilitiesStyle.css" as="style">
</head>
</html>
<body>
<header>
</header>
<main>
<article>
<h1>Abilities, Saves, Senses</h1>
<section>
<div class="grid">
<div class="grid-item">
<label>STRENGTH</label>
<input type="number" name="strengthScore">
<label id="strengthModifier"></label>
</div>
<div class="grid-item">
<label>DEXTERITY</label>
<input type="number" name="dexterityScore">
<label id="dexterityModifier"></label>
</div>
<div class="grid-item">
<label>CONSTITUTION</label>
<input type="number" name="constitutionScore">
<label id="constitutionModifier"></label>
</div>
<div class="grid-item">
<label>INTELLIGENCE</label>
<input type="number" name="intelligenceScore">
<label id="intelligenceModifier"></label>
</div>
<div class="grid-item">
<label>WISDOM</label>
<input type="number" name="wisdomScore">
<label id="wisdomModifier"></label>
</div>
<div class="grid-item">
<label>CHARISMA</label>
<input type="number" name="charismaScore">
<label id="charismaModifier"></label>
</div>
</div>
</section>
</article>
</main>
<footer>
</footer>
</body>
You can style the input type by doing input[type=number] and set the width to 100%. I also added - margin-left to center the input field. This method is 100% responsive on all screens.
section, h1 {
padding: 0 1em;
}
.grid {
display: grid;
grid-template-columns: repeat(3, 150px);
grid-template-rows: repeat(3, 150px);
grid-gap: 50px 30px;
}
.grid-item {
border: thin #566d7e solid;
padding: 10px;
}
.grid-item > label {
text-align: center;
}
.grid-item > input {
margin: 2px;
word-wrap: true;
}
/* additions */
input[type=number] {
width: 100%;
margin-left: -.2rem;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css\abilitiesStyle.css" as="style">
</head>
</html>
<body>
<header>
</header>
<main>
<article>
<h1>Abilities, Saves, Senses</h1>
<section>
<div class="grid">
<div class="grid-item">
<label>STRENGTH</label>
<input type="number" name="strengthScore">
<label id="strengthModifier"></label>
</div>
<div class="grid-item">
<label>DEXTERITY</label>
<input type="number" name="dexterityScore">
<label id="dexterityModifier"></label>
</div>
<div class="grid-item">
<label>CONSTITUTION</label>
<input type="number" name="constitutionScore">
<label id="constitutionModifier"></label>
</div>
<div class="grid-item">
<label>INTELLIGENCE</label>
<input type="number" name="intelligenceScore">
<label id="intelligenceModifier"></label>
</div>
<div class="grid-item">
<label>WISDOM</label>
<input type="number" name="wisdomScore">
<label id="wisdomModifier"></label>
</div>
<div class="grid-item">
<label>CHARISMA</label>
<input type="number" name="charismaScore">
<label id="charismaModifier"></label>
</div>
</div>
</section>
</article>
</main>
<footer>
</footer>
</body>

Bootstrap icon wrong positioning

I'm new to CSS and HTML, so I got stuck on a very stupid step. The thing is that fa-list-ul icon is wrong positioned. Without text-align:center it positions fine. Any way to fix it? Thanks for spending your time with my problem.
Here's the JSFiddle
And here is my code :
.player{padding:.75rem 1rem;margin-bottom:1rem;line-height:36px}
.player_play{font-size:36px;vertical-align:middle}
.radio_name{vertical-align:middle}
.radio_icon{padding-right:5px;vertical-align:middle}
.radio_select{font-size:20px;vertical-align:middle}
<nav class="player">
<div class="container">
<div class="float-left">
<i class="fa fa-play-circle player_play action"></i>
</div>
<div class="radio_volume">
<i class="fa fa-volume-down"></i>
<i class="fa fa-music radio_icon accent_color"></i><span class="radio_name"> Anison</span>
</div>
<div class="float-right">
<i class="fa fa-list-ul radio_select action"></i>
</div>
</div>
</nav>
Using display: flex will make every element inside that container have the same horizontal size so this should solve your problem:
.container {
display: flex;
}
.float-left {
flex: 1;
}
.radio_volume {
text-align: center;
flex: 1;
}
.float-right {
flex: 1;
}
.float-right i {
float: right;
margin-top: 10px;
}
also here's the jsfiddle: https://jsfiddle.net/fqkvv8es/3/
You can make use of Bootstrap's classes, which results in less code than what the chosen answer uses:
JSFiddle
HTML
<nav class="player">
<div class="container">
<div class="row justify-content-between align-items-center">
<i class="fa fa-play-circle player_play action"></i>
<div class="radio_volume">
<i class="fa fa-volume-down"></i>
<i class="fa fa-music radio_icon accent_color"></i><span class="radio_name"> Station</span>
</div>
<i class="fa fa-list-ul radio_select action"></i>
</div>
</div>
</nav>
CSS
.player {
padding: .75rem 1rem;
margin-bottom: 1rem;
line-height: 36px
}
.player_play {
font-size: 36px;
}
.radio_icon {
padding-right: 5px;
}
.radio_select {
font-size: 20px;
}
JSFiddle

Complex table layout with CSS

I created table with ul lists and styled as table with CSS display:table
The problem is that my table rows should be draggable and grouped in some parts which affects on list behavior like table. Here is my Code http://jsfiddle.net/frontDev111/38pvx9bn/1/
So In my code dd-list is table, dd-itemis table-row and dd-handle is table-cell. It works fine when I have only one table, but I need to have nested tables to make some part of row draggable (e.g from 1.draggable entire row, 2.draggable only right part of row) . So I set dd-list in dd-list in each row. This affects on behavior like table, and table-cell become independent from each other.
So, what can you advise to get table in table but keep table-cell's dependence from each other?
.dd-list {
display: table ;
vertical-align: middle;
width: 100%;
margin: 0 auto;
padding: 0;
}
.dd-item {
list-style: decimal;
display: table-row ;
vertical-align: middle;
}
.dd-item, .dd-empty, .dd-placeholder {
position: relative ;
padding: 0;
margin: 0;
min-height: 20px ;
}
.dd-handle {
display: table-cell ;
vertical-align: top;
margin: 5px 0 ;
padding: 10px;
text-decoration: none ;
font-weight: bold ;
border-bottom: 1px solid #dddddd;
border-right: 1px solid #dddddd;
box-sizing: border-box;
}
.dd-container, .btn-gray {
border-left: 1px solid #dddddd;
}
<ol ui-tree-nodes="" class="dd-list dd-container ng-scope">
<li class="dd-item">
<div class="dd-handle dd-head">-</div>
<div class="dd-handle dd-head">1.draggable dfdfd</div>
<ol class="dd-list">
<li class="dd-item">
<div class="dd-handle dd-head">2.draggable</div>
<div class="dd-handle dd-head">bbb</div>
<div class="dd-handle dd-head">ccc</div>
<div class="dd-handle dd-head">ddd</div>
<div class="dd-handle dd-head">gg</div>
<div class="dd-handle dd-head">ggg</div>
</li>
</ol>
</li>
<li class="dd-item ng-pristine ng-untouched ng-valid ng-scope angular-ui-tree-nodes" ng-repeat="employee in employees" ui-tree-nodes="" ng-model="employees" data-type="employee">
<div class="dd-handle ng-binding">1</div>
<div class="dd-handle">
<edit-in-place id="1" value="employee.name" class="ng-isolate-scope edit-in-place"><span ng-click="edit()" ng-bind="value" class="ng-binding">test</span>
</edit-in-place>
</div>
<ol class="dd-list ng-pristine ng-untouched ng-valid ng-scope angular-ui-tree-nodes" ui-tree-nodes="" ng-model="employee.contracts" data-type="contract">
<li class="dd-item ng-scope angular-ui-tree-node" ng-repeat="contract in employee.contracts" ui-tree-node="" collapsed="false">
<div class="dd-handle">
<edit-in-place value="contract.client_name" class="ng-isolate-scope edit-in-place"><span ng-click="edit()" ng-bind="value" class="ng-binding">fghfghfghfgh</span>
</edit-in-place>
</div>
<div class="dd-handle"> sdfsdgdfg</div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
</li>
<li class="dd-item ng-scope angular-ui-tree-node" ng-repeat="contract in employee.contracts" ui-tree-node="" collapsed="false">
<div class="dd-handle">
<edit-in-place value="contract.client_name" class="ng-isolate-scope edit-in-place"><span ng-click="edit()" ng-bind="value" class="ng-binding">test</span>
</edit-in-place>
</div>
<div class="dd-handle"> sdfsdgdfg</div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
<div class="dd-handle"> </div>
</li>
</ol>
</li>
</ol>
Please have a look at the following markup:
<div class="wrapper">
<article class="main" >My awesome content here </article>
<footer class="footer">Some informations here </footer>
<header class="header">My site title goes here </header>
<aside class="sidebar">Here is my side content </aside>
<aside class="annexe" >Some more side content </aside>
</div>
Now the CSS. Pay attention to the number of lines:
.wrapper {
display: grid;
grid-columns: 200px 15px 1fr 15px 100px;
grid-rows: (auto 15px)[2] auto;
}
.header, .footer { grid-column-span: 5; }
.sidebar,
.main,
.annexe { grid-row: 3; }
.header { grid-row: 1; }
.footer { grid-row: 5; }
.sidebar { grid-column: 1; }
.main { grid-column: 3; }
.annexe { grid-column: 5; }
Done. 10 lines. No float. No inline-block. No height. No width. No margin. And if you want to make everything nice on small devices.
Note: I won’t explain the syntax. If you want to understand how works the Grid Layout, please have a look at: CSS-Tricks