Nuxtjs/Vuejs CSS styles are conflicting for 2 components - html

I have 2 different components in my Vuejs/Nuxtjs application: pages/Create.vue and pages/Design.vue. I have the stylesheet assets/css/styles.css.
Within the stylesheet styles.css I have a style: overflow:hidden;. This style sheet has been added only to my Design.vue component and not to my Create.vue component. However, I see that this style is impacting my Create.vue without even including it.
If I modify to overflow:auto; then everything works perfectly in Create.vue but Design.vue gets messed up.
I tried following things but still had no luck in making both components work perfectly:
Tried adding <style scoped> to both my Create.vue & Design.vue then also styles in Design.vue is getting messed up.
Tried adding overflow:hidden; to my Create.vue but that's not working either.
Tried adding scoped to both components then also its not working perfectly for me.
Following is the code I have from both components:
styles.css
html,
body {
overflow: hidden;
}
Create.vue:
<template>
<div>
<!-- My code with overflowing the page-->
</div>
</template>
<script>
export default {
}
</script>
<style>
/* OTHER STYLES */
</style>
Design.vue:
<template>
<div>
<!-- My code with overflowing the page-->
</div>
</template>
<script>
export default {
}
</script>
<style>
#import "~/assets/css/styles.css";
/* OTHER STYLES */
</style>

Related

How to select <html> tag in CSS when the source HTML has multiple nested <html> tags?

I'm working on making a dark mode for the Kaplan website tests so I don't blind myself studying.
The following HTML code is representative of the structure of the source, and the tag with id="stylish-23" is what's added by a chrome extension to change the page's CSS styling:
<html> // html 1
<html> // html 2
<html> // html 3
<html> // html 4
<div id="divQuestions"> </div> //actual tag I want to change
</html> // html 4
</html> // html 3
</html> // html 2
<style id="stylish-23" type="text/css">...</style>
</html> // html 1
I put div#divQuestions in the style tag's CSS and it does not appear to have any effect at all. Due to the nature and limitation of the extension, I'm only able to add CSS to the style tag, and the CSS appears to not be able to select HTML tags (or at least when I do, nothing happens). I've noticed that dragging the style tag into html #4 in developer console will properly apply the CSS.
The element in question's CSS from inspect:
My CSS in the style tag:
div#divQuestions {
background: black;
}
Thanks for the help!
#divQuestions selector works for me if I fix the div's closing tag (or even if I don't, as it turns out):
<html>
<html>
<html>
<html>
<div id="divQuestions"> </div>
</html>
</html>
</html>
<style id="stylish-23" type="text/css">
#divQuestions {
padding: 48px;
background: aliceblue;
border: 4px solid blue;
}
</style>
</html>
nth-of-type is a selector that matches the nth element of their "type".
So, you can do this:
html:nth-of-type(1)
html:nth-of-type(2)
html:nth-of-type(3)
...
Or, you can do this since you said "multiple nested tags":
html
html > html
html > html > html
...

How to use the same name classes but in separate styles

see the example to understand:
<!--Standard Bootstrap -->
<link href="/build/css/site/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="/build/css/site/mdb.min.css" rel="stylesheet">
so i want a thing like it:
<div class="btn btn-danger" >Standard Bootstrap Button</div>
<div class="btn btn-danger" >Material Design Bootstrap Button</div>
The name of the classes are the same. But they are in two separate styles.
How can I use the two styles as I said?
Forgive me for the bad English.
You can't, you will allways get the last definition of the class.
This is how style-sheets work, That's why they are called CASCADING Stylesheets. So basically what you define in mdb.min.css extends or overwrites what is definied in bootstrap.min.css And yo will get the combination of both
Let's say in bootstrap.min.css you have this :
btn-danger:{
color:#FF0000;
width:100px;
}
and in mdb.min.cs you have
btn-danger:{
background-color:#00FF00;
width:120px;
}
Your browser will interpret this:
btn-danger:{
color:#FF0000;
background-color:#00FF00;
width:120px;
}
The width will be overwritten by mdb.min.css because that one is added last, the later you add a stylesheet, the more precedence it has, so it will overwrite everything that was defined earlier, and extend everything that hasn't been defined earlier, and merge everything else
If using SCSS is an option, you could create a file that imports the two files but wraps each in its own namespace. Something like:
.bootstrap {
#import 'bootstrap.min.css';
}
.mdb {
#import 'mdb.min.css';
}
This file should go in the same directory as bootstrap.min.css and mdb.min.css and should have a .scss extension. After running the above through an SCSS compiler, you will have one CSS file that you can link to in your HTML file instead of bootstrap.min.css and mdb.min.css. For example, if your new compiled file is named combined.css, then you would replace the link tags in your question with this:
<link href="/build/css/site/combined.css" rel="stylesheet">
You could then use the styles in your HTML like so:
<div class="bootstrap">
<div class="btn btn-danger" >Standard Bootstrap Button</div>
</div>
<div class="mdb">
<div class="btn btn-danger" >Material Design Bootstrap Button</div>
</div>
Note that you must wrap your elements in a DIV (or other element) with a class of bootstrap or mdb to get the intended styling.
Browser's stylesheet
Included by <link> tag
Nested in <head><style> tag
Inline, e.g. <a style="display: none">
That's the order of loading cascading stylesheets in your document. You can extend style of any class in any further place, but cannot define two classes with same name with different styles. It will override in given order.
.btn-danger{
background-color:red;
width:90px;
height:90px;
}
.m1 .btn-danger{
background-color:green;
width:90px;
height:90px;
}
<div class="btn btn-danger" >Standard Bootstrap Button</div>
<div class="m1">
<div class="btn btn-danger" >Material Design Bootstrap Button</div></div>
i think one way is like this, hope this may solve your problem
Using the <style> scoped attribute this is possible, but comes with several caveats.
It currently works only in Firefox
Every other browser will require a polyfill to add support for the scoped attribute - here's one and there are several others available
And even with a polyfill it may not work - I did a few quick experiments with different polyfills and #import but had no luck
The scoped attribute allows CSS within a <style> tag to be scoped to the parent element where the <style> tag is contained. Here's a quick example:
<div>
<style scoped>
p {color: blue;}
</style>
<p>This paragraph is blue.</p>
</div>
<div>
<style scoped>
p {color: red;}
</style>
<p>This paragraph is red.</p>
</div>
Using this, we can replace the CSS selector with an #import to import the Bootstrap CSS in one section and the Material Design Bootstrap in another.
Note: the example below will ONLY work in Firefox as of 07/06/2017.
<div>
<style scoped>
#import url(https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css)
</style>
<div class="btn btn-danger">Standard Bootstrap Button</div>
</div>
<div>
<style scoped>
#import url(https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.min.css)
</style>
<div class="btn btn-danger">Material Design Bootstrap Button</div>
</div>
Here's the result in Firefox
Another downside to this is you'll need to re-#import each stylesheet for each section.
There are several polyfills available to add support for scoped to browsers which currently don't support it. There's also a jQuery script if you're already using jQuery.

