I have the following in my CSS file, and it works fine apart from the rule around --md and --sm arent turning off when the screen width goes over 899px.
.ProductThumbnail {
position: relative;
overflow: visible;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
&--md,
&--sm {
display: none;
background-position: 30% top;
#include media('sm', true, true) {
display: block;
}
}
&--lg {
display: none;
background-position: 25% top;
width: 1600px;
#include media('md', true) {
display: block;
}
}
}
The return function in the react component is as follows:
return (
<>
<div
className="ProductThumbnail__bg ProductThumbnail__bg--xs"
style={{
backgroundImage: getURL({
w: 600,
h: 455,
}),
}}
/>
<div
className="ProductThumbnail__bg ProductThumbnail__bg--md"
style={{
backgroundImage: getURL({
h: 455,
}),
}}
/>
<div
className="ProductThumbnail__bg ProductThumbnail__bg--lg"
style={{
backgroundImage: getURL({
w: 2560,
h: 1040,
}),
}}
/>
</>
);
I can see in the dev tools that the rules are being applied as expected for --md and --sm but they dont disappear when the screen gets bigger.
Update, media mixin code:
#mixin media(
$breakpoint,
$is-minimum-only: false,
$is-maximum-only: false) {
#if map_has_key($breakpoint-ranges, $breakpoint) {
$breakpoint-range: get-break-point-range($breakpoint);
$breakpoint: "";
#if length($breakpoint-range) < 2 or $is-minimum-only {
$breakpoint: "(min-width:#{nth($breakpoint-range, 1)})";
} #else if $is-maximum-only {
$breakpoint: "(max-width:#{nth($breakpoint-range, 2)})";
} #else {
$breakpoint: "(min-width:#{nth($breakpoint-range, 1)}) and (max-width:#{nth($breakpoint-range, 2)})";
}
#media screen and #{$breakpoint} {
#content;
}
} #else {
#warn "No registered breakpoint for `#{$breakpoint}`";
}
}
if I understand your mixin correctly, it should generate a media-query with "min" and "max" value if there's no "$is-minimum-only" or "$is-maximum-only" set. So in your case I would remove both "true" settings in this line:
#include media('sm', true, true) {
so it looks like this
#include media('sm') {
Now the third case inside the "#if length($breakpoint-range)" statement should take effect.
Not sure if it even makes sense to set both variables to "true". Because they have a "only" in their names, I suppose only one of them should apply at the same time ;)
I hope that helps.
Related
I have a card component id like to leverage the Bootstrap Card ImgOverlay for, but the image itself is coming gatsby-plugin-image as a GatsbyImage. Below is the component:
const BlogPostCard = (props: BlogPostCardProps) => {
const imageData = getImage(props.imgData)
return (
<Card className={style.blogPostCard}>
<Card.ImgOverlay>
<Card.Body className={style.blogPostCardContent}>
<Card.Title as="h1">{props.title}</Card.Title>
<Card.Subtitle className={style.blogDate}>{props.date}</Card.Subtitle>
<Card.Text>{props.excerpt}</Card.Text>
<Card.Link as={Link} to={props.slug}>Read post.</Card.Link>
</Card.Body>
</Card.ImgOverlay>
<Card.Img className={style.blogPostCardImg} as={GatsbyImage} image={imageData} alt="asdf"/>
</Card>
);
};
where the props.imgData is coming from the following graphql fragment:
node {
frontmatter {
...
image {
childImageSharp {
gatsbyImageData(
placeholder: BLURRED
formats: [AUTO, WEBP]
)
}
...
}
}
Here the scss is as follows:
.blogPostCardContainer {
.blogPostCard {
height: 300px;
.blogPostCardContent {
h1 {
color: $primary-font-color;
text-decoration: underline;
}
p {
color: $primary-font-color;
}
.blogDate {
color: $secondary-font-color;
}
}
.blogPostCardImg {
object-fit: cover;
picture {
opacity: 0.3;
}
}
}
padding-bottom: 2vh;
}
Unfortunately, this is just rendering a card 300px high with the image at full width and no cropping to cover. What id really like is something equivalent to the example given in the object-fit docs: https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit
The card should be dynamic with the props.excerpt length (currently just 300px), and the image should scale and crop to fill the background. Where am I going wrong in my CSS?
This was eventually solved by adding some position values to various container elements to allow one to overflow the parent and the other to govern the parent's height:
js
<Card className={style.blogPostCard}>
<Card.Img className={style.blogPostCardImg} as={GatsbyImage} image={imageData}/>
<Card.ImgOverlay className={style.blogPostCardContent}>
<Card.Body>
<Card.Title as="h1">{props.title}</Card.Title>
<Card.Subtitle>{props.date}</Card.Subtitle>
<Card.Text>{props.excerpt}</Card.Text>
</Card.Body>
</Card.ImgOverlay>
</Card>
css:
.blogPostCardContainer {
.blogPostCard {
position: relative;
overflow-y: hidden;
.blogPostCardImg {
position: absolute;
object-fit: cover;
height: 100%;
}
.blogPostCardContent {
position: relative;
}
}
}
I have a couple of SVG that get rendered like this
export const MenuHeaderTab = (props: RenderableProps<Props>) =>
{
const css = props.isActive ? "menu-tab menu-tab-selected" : "menu-tab";
return (
<div onClick={() => props.onClick()} className={css}>
{props.children}
</div>
)
}
the problem i have is that in desktop mode it works fine cause they render in the order that i want them to. the problem is that in mobile portrait mode i want one of the rendered SVG to be first in the order (row). So i thought i use row and just set the className on the SVG
so here is the sass/css
#media all and (orientation: portrait)
{
.menu-tab {
width: 10%;
height: 20%;
margin-left: 4vw;
}
.menu-close-button {
order: -1;
}
.menu-leaderboard-button {
order: 2;
}
.menu-prize-button {
order: 3;
}
.menu-rules-button {
order: 4;
}
so i even provided order to all the SVG and -1 to the one that should be first, but they all stay in the exact same order still. Anyone have any clue why this happens.
Order attribute only works if the father element use display: flex
Assuming the .menu-tab is the father's div of this elements .menu-close-button, .menu-leaderboard-button, .menu-prize-button, .menu-rules-button, you just need to set a display: flex to the .menu-tab
Bellow follow an example of the code:
Look athe the close button, its the last element but how its set -1 as order, it become the first element
.menu-tab {
width: 10%;
height: 20%;
margin-left: 4vw;
display: flex;
}
.menu-tab a{
margin-right: 10px;
}
.menu-close-button {
order: -1;
}
.menu-leaderboard-button {
order: 2;
}
.menu-prize-button {
order: 3;
}
.menu-rules-button {
order: 4;
}
<div class="menu-tab">
leaderboard
Prize
Rules
Close
</div>
I couldn't get a JSFiddle to work properly with React and some other dependencies, so I hope the link to this Github repo is sufficient for demonstrating the issue:
https://github.com/ishraqiyun77/button-issues/
Basically, a group of buttons is rendered and they should be auto-widened to fill white space and take up the whole row. This works in Chrome, Edge, Safari, and Firefox. It looks like this:
This isn't happening in IE. I've been messing with it for hours and haven't made much progress:
Here is the code, although could clone the repo I posted above:
// component.jsx
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import {
Button,
Col,
Modal,
ModalBody,
ModalHeader,
Row
} from 'reactstrap';
import styles from '../assets/scss/app.scss';
class TestPrint extends Component {
constructor(props) {
super(props);
this.state = {
modal: false,
}
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
modal: !this.state.modal
})
}
renderContent() {
let buttons = [];
for (let i = 1; i < 50; i++) {
buttons.push(
<Col key={i}>
<Button
key={i}
className='cuts-btn'
>
{i} - Test
</Button>
</Col>
);
};
return buttons;
}
render() {
return (
<div>
<Button
style={
{
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)'
}
}
onClick={this.toggle}
>
Open Modal for Buttons
</Button>
<Modal
size='lg'
isOpen={this.state.modal}
toggle={this.toggle}
className='results-modal'
>
<ModalHeader toggle={this.toggle}>
Button Issues
</ModalHeader>
<ModalBody>
<div className='results-bq-cuts'>
<Row>
{this.renderContent()}
</Row>
</div>
</ModalBody>
</Modal>
</div>
)
}
}
ReactDOM.render(<TestPrint />, document.getElementById('app'));
.results-modal {
max-width: 1200px;
.modal-content {
.modal-body {
margin-left: 13px;
margin-right: 13px;
.results-bq-cuts {
width: 100%;
.col {
padding:2px;
}
.cuts-btn {
font-size: 11px;
padding: 3px;
width: 100%;
box-shadow: none;
}
// .col {
// padding: 2px;
// display: table-cell;
// flex-basis: 100%;
// flex: 1;
// }
// .cuts-btn {
// font-size: 11px;
// padding: 3px;
// width: 100%;
// box-shadow: none;
// }
}
}
}
}
I have all of the <Button> wrapped in <Col> because that should be what is filling the white space by increasing the size of the button.
Thanks for the help!
IE11 doesn't like working out the width of flex items. If you add flex-basis: calc( 100% / 24 ); to .col it works :) Obviously use any width you want, but what I've given replicates the 21 boxes on one line. But essentially flex-basis needs a defined width to work.
Or add an extra class to each element (such as col-1 ) This'll also achieve the same thing.
I had done one quiz application, But i want to add some animations
like fadein/fade-out, when click the prev/next button. Can any one
help me do the same. something need to change the css something need to change the CSS something need to change the css something need to change the css?
* {}
body {}
.question {
width: 70%;
margin: 0 auto;
height: auto;
display: block;
background: #eeeeee;
}
.question h1 {
text-align: center;
padding-top: 30px;
color: #666666;
}
.question h2 {
width: 100%;
font-size: 22px;
color: #0c1e5c;
padding: 1% 3% 0% 3%;
}
.question ul:nth-child(odd) {
background: #d0dff6;
width: 30%;
padding: 8px;
margin: 1% 9%;
display: inline-block;
color: #0c1e5c;
}
.question ul:nth-child(even) {
background: #d0dff6;
width: 30%;
padding: 8px;
margin: 1% 9%;
display: inline-block;
color: #0c1e5c;
}
.button {
text-align: center;
margin: 1% 0;
}
.btn {
background: #8bf8a7;
padding: 5px;
}
<html ng-app="quiz">
<head>
<meta charset="utf-8">
<title>Basic Quiz</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body ng-controller="quizCtrl">
<div class="question">
<h1>QUIZ APPLICATION</h1>
<h2>{{questions.question}}</h2>
<ul ng-repeat="option in questions.options">
<li style="list-style:none">
<input type="{{buttonType}}">{{option.text}}</li>
</ul>
</div>
<div class="button">
<input type="button" value="previous" class="btn" ng-show="isPrevious" ng-click="previousQuestion()">
<input type="button" value="next" class="btn" ng-show="isNext" ng-click="nextQuestion()">
</div>
</body>
<script>
var app = angular.module("quiz", [])
app.controller("quizCtrl", function($scope) {
$scope.data = [{
question: "1)Which of the following selector matches a element based on its id?",
type: "single",
options: [{
text: "The Id Selector"
},
{
text: "The Universal Selector"
},
{
text: "The Descendant Selector"
},
{
text: "The Class Selector"
}
]
},
{
question: "2)Which of the following defines a measurement as a percentage relative to another value, typically an enclosing element?",
type: "multiple",
options: [{
text: "%"
},
{
text: "cm"
},
{
text: "percentage"
},
{
text: "ex"
}
]
},
{
question: "3)Which of the following property is used to set the background color of an element?",
type: "single",
options: [{
text: "background-color"
},
{
text: "background-image"
},
{
text: "background-repeat"
},
{
text: "background-position"
}
]
},
{
question: "4)Which of the following is a true about CSS style overriding?",
type: "multiple",
options: [{
text: "Any inline style sheet takes highest priority. So, it will override any rule defined in tags or rules defined in any external style sheet file."
},
{
text: "Any rule defined in tags will override rules defined in any external style sheet file."
},
{
text: "Any rule defined in external style sheet file takes lowest priority, and rules defined in this file will be applied only when above two rules are not applicable."
}
]
}
];
$scope.index = 0;
$scope.questions = $scope.data[$scope.index];
$scope.buttonType = $scope.questions.type == 'single' ? 'radio' : 'checkbox';
$scope.isPrevious = false;
$scope.isNext = true;
$scope.nextQuestion = function() {
if ($scope.index < 3) {
$scope.index = $scope.index + 1;
$scope.questions = $scope.data[$scope.index];
$scope.buttonType = $scope.questions.type == 'single' ? 'radio' : 'checkbox';
$scope.isPrevious = true;
if ($scope.index == 3) {
$scope.isNext = false;
}
} else {
// disble next botton logic
$scope.isNext = false;
}
}
$scope.previousQuestion = function() {
if ($scope.index > 0) {
$scope.index = $scope.index - 1;
$scope.questions = $scope.data[$scope.index];
$scope.buttonType = $scope.questions.type == 'single' ? 'radio' : 'checkbox';
$scope.isNext = true;
if ($scope.index == 0) {
$scope.isPrevious = false;
}
} else {
// disble next botton logic
$scope.isPrevious = false;
}
}
});
</script>
</html>
Check out ng-animate, basically what it does is it adds classes that you can style accordingly on showing dom and on hiding dom, like this:
/* The starting CSS styles for the enter animation */
.fade.ng-enter {
transition:0.5s linear all;
opacity:0;
}
/* The finishing CSS styles for the enter animation */
.fade.ng-enter.ng-enter-active {
opacity:1;
}
And to use that functionality you would have to use ng-repeat in your html, something like this:
<div ng-repeat="item in data" ng-if="index === $index">
//Your question html here
</div>
Where data and index are $scope.data and $scope.index.
That would be the angular way of doing things.
However I see that you are using the same div, only changing scope data, that would require you to set
transition: 1s all ease;
On the question class, and then to do something like this in javascript:
angular.element('.question').css('opacity', 0);
$timeout(function() {
// change question..
angular.element('.question').css('opacity', 1);
}, 1000);
I currently have two Views that are using the same layout. However, they differ from each other in the following aspect:
View Foo:
<div class="MajorSection" id="foo">
</div>
View Bar:
<div class="MajorSection" id="bar">
</div>
And I want to declare #labelWidth differently between these two classes in one .less file so that I don't need to repeat myself with the following code.
.MajorSection {
#labelWidth: 10em;
.editor-label {
width: #labelWidth;
}
input, textarea {
width: (#editorWidth)-(.5em); //border & padding
}
}
In View Foo I want #labelWidth to be 10em, and in Bar I want it to be 20em. Is there anyway to do that?
I think the simplest method to achieve this is to define "depended" styles via parametric mixin, e.g.:
.MajorSection {
#foo& {
.labelStyles(10em);
}
#bar& {
.labelStyles(20em);
}
.labelStyles(#width) {
.editor-label {
width: #width;
}
}
input, textarea {
width: (#editorWidth - .5em); // border & padding
}
}
CSS output:
#foo.MajorSection .editor-label {
width: 10em;
}
#bar.MajorSection .editor-label {
width: 20em;
}
.MajorSection input,
.MajorSection textarea {
width: ...;
}