Do you have a list of words that you want to arrange in columns to optimize space in an HTML file for a Django project?
If you're not very familiar with web development, feel free to break it down to me like I'm 10 years old!
{% extends "todo/base.html" %}
{% block content %}
<style>
.elements {
display: block;
}
ul.items {
display: flex;
margin: 0;
padding: 0;
flex-wrap: wrap;
list-style: none;
}
li.item {
flex: 1 0 20%;
padding: 8px;
margin: 2px;
border-radius: 8px;
border: 1px solid rgba(61, 86, 233, 0.3);
text-align: center;
}
.col {
display: flex;
flex-direction: column;
align-items: center;
}
</style>
<!-- Header -->
<header class="intro-header">
<div class="container">
<div class="col-lg-5 mr-auto order-lg-2">
<h3><br>Introduce yourself... </h3>
</div>
</div>
</header>
<!-- Page Content -->
<section class="content-section-a">
<div class="container">
<dt>
<span>Select keywords to express your fragrance preferences</span>
</dt>
<form action = "/getmatch" method="POST">
{% for keyword in keywords %}
<div class="elements">
<ul class="items ">
<li class="item col-xs-6 col-sm-3 col-md-3 col-lg-3">
<div data-toogle="buttons" class="col">
<span>{{ keyword.title }}</span>
</div>
</li>
</ul>
</div>
{% endfor %}
{% csrf_token %}
<button type="submit">Submit</button>
</form>
</div>
</section>
<!-- Bootstrap core JavaScript -->
<script src="static/vendor/jquery/jquery.min.js"></script>
<script src="static/vendor/popper/popper.min.js"></script>
<script src="static/vendor/bootstrap/js/bootstrap.min.js"></script>
{% endblock %}
If you're unsure whether to include this in a specific CSS file like style.css
or if adding it within <style>
tags in your file is better, you can go with the latter for simplicity.
Currently, the buttons look good but are not aligned properly:
https://i.sstatic.net/y9gKj.png
Additionally, the multi-selection effect is not working as expected.
In base.html
, the following style.css
is loaded with this line:
<link href="static/css/style.css" rel="stylesheet">
/*!
* Start Bootstrap - Landing Page (http://startbootstrap.com/template-overviews/landing-page)
* Copyright 2013-2017 Start Bootstrap
* Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap-landing-page/blob/master/LICENSE)
*/
<!-- CSS styles for better button alignment -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Test Document</title>
<style>
.elements {
display: block;
}
ul.items {
display: flex;
margin: 0;
padding: 0;
flex-wrap: wrap;
list-style: none;
}
li.item {
display: flex;
flex-direction: column;
align-items: center;
flex: 1 0 20%;
padding: 8px;
margin: 2px;
border-radius: 8px;
border: 1px solid rgba(61, 86, 233, 0.3);
text-align: center;
}
</style>
</head>
<body>
<h1>Buttons</h1>
<div class="elements">
<ul class="items">
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
<li class="item">
<i class="fa fa-home"></i>
<span>Label</span>
</li>
</ul>
</div>
</body>
</html>
You can consider arranging them as shown above for a better visual presentation.