I am having trouble trying to have a responsive grid of 3 boxes with some aligned content inside using the library Bulma. I would like to make it work still maintaining the level inside a box if possible.
Any help would be appreciated.
This is the result I expect:
But when decreasing the width, it breaks:
This is the code I am using:
<div className="columns sub">
{this.props.options.map(option => (
<div className="column is-one-third" key={option.id}>
<div
name={option.id}
className={
`box ` +
(this.props.optionToBeChosen === option.id
? "box-is-active"
: "")
}
onClick={() => this.props.onClick(option.id)}
>
<div className="level is-mobile">
<div className="level-item level-left">
<div>
<p className="box-text-title">{option.title}</p>
<p className="box-text-small">{option.description}</p>
<p className="box-text-small">{option.description2}</p>
</div>
</div>
<div className="level-item level-right has-text-right">
<div>
<p className="box-text-demo">{option.cta}</p>
</div>
</div>
</div>
</div>
</div>
))}
</div>
The Bulma levels are explicitly told not to shrink
.level-left, .level-right {
flex-basis: auto;
flex-grow: 0;
flex-shrink: 0;
}
You'll have to override that to get the levels to not break out of the .box elements.
Rather than overriding ALL level items, I suggest you add a custom class to those levels that you want to be able to shrink.
Something like
<div class="level is-mobile level-is-shrinkable">
Level items here...
</div>
<style>
.level-is-shrinkable .level-left,
.level-is-shrinkable .level-right {
flex-shrink: 1;
}
</style>
In my case, I had to add a third styling condition for centered level-item elements:
.level-is-shrinkable .level-left,
.level-is-shrinkable .level-item,
.level-is-shrinkable .level-right {
flex-shrink: 1;
}
Many thanks to just-a-web-designer for his|her answer.
Related
I have array of elements that I want to display, and I want to create this all tiles in same width, and make div 100% width. (In this code the tile sizes are different). Any help is much appreciated.
<div class="summaryArea" align="center">
<div *ngFor="let item of getSummery()">
<kendo-tilelayout [rowHeight]="200" [resizable]="true">
<kendo-tilelayout-item>
<kendo-tilelayout-item-body align="center">
<div class="summary" align="center">
<h4>{{item.amount}}</h4>
<div *ngIf="item.status == 'up'"><span class="k-icon k-i-arrow-60-up k-icon-md" style="color:green"></span></div>
<div *ngIf="item.status == 'down'"><span class="k-icon k-i-arrow-60-down k-icon-md" style="color:red"></span></div>
</div>
<br />
<div>{{item.name}}</div>
<hr />
<div>{{item.Description}} </div>
</kendo-tilelayout-item-body>
</kendo-tilelayout-item>
</kendo-tilelayout>
</div>
</div>
This is my CSS
.summary {
display:inline-flex;
}
.summaryArea {
width:fit-content;
font-size:medium;
display: flex;
}
I tried like this but this not works
<kendo-tilelayout-item [width] ="calculatewidth(getSummery().length)">
Ts file
public calculatewidth(length) {
return 100 / length+'%';
}
what if the width in the .summaryArea area is changed to width : 100%? is the result what you want?
I did it using following code. Thanks All for your effort
<div class="summaryArea">
<div *ngFor="let item of getSummery()" [style.width]="calculatewidth(getSummery().length)">
<kendo-tilelayout [rowHeight]="170">
<kendo-tilelayout-item>
<kendo-tilelayout-item-body align="center">
//content
</kendo-tilelayout-item-body>
</kendo-tilelayout-item>
</kendo-tilelayout>
</div>
</div>
Css
.summaryArea {
width:100%;
font-size:medium;
display: flex;
}
ts
public calculatewidth(length) {
return 100 / length + '%';
}
try by using 25% each because it is 4 box
This question already has answers here:
CSS 3 nth of type restricted to class [duplicate]
(2 answers)
Closed 1 year ago.
I'm been working on finding a way to change my even and odd setup so it relies more on the classes instead of the html strucktur but am at a complet loss.
The setup i but below works but if there's too much change to the HTML it would likely break.
(The HTML images gives a simpel overview)
The collapsed HTML version shows 3 div's but the 2 div is actually a set of 2.
The classes it goes like this:
academy-subject-block
academy-column-block
academy-column-block
academy-subject-block
The end result is 4 squares where the first one keeps it's image from what it had on tablet size screens and above.
The next 3 will alternate between a white and a light grey bagground-color without the images.
HTML from browser view:
HTML Viewed from browser
HTML Viewed from browser collapsed
HTML:
<div class="container academy ">
<div class="academy-front-page">
<div class="fullPageAdjustment">
#Html.PropertyFor(m => m.CurrentPage.ContentArea)
</div>
</div>
</div>
-------------------------------------------------------------
<div class="academy-subject-block">
<div class="row">
<div class="col-xs-12">
<div class="img-fullwidth cover-image">
<img src="#Url.ContentUrl(Model.CoverImage)" alt="Cover Image" class="fill-height-image min-height"/>
<div class="cta-turquiose-centerallign-mobile">
<a href="#Url.ContentUrl(Model.ButtonLink)" class="pulse animated btn bta-cta-turkuoise">
#Html.PropertyFor(l => l.ButtonText)
</a>
</div>
</div>
</div>
</div>
<div class="text-block-image fadeIn animated">
#Html.PropertyFor(m => m.OverlayText)
</div>
</div>
-------------------------------------------------------------
<div class="academy-column-block ">
<div class="img-fullwidth cover-image">
<img src="#Url.ContentUrl(Model.CoverImage)" alt="Cover Image" class="fill-height-img min-height"/>
<div class="cta-turquiose-centerallign">
<a href="#Url.ContentUrl(Model.ButtonLink)" class="pulse animated btn bta-cta-turkuoise">
#Html.PropertyFor(l => l.ButtonText)
</a>
</div>
</div>
<div class="text-block-image-column-block fadeIn animated">
#Html.PropertyFor(m => m.OverlayText)
</div>
</div>
SCSS:
//Pulls the section up and down as to remove any spacing
.academy-front-page {
.fullPageAdjustment {
#include mobile {
position: relative;
margin-top: -80px;
bottom: -40px;
}
}
//Removes images but keeps the size without effecting the fist image
//And adds new text color to images that have changed
:not(:first-child) {
#include mobile {
img {
width: 0;
}
.text-block-image-column-block {
color: #{$Color-DarkPurple};
}
.text-block-image {
color: #{$Color-DarkPurple};
}
}
}
//Switches between background-colors of the images with exception of the fist one (Mobile only)
div :nth-child(odd) {
#include mobile {
.img-fullwidth {
background-color: #{$Color-White};
}
.hidden-print {
.img-fullwidth {
background-color: #{$Color-WhiteSmoke};
}
}
}
}
:nth-child(even) {
#include mobile {
.img-fullwidth {
background-color: #{$Color-White};
}
.hidden-print {
.img-fullwidth {
background-color: #{$Color-WhiteSmoke};
}
}
}
}
}
Afaik, this is currently not possible with CSS alone.
You would have to:
use Javascript to implement that CSS class based or
go with the CSS pseudo classes :nth-of-type or :nth-child depending on HTML elements.
I've got a menu with 3 levels of deepness. It starts with the categories, then the subcategories, and after all, the final links. Some of these links are already in the second or even the first level, but that's not a problem. The menu is working fine.
The problem is that I'm trying to make it look fancy, so I added to each div a class that designates the menu level. You can see the full Angular template here. Mind that these classes are the "lvl0", "lvl1", "lvl2":
<div class="menu-container">
<div class="row header">
<img class="logo" src="../../../assets/menu-header.PNG">
</div>
<div class="row menu-btn">
<div class="inner-menu-btn" (click)="openMenu()">
<span class="menu-span" [#menuStringAnim]="active">MENU</span>
<i class="fa fa-bars menu-icon" [#menuIconAnim]="active"></i>
</div>
</div>
</div>
<div class="menu-list" [#menuListAnim]="active">
<div class="row row-fix lvl0" *ngFor="let category of getCategories()" (click)="openCategory(category)">
<div class="little-menu-bar-toplvl" *ngIf="categoriesNavigator.lvl0 == category.key"></div>
<span class="menu-top-level">{{ category?.title?.toUpperCase() }} </span>
<div *ngIf="categoriesNavigator.lvl0 == category.key">
<br>
<div class="row row-fix lvl1" *ngFor="let subcategory of getSubcategories(category.key)" (click)="openSubcategory(subcategory)">
<div class="little-menu-bar-midlvl"></div>
<span class="menu-second-level">{{ subcategory?.title?.toUpperCase() }} </span>
<div *ngIf="categoriesNavigator.lvl1 == subcategory.key">
<br>
<div class="row row-fix lvl2" *ngFor="let thirdLevel of getThirdLevel(category.key, subcategory.key)" (click)="openUrl(thirdLevel)">
<div class="little-menu-bar-lowlvl" *ngIf="categoriesNavigator.lvl0 == category.key"></div>
<span class="menu-third-level">{{ thirdLevel?.title?.toUpperCase() }} </span>
</div>
</div>
</div>
</div>
</div>
</div>
So these classes are very simple. I'm not very good at CSS (I prefer designing logic rather than designing), and maybe I'm doing some stupid thing here:
.lvl0 :hover{
color: orange;
}
.lvl1 :hover{
color: orange;
}
.lvl2 :hover{
color: orange;
clear: both;
}
So the behavior works nice for first level, but as you can see, all the rows with the second level get highlighted instead of just the one I'm hovering on:
Same happens with the third level.
Do you have any idea on what I'm doing wrong? I'm adding the Angular tag just in case it has something to do with my template code. Thank you!
The problem is that you have applied the style to your div and as the divs are nested, the styles will cascade and turn everything inside it the colour - you can try to apply the styles directly to the spans to avoid this. Also I have removed the space before your hover colon
.lvl0:hover>span { /* leave hover on div but style the span */
color: orange;
}
.lvl1:hover>span {
color: red;
}
.lvl2:hover>span {
color: green;
}
<div class="lvl0">
<span>test 0</span>
<div class="lvl1">
<span>test 1</span>
<div class="lvl2">
<span>test 2</span>
</div>
</div>
</div>
The :hover is basically propagating down to other levels. Do not use CSS on the parent directly. Instead, use it on something like span etc.
Check pen here to solve your issue. In your case, you can have <div> tag too instead of the span which closes there and is basically a sibling of next level.
.lvl:hover {
//common for all
color: orange;
}
I have two divs that I want to show on the page. The order of the two divs depends on the value of a variable on the scope.
The trivial way of doing this is by repeating the divs code twice in the page, each time in a different order:
<div class="option 1" ng-if="value">
<div class="div 1">
<p>"this is the content for div 1"</p>
</div>
<div class="div 2">
<p>"this is the content for div 2"</p>
</div>
</div>
<div class="option 2" ng-if="!value">
<div class="div 2">
<p>"this is the content for div 2"</p>
</div>
<div class="div 1">
<p>"this is the content for div 1"</p>
</div>
</div>
Is there another way to do this, without repeating the code?
If you do not support IE9 I guess you can use the flexbox order CSS property with a conditional class.
<div class="main">
<div ng-class="{after: !value}">this is the content for div 1</div>
<div class="fixed">this is the content for div 2</div>
</div>
And the CSS:
.main { display: flex; flex-direction: column; }
.fixed { order: 2; }
.after { order: 3; }
See the flexbox order in action: https://jsfiddle.net/a6eaov63/2/
UPDATE: You can move each <div> to external file and include it in proper order depending on value.
<ng-include src="value ? 'div1.html' : 'div2.html'"></ng-include>
<ng-include src="value ? 'div2.html' : 'div1.html'"></ng-include>
(function(angular) {
'use strict';
angular.module('orderDivs', [])
.controller('orderController', ['$scope', function($scope) {
//$scope.variable = true; //uncomment this line to reverse the div ..
$scope.divList = [{'div':'option 1','condition':'true', 'content':'THIS IS DIV 1111'},{'div':'option 2','condition':'false', 'content':'THIS IS DIV 2222'}]
if ($scope.variable){
$scope.divList = $scope.divList.reverse();
}
$scope.changeOrder = function(){
$scope.divList = $scope.divList.reverse();
}
}]);
})(window.angular);
<!-- in views -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.1/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="orderDivs">
<div ng-controller="orderController">
<input type="checkbox" ng-click="changeOrder()" ng-model="variable"/>
<div ng-repeat="opt in divList">
<div class="option" ng-model="opt.div" ng-if="opt.condition">
<div>
{{opt.content}}
</div>
</div>
</div>
</div>
</body>
</html>
:)
I started making a website few days ago and I'm stuck at this step:
http://jsfiddle.net/r6uhczks/
CSS:
/* This section to be trigger of dropdown process */
.parent_style { background: -webkit-linear-gradient(left,rgba(0,0,0,0.5),transparent); width: 325px; height: 21px; }
.parent_style:hover { background: -webkit-linear-gradient(left,rgba(242,182,0,0.7),transparent); }
.parent_style .textP {}
.parent_style:hover .textP {color: red;}
/* This section to be shown by clicking on ↑ and hidden by clicking for second time */
.child_style { background: rgba(0, 0, 0, 0.5); width: 325px; height; auto; }
.child_style:hover { background: rgba(242,182,0,0.7);}
.child_style .textC {color: white;}
.child_style:hover .textC {color: black;}
As you can see I created two styles for dropdown menu,
.parent_style
defines trigger of show/hide content defined by
.child_style
Simplier I want to make a class="parent_style" to be show/hide trigger of shown/hidden class="child_style"
The problem is that I don't know how to create this action by click with CSS/HTML only, I know only by hover.
HTML:
<div class="parent_style">
<p class="textP">Something</p>
</div>
<div class="child_style">
<p class="textC">Content</p>
</div>
<div class="child_style">
<p class="textC">Content2</p>
</div>
<div class="child_style">
<p class="textC">Content3</p>
</div>
<div class="parent_style">
<p class="textP">Something else</p>
</div>
<div class="child_style">
<p class="textC">Content</p>
</div>
<div class="child_style">
<p class="textC">Content2</p>
</div>
<div class="child_style">
<p class="textC">Content3</p>
</div>
<div class="parent_style">
<p class="textP">Something else 2</p>
</div>
<div class="child_style">
<p class="textC">Content</p>
</div>
<div class="child_style">
<p class="textC">Content2</p>
</div>
<div class="child_style">
<p class="textC">Content3</p>
</div>
<br>
EDIT: and also I would like to know how to edit spaces between these elements, best to remove them.
You can add state to CSS and HTML by using checkboxes (persistent) or focus (temporary):
http://jsfiddle.net/rudiedirkx/L40zcjfc/
HTML
<button>hold down here</button>
<ul>
<li>Foo</li>
<li>Bar</li>
<li>Baz</li>
</ul>
<br />
<br />
<button><label for="cb1">click here</label></button>
<input id="cb1" type="checkbox" />
<ul>
<li>Foo</li>
<li>Bar</li>
<li>Baz</li>
</ul>
CSS
input,
ul {
display: none;
}
button:active + ul,
input:checked + ul {
display: block;
}
The persistence comes from the checkbox's :checked state. You can toggle the checkbox with a <label> so you don't have to know it's there.
The temporariness comes from the :active state of a button. Maybe you can use a normal link, but that might keep focus and/or active.
If you can use custom html and css, i'm sure you can stick a custom script at the bottom of the page if it doesn't allow you to add to the head (keep in mind this script requires the page to be loaded first).
Because the elements are not paired together in individual divs, the javascript is a bit longer but nothing too complicated. This script I created will scan through all the divs on the page and will allow the onclick function to determine what the next three divs are. This means that the script is custom to your layout of navigation so you'll need to change the javascript with a layout change.
Here is a working jsfiddle: http://jsfiddle.net/sLc4svam/
<script>
var divs = document.getElementsByTagName("div");
var parents = document.getElementsByClassName("parent_style");
for (var i=0; i<parents.length; i++) {
parents[i].onclick = function() { toggleChildren(this); };
}
function toggleChildren(elem) {
for (var i=0; i<divs.length;i++) {
if (divs[i] == elem) {
for (var ii=1; ii<=3; ii++) { // The 3 is how many children it will toggle
if (divs[i+ii].style.display == "none") {
divs[i+ii].style.display = "block";
} else {
divs[i+ii].style.display = "none";
}
}
}
}
}
</script>