Form Field Layout issue with Accordion

I have a form and I'm using CSS to layout the fields on the screen.
This is working as I'd like and can be seen here :
FIDDLE
I'm now trying to apply the same layout to a form within a CSS Accordion layout and it's getting messed up. This FIDDLE shows what going wrong.
This is the HTML I'm using :
<div class='block'><label> Text 1</label><input type="text" name="text1" /></div>
<div class='block'><label> Text 2</label><input type="text" name="text2" /></div>
and the CSS:
div.block {overflow:hidden; }
div.block label {width:325px; display:block; float:left; text-align:left; vertical-align:middle; }
I'm assuming this is messing up as accordion is using the <lable> tag to create the sections.. and I'm using it to layout the fields.
So how do I layout my form fields neatly and keep the accordion working ?
This is the final result I'm after:
Thanks
Some of your form styles are being overridden by the accordion's CSS. Neither have very impressive specificity. You can fix this particular problem by moving your CSS to the end and adding an ancestor selector to increase rank:
.horizontal div.block {
overflow:hidden;
}
.horizontal div.block label {
width:325px;
display:block;
float:left;
text-align:left;
vertical-align:middle;
}
Demo
Updated demo to remove border & background from interior labels.
I haven't added all necessary reset styles on your elements. A better approach might be to add classes to the outer labels, and modify the accordion CSS to target that class, or use a child selector (.horizontal > ul > li > label). That would prevent you from needing to reset so many properties.
A best-practice approach for situations like this is to load a third-party product like this in its own CSS file, along with any others in their respective files, and then load your custom CSS file that includes any overrides. This makes it easier to get your styles to trump the others, which is normally what you'd want.
<link rel="stylesheet" href="accordion.css" />
<link rel="stylesheet" href="menu.css" />
<link rel="stylesheet" href="widget.css" />
<link rel="stylesheet" href="custom.css" />

Blank page in Polymer

I am newbie for polymer. I just tried to add but getting blank screen. Did I missed any script or something?
Head
<script src="bower_components/polymer/polymer.js"></script>
<script src="bower_components/webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="bower_components/core-drawer-panel/core-drawer-panel.html">
body
<core-drawer-panel transition id="core_drawer_panel" touch-action>
<section id="section" drawer></section>
<section id="section1" main></section>
</core-drawer-panel>
<script>
Polymer({
});
</script>
Actually, this is exactly how it should be.
Look in your inspector and you will see that there is a core-drawer-panel element with two section's. The core-drawer-panel doesn't have any visual and is just a container that holds your sub components.
Basically you need to put something in the sections to see something in the browser :)
Add the following to your code:
<style>
core-drawer-panel /deep/ section {
border:1px solid red;
}
</style>
This will visually highlight the sections.

apply an external css file to a scoped div tag?

I have a main css file for the whole site called StyleSheetMain.css. I download a slider that has his own style.css file and there is a conflict on some items.I want to scope the slider's css file only to a div that it will contains only the slider items.I dont want to apply this css outside the slider div.
Any idea?thanksss
There is no such thing as scope in CSS. You can't nest a specific chunk of CSS in other CSS. The below code is WRONG and is just an example of what you CAN'T DO.
.some-class {
/* THIS */
.some-minor-class {
/* IS */
}
/* WRONG */
}
You also can't point certain .css file to work in only a part of html.
Your solution is simple - rename your classes.
There are so many words to describe this world we live in
You can make use of CSS Grouping / Nesting.
for example you have:
<div id="main">
<div id="slider">
</div>
</div>
<div id="newslider">
<div id="slider">
</div>
</div>
for you to change the style for the second slider:
#newslider #slider {
background: #fff;
}