Bootstrap stretched-link on custom element - html

I am struggling with stretched-link. I've wanted to make a div with class menu-button working as a link, but clearly I am doing something wrong. Can anyone explain to me how to do it properly?
Here is the code:
import {BsHouseDoor} from 'react-icons/bs';
const Menu = () => {
return (
<div className={"menu container-fluid"}>
<div className={"row h-100"}>
<div className={"col-4"}>
<div className="d-flex align-items-center h-100 pl-3">
<BsHouseDoor className={"logo-icon"}/>
<span className={"logo-title ml-3"}>Some name</span>
</div>
</div>
<div className={"col-5"}>
<div className={"d-flex justify-content-around h-100"}>
<div className={"menu-button d-flex position-relative w-100 justify-content-center align-items-center"}>
Home
</div>
<div className={"menu-button d-flex w-100 position-relative justify-content-center align-items-center"}>
About
</div>
<div className={"menu-button d-flex w-100 position-relative justify-content-center align-items-center"}>
Contact
</div>
</div>
</div>
</div>
</div>
);
}
export default Menu;

Related

How to manage long text div using bootstrap CSS flex boxes

I'm modifying a CSS template based on bootstrap, in order to obtain a responsive simple website.
The page provides a list of events. Since show_date and show_shop have fixed width, when the website is opened on a smartphone (smaller screen) the class flex-row allows the show_name and show_location to be disposed in column to save space.
The problem is that when the text in show_name and show_location is too long, the text wrap out of the box in vertical.
How can I force the text in show_name and show_location to use only a single line (one for each one), truncating the text with ...?
I tried overflow: hidden with text-overflow: ellipsis but it doesn't work (I think due to the flex width of the div).
Thanks for help.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="col-lg-8 order-lg-1 order-2 shows_list_col">
<div class="shows_list_container">
<ul class="shows_list">
<li class="d-flex flex-row align-items-center justify-content-start">
<div>
<div class="show_date">18/07</div>
</div>
<div class="show_info d-flex flex-md-row flex-column align-items-md-center align-items-start justify-content-md-start justify-content-center">
<div class="show_name">Electric Castle Festival</div>
<div class="show_location">Cluj, Romania</div>
</div>
<div class="ml-auto">
<div class="show_shop trans_200">Buy Tickets</div>
</div>
</li>
<li class="d-flex flex-row align-items-center justify-content-start">
<div>
<div class="show_date">20/07</div>
</div>
<div class="show_info d-flex flex-md-row flex-column align-items-md-center align-items-start justify-content-md-start justify-content-center">
<div class="show_name">Ultra Music Festival</div>
<div class="show_location">Miami, USA</div>
</div>
<div class="ml-auto">
<div class="show_shop trans_200">Buy Tickets</div>
</div>
</li>
<li class="d-flex flex-row align-items-center justify-content-start">
<div>
<div class="show_date">25/08</div>
</div>
<div class="show_info d-flex flex-md-row flex-column align-items-md-center align-items-start justify-content-md-start justify-content-center">
<div class="show_name">Vikings Festival</div>
<div class="show_location">Oslo, Norway</div>
</div>
<div class="ml-auto">
<div class="show_shop trans_200">Buy Tickets</div>
</div>
</li>
</ul>
</div>
</div>
You could simply use the text-nowrap class on those divs and use spans inside. I've also removed some redundant div elements and combined classes.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="col-lg-8 order-lg-1 order-2 shows_list_col">
<div class="shows_list_container">
<ul class="shows_list">
<li class="d-flex flex-row align-items-center justify-content-start">
<div class="show_date mr-3">18/07</div>
<div class="show_info text-nowrap">
<span class="show_name">Electric Castle Festival</span>
<span class="show_location">Cluj, Romania</span>
</div>
<div class="show_shop trans_200 ml-auto">Buy Tickets
</div>
</li>
<li class="d-flex flex-row align-items-center justify-content-start">
<div class="show_date mr-3">20/07</div>
<div class="show_info text-nowrap">
<span class="show_name">Ultra Music Festival</span>
<span class="show_location">Miami, USA</span>
</div>
<div class="show_shop trans_200 ml-auto">Buy Tickets</div>
</li>
<li class="d-flex flex-row align-items-center justify-content-start">
<div class="show_date mr-3">25/08</div>
<div class="show_info text-nowrap">
<span class="show_name">Vikings Festival</span>
<span class="show_location">Oslo, Norway</span>
</div>
<div class="show_shop trans_200 ml-auto">Buy Tickets</div>
</li>
</ul>
</div>
</div>
Since show_date and show_shop have fixed width
You can easily achieve this with some few lines of CSS
#media (max-width: 767.98px){
.show_info {
width: calc(100% - 50px - 70px); /* where 50px and 70px are the width of .show_date and .show_shop respectively */
}
.show_name, .show_location {
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
I've solved my problem following the bootstrap's way.
I can obtain the best result adding the class text-truncate to the classes show_info, show_name, and show_location.
Thanks for help!

Center logo + menu bar?

I am using this theme: https://themeforest.net/item/memento-multipurpose-funeral-services-html-template/23890802
Can somebody explain me where I start with centering the logo + the menubar?
<section class="page_toplogo ls s-pt-25 s-pb-20 s-py-md-30">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-12">
<div class="d-md-flex justify-content-md-end align-items-md-center">
<div class="mr-auto">
<div class="d-none d-md-flex justify-content-center justify-content-md-start">
<a href="./" class="logo">
<img src="images/logo.png" alt="">
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
thanks in advance
If all you want to do is to center the logo your can remove the mr-auto class from the html or this css
.page_toplogo .mr-auto {
margin-right: 0 !important;
}
If you also want to remove those items to the right of the logo, either remove the html or hide them with display: none and replace justify-content-center with justify-content-start to the logo wrapper.

Is it possible to combine several bootstrap classes into one?

I am using different bootstrap classes multiple times in an HTML <form>.
e.g.:
<form id="frmData" name="frmData" method="POST">
<div class="row justify-content-sm-center mb-2 align-items-center">
<div class="col-12 col-sm-auto d-flex justify-content-md-end">
<label>....</label>
</div>
<div class="col-12 col-sm-6 col-lg-4">
<input .....>
</div>
</div>
<div class="row justify-content-sm-center mb-2 align-items-center">
<div class="col-12 col-sm-auto d-flex justify-content-md-end">
<label>....</label>
</div>
<div class="col-12 col-sm-6 col-lg-4">
<input .....>
</div>
</div>
......
</form>
Is there an opportunity to define a class for the <div> of the <label> for example and reuse it for every <div> that is containing a label?
This would help a lot during development. Instead of changing the classes of each <div>, it would be sufficient to change only the class definition.
Something like this:
<div class="div_class">
<label>...</label>
</div>
<style>
.div_class {
.col-12
.col-sm-auto
.d-flex
.justify-content-md-end
}
</style>
This I think will be the only way to do it in pure CSS. In this model all of the innner Div's and Label's should inherit settings from the new wrapper that I have added and .div_class > * ensures only children are affected not grandchildren. Give it a try any way.
<div class="wrapper">
<!-- Now as many of your label divs as you need -->
<div class="div_class">
<label>...</label>
</div>
<div class="div_class">
<label>...</label>
</div>
<div class="div_class">
<label>...</label>
</div>
</div>
And the CSS
.wrapper * {
color: black;
}
.div_class > * {
color:blue;
}

Bootstrap 4 issue with div content of different sizes

I am stuck with the following issue, as per the below script, where the data in a div is not always the same size, which results in the div NOT taking the entire horizontal space allocated by the use of the col-6 class, from one row to the next:
<div class="card-body " >
<div class="row comments_container" id="comments_container">
<?php foreach ($comments AS $comment){?>
<div class="callout <?php echo $comment['comment_callout'];?>">
<div class="row">
<div class="col-3"><?php echo '<span class="text-bold">De: </span>'.$comment['comment_author'];?></div>
<div class="offset-6 col-3">Envoyé le: <?php echo $comment['comment_date'];?></div>
</div>
<div class="row">
<div class="offset-3 col-6 border-primary border-left">
<?php
if (!empty($comment['comment_parent_author'])){echo 'En réponse à '.$comment['comment_author'].'.<br/>';}
echo '<span class="text-xs">'.$comment['comment_content'].'</span>';
?>
</div>
<div class="col-3"></div>
</div>
<div class="row justify-content-center border-top mt-2 pt-2 border-thick border-primary w-100">
<div class="col-1">Approuver</div>
<div class="col-1">Répondre</div>
<div class="col-1">Indésirable</div>
<div class="col-1">Corbeille</div>
</div>
</div>
<?php } ?>
</div>
</div>
As you can see also from the below adjoined screenshot, when the $comment['comment_content'] data is not the same size, or smaller, it results in the div containing the smallest data not 'respecting' the col-6 class, eg. only taking the smallest data field's size
Your classes are not formatted very well try this :
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container card-body">
<div class="row comments_container" id="comments_container">
<div class="col-3"><span class="text-bold">De:John john</span></div>
<div class="offset-6 col-3">Envoyé le : 31 mai 2020 </div>
</div>
<div class="offset-3 col-6 border-primary border-left">
<span class="text-xs">Commentaire</span>
</div>
<div class="row justify-content-center border-top mt-2 pt-2 border-thick border-primary w-100">
<div class="p-1">Approuver</div>
<div class="p-1">Répondre</div>
<div class="p-1">Indésirable</div>
<div class="p-1">Corbeille</div>
</div>
</div>

Bootstrap 4: Footer not at bottom

I know this question was probably asked some hundred times, but sadly no answer that I found in here really helped me.
I tried these answers for example:
Bootstrap footer not at bottom
Flushing footer to bottom of the page, twitter bootstrap
Height not 100% on Container Fluid even though html and body are
But I still have the problem that when my page content is to "small" and doesn't fill out the whole height of the body/page container the footer just floats somewhere above the end of the browser window.
This is the code for my footer:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<footer class="d-flex justify-content-center">
<div class="d-flex justify-content-between col-md-8 col-md-offset-2 mb-3 mt-5">
<div class="align-left">
<a class="font-weight-bold small kf-blue kf-links" href="#">Link1</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link2</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link3</a>
</div>
<div class="align-right small">
Crafted with Love by <a class="font-weight-bold kf-blue kf-links" href="#" target="_blank">Me</a>
</div>
</div>
</footer>
I'm using Bootstrap 4.1 and Chrome, here's also a codepen to my site:
https://codepen.io/anon/pen/oMZVxq
Note: you have to use the sidebar view in codepen to actually see that the footer is not at the bottom, as the view size in codepen is so small that it looks correctly.
You can use built-in bootstrap class to achieve this.
What you need is the container to be a column flex container . class to use are : d-flex flex-column
To set the container to height:100% you can apply the class h-100to html, body and the container or add to the container style height:100vh;
For the footer, a margin-top:auto will do, the class to use is : mt-auto;
example below to run in full page mode
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<html class="h-100">
<body class="h-100">
<!-- Page Container -->
<div id="page-container" class="container-fluid pr-0 pl-0 h-100 d-flex flex-column">
<!-- Header -->
<nav class="navbar navbar-expand-lg navbar-light bg-light pt-3 pb-3 d-flex justify-content-center">
<div class="col-md-8 col-lg-8 col-sm-12 col-xs-12 d-flex justify-content-between">
<div class="d-flex justify-content-start align-items-center">
<a href="/" class="kf-links">
<span class="h5">
<i class="fas fa-paper-plane"></i>
<span class="h4 font-weight-bold kf-dark">
MyPage
</span>
</span>
</a>
</div>
<!-- Main Header Navigation -->
<div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
<ul class="navbar-nav">
<li class="nav-item">
Link1
</li>
<li class="nav-item">
Link2
</li>
<li class="nav-item">
Link3
</li>
</ul>
</div>
<!-- END Main Header Navigation -->
</div>
</nav>
<!-- END Header -->
<!-- Main Container -->
<div style="background:#5c90d2">
<div class="col-md-12 text-center pt-5 pb-5">
<div class="pt-5 pb-5">
<h1>
<span class="main-text">
Login
</span>
</h1>
<p class="lead"><span class="main-text">
Login Now!
</span></p>
</div>
</div>
</div>
<!-- Content -->
<div class="d-flex justify-content-center fadeIn">
<div class="col-md-8 col-xs-12">
<div class="d-flex justify-content-center">
<div class="col-md-6 pt-5 pb-5 pr-0 pl-0">
<form class="form-horizontal" method="post">
<div class="form-group">
<div class="col-xs-12">
<div class="">
<label for="id_username">E-Mail</label>
<input id="id_username" class="form-control" maxlength="254" name="username" value="" type="text" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<div class="">
<label for="id_password">Password</label>
<input id="id_password" class="form-control" name="password" type="password" required>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<small class="float-right">
Forgot Password?
</small>
</div>
</div>
<div class="form-group mt-5">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4 pl-0">
<button class="btn btn-sm btn-block btn-primary" type="submit">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- END Content -->
<!-- END Main Container -->
<!-- Footer -->
<footer class="d-flex justify-content-center mt-auto">
<div class="d-flex justify-content-between col-md-8 col-md-offset-2 mb-3 mt-5">
<!-- Copyright Info -->
<div class="align-left">
<a class="font-weight-bold small kf-blue kf-links" href="#">Link1</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link2</a> |
<a class="font-weight-bold small kf-blue kf-links" href="/">Link3</a>
</div>
<div class="align-right small">
Crafted with Love by <a class="font-weight-bold kf-blue kf-links" href="#" target="_blank">Me</a>
</div>
<!-- END Copyright Info -->
</div>
</footer>
<!-- END Footer -->
</div>
<!-- END Page Container -->
</body>
</html>
codepen updated https://codepen.io/anon/pen/PBpgNN
reminder for boostrap classes https://getbootstrap.com/docs/4.5/utilities/flex/ about sizing see https://getbootstrap.com/docs/4.5/utilities/sizing/
If you want a fixed footer, just add the class fixed-bottom to the footer tag like shown below.
<footer class="fixed-bottom bg-dark">
<div class="text-center">
<p>Footer</p>
</div>
</footer>
First add display: flex; and flex-direction: column; to #page-container.
Now you have "set the stage" for aligning the footer to the bottom. Set its margin-top to auto (by adding the class mt-auto) and you are done;
<div class="d-flex justify-content-center mt-auto">
Content here
</div>
See this codepen.
So this helped me - if someone is still looking for an answer:
on your <HTML>, <body> and your container div add a class h-100 and your footer will stay on the bottom.
Important
One thing I did to remove the extra height is that on my container div I changed the h-100 styling to height: calc(100% - 200px) !important; (where -200px was the height of my navigation and footer)
if you are not using the bootstrap, here is the styling .h-100{height:100% !important}