I am using an imported component which I can't change.
This component has a lot of nested divs.
Somewhere deep in these divs, I need to add a bottom margin to it.
Via Chrome DevTools, I am able to add the margin in one of the divs and achieve the
margin I want. But unable to get it to work when I try to add my css into my scss file.
How can I do this?
const MyComponent = props => {
return (
<div>
{/* This component is not in my control. I can't modify this component*/}
<ImportedComponent/>
</div>
);
};
When I see it in Chrome DevTools, the CSS is something like this.
If I were to add a margin style near the aCssClass or within the block of aCssClass via Chrome,
I get the margin I need. But as said, able to achieve in Chrome DevTools, but not via my scss file.
<div class="my-own-class">
<!-- This is all coming from ImportedComponent, each div has some css class -->
<div>
<div>
<div class="aCssClass anotherClass"> <!-- i want to be able to add my margin here, able to do it but only via Chrome dev tools-->
<div>
<div>
Some data
</div>
</div>
</div>
</div>
</div>
</div>
These are the styles I tried which makes no difference.
.my-own-class {
margin-bottom : 1em;
}
.my-own-class > div:nth-child(3) {
margin-bottom : 22px;
}
.my-own-class body .aCssClass {
margin-bottom: 22px;
}
body .aCssClass {
margin-bottom: 22px;
}
body > .aCssClass {
margin-bottom: 22px;
}
.my-own-class .aCssClass {
margin-bottom: 22px;
}
.my-own-class > .aCssClass {
margin-bottom: 22px;
}
Screenshot
At the highlighted portion, I added margin-bottom 10px under body .sc_marginRight_0 on the right panel which works.
i think it's just a specificity problem, try adding !important and it will work just fine.
.my-own-class .aCssClass {
margin-bottom: 22px !important;
}
Related
I decided to try my hand at web design for the first time.
I decided to try out React. Then I found that there is a FontAwesome library for React. Cool! However, my icons are rendering at different sizes on my footer and I have no clue why. I've spent a few days on this and I am out of ideas.
I've tried manipulating the icons using the built-in size prop. I've also tried manually sizing and moving the icons using CSS and that hasn't worked for me, either. Lastly, I've tried changing the icon container to some different tags. I've checked around Stack Overflow, React blogs, and read the FontAwesome API docs to try and find out what I am doing wrong, but I have been unable to find a solution.
It seems to be related to the icon's "path" attribute, but I don't know enough about svg icons to figure out why that is. Can someone please take a look at my code? I'm curious if this is a library issue or an implementation issue (I assume its the latter, as I have no clue what I'm doing).
Here is my footer (icon array passed as a prop to the Footer component from App component):
import React from "react";
import { Container, Row, Col } from "react-bootstrap";
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
const Footer = props => {
return (
<footer className="footer-container">
<Container fluid="true">
<Row>
<Col sm>
<div className="col-left">
<h5>Contact</h5>
<span className="icon-area">
{props.icons.map((icon, index) => (
<a
href={icon.link}
key={index}
// className={`${icon.name}-svg`}
>
<FontAwesomeIcon
key={index}
icon={icon.icon}
color="white"
fixedWidth //I've tried sizes 2x, 3x instead
// className={`${icon.name}-svg`}
/>
</a>
))}
</span>
</div>
</Col>
<Col sm>
<h6>some more stuff will go here</h6>
</Col>
<Col sm>
<h6>and even more stuff here</h6>
</Col>
</Row>
<Row>
<div className="row2-copyright">
<hr />
<h6>© 2020 Copyright Stuff</h6>
</div>
</Row>
</Container>
</footer>
);
};
export default Footer;
And here is my stylesheet (commented out some different things I've tried):
$font: "Roboto";
.footer-container {
position: relative;
bottom: 0;
left: 0;
right: 0;
font-family: $font;
padding-top: 20px;
background-color: #161515;
.col-left {
text-align: center;
color: #fff;
.icon-area {
align-self: center;
display: inline-flex;
padding: 2px;
font-size: 2rem;
// svg {
// width: 28px;
// height: 28px;
// }
// .discord-svg {
// margin-top: 0.2rem;
// }
// .linkedin-svg {
// margin-top: 0.1rem;
// }
// .envelope-svg {
// margin-top: 0.1rem;
// }
}
h5 {
text-transform: uppercase;
font-size: 1.5rem;
}
}
.row2-copyright {
text-align: center;
width: 100%;
color: #fff;
padding: 0.5rem;
h6 {
margin: 0;
}
hr {
background-color: #fff;
}
}
}
And here is my code sandbox.
The anchor tags that contain the icons do have the same width and height (width 40px, height 48px), as well as the font awesome icons (width: 40px, height 32px) so I guess that your problem is the lack of consistency in the eye, since each font awesome icon has a different shape.
If you want to change the size of the icons, you just need to modify font-size, since font awesome elements are actual fonts.
I have edited your code sandbox below (the selected font sizes are an example, you can change them at your own accordance of course). The only things that I have changed are the following:
Removed the font-size property from the .icon-area
Added vertical alignment (center) at the .icon-area (property: align-items)
Added different font-size for each anchor tag so that the font awesome icons would look somehow similar.
Here's the edited sandbox (changes are concerning only the styles.scss file):
I have a div and for some reason I cant reduce its margin.
HTML
<div class="activebombgame">
</div>
CSS
.activebombgame{
height: 82vh;
width: 5vw;
background: black;
margin: 0;
}
This is from google chrome developer tools(blue = div, orange = margin)
Whole source code: https://www.hastebin.com/tapodoyuke.xml
Your code works fine see the fiddle here. Probably a surrounding tag is restricting the resize. Try something like taking ".activebomb" outside like
<div class="sorrounding">
</div>
<div class="activebombgame">
</div>
It sounds like it's your body margin. Many pages have one set by default. See the test below for an example. When you first run it, the body has a default margin. Clicking the button will remove it and line your div up with the page edge.
function change() {
document.body.style.margin = "0px";
}
.activebombgame{
height: 82vh;
width: 5vw;
background: black;
margin: 0px;
}
body {
background-color: lightgray;
}
button {
position: fixed;
left: 40%;
top: 20%;
}
<div class="activebombgame">
</div>
<button onclick='change();'>Remove Body Margin</button>
#Nisarg Shah,
You have added one extra closing div at the end, that's why your css is not working properly. Remove that extra closing div and run it.
I'm building some sort of framework where the content of the page can be edited with ContentTools. A requirement of ContentTools is that the regions must be parents.
If you try this:
<h1 data-editable data-name="heading">Content</h1>
It wont work as a region has to contain editable block level elements. A way around this is to wrap the tag like so:
<div data-editable data-name="heading">
<h1>Content</h1>
</div>
But I just want to make the text editable, so I automatically wrapped the inner elements in a div. This works but it affects the styles.
Is there a way to make a div 'transparent', so it will inherit all styles?
I tried the following code.
To be clear: In this example I don't write the h1 css, so i have no influence over which styles are used.
$("[data-editable]").wrapInner("<div class='innerWrap'></div>");
/* example h1 css, could be anything */
body > h1{
font-size: 40px;
color: red;
font-family: sans-serif;
border: 3px solid green;
background-color: blue;
padding: 5px;
}
.innerWrap{
all: inherit;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 data-editable data-name="heading">Content</h1>
As you can see some things work. But things like a border will double.
It has to be no difference with or without the innerWrap.
Is it possible to do this with css? It has to work on every css property.
I think you need to wrap the h1 with a div not div with h1.
for eg. .wrapInner() will produce something like
<h1 data-editable="" data-name="heading">
<div class="innerWrap">Content</div>
</h1>
But what you want is
<div data-editable data-name="heading">
<h1>Content</h1>
</div>
So please try with .wrap() instead of .wrapInner()
$("[data-editable]").wrap("<div class='innerWrap'></div>");
h1{
font-size: 40px;
color: red;
font-family: sans-serif;
border: 3px solid green;
background-color: blue;
padding: 5px;
}
.innerWrap{
all: inherit;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 data-editable data-name="heading">Content</h1>
.innerWrap{
all: inherit; /* remove it*/
}
As a default behaviour, if you not specify css props for ".innerWrap" it will look same as parent only
The ability to make an individual element editable standalone as opposed to as part of a collection (e.g in a region) is currently being worked on: https://github.com/GetmeUK/ContentTools/issues/79
There is however a short-term imperfect approach you could try, first change you're HTML as follows:
<h1 data-editable data-name="heading">
<span data-inline data-ce-tag="h1">Content</span>
</h1>
This will make the h1 tag the region and tell ContentTools/Edit to treat the inner span element as a h1 (text) element (thanks to the data-ce-tag).
But the next problem is that if the user hit's return you'll end up with a new paragraph tag inside of your h1 - which we don't want. This is where the data-inline attribute comes in, we need to listen for mount events and if the element mounted has the data-inline attribute we'll modify its behaviour so it can't do certain things which might produce undesirable events:
ContentEdit.Root.get().bind('mount', function(elem) {
// We're only interested in elements that are marked as inline
if (elem.attr('data-inline') === undefined) {
return;
}
// Change the default behaviour of the element
elem.can('drag', false);
elem.can('drop', false);
elem.can('remove', false);
elem.can('spawn', false);
});
You can find out more about modifying behaviours here, along with their current limitations here.
I'm trying to remove the margin-left on http://insightcxo.com/epicwin/
The problem is when I target the class .container, it shifts the whole website over - I only want to target the div on the specific page.
This is the code I'm using that makes the page work but shifts the whole website over as well:
.container {
margin-left: 0;
}
Most WordPress themes (including yours) include the page ID as a body class name. In this case, the <body> tag looks like the following:
<body class="page page-id-731 page-template-default page-shadow responsive-fluid ">
This means that you can target this page via:
.page-id-731 .container {
margin-left: 0;
}
More about WordPress's body_class() function can be found in the Codex.
As per the page you are linking, it seems you are using an page-id as a class in your body, so this might work:
.page-id-731 .container {
margin-left: 0;
}
I am not sure if I understand completely, but I think what you need to do is add an id to the div you want to target.
Here is a JSFiddle of what I mean:
https://jsfiddle.net/dT9Yk/25/
HTML:
<div class="div1"></div><br>
<div class="div1" id="marginleft"></div><br>
<div class="div1"></div><br>
CSS:
.div1 {
width: 100%;
height: 50px;
background: red;
}
#marginleft{
margin-left:10%;
}
As you can see they all have the same class name but the middle one has an additional id tag.
Add a class to the body on that page only and then use specificity to target the container on only that page. For instance, add body class epicwin on that page and then use
.epicwin .container {
margin-left:0;
}
to target it.
Adding margin-left: 0px; to your CSS file is conflicting with the default .container class of bootstrap.
To fix your issue apply the class directly inline, it will solve your issue, like so:
<div class="container" style="margin-left: 0px;">
You can create something like this in the stylesheet you are using:
.Container_Div { padding: 0px 0px 0px 0px;}
Add this to your HTML:
div class="Container_Div"
Try this and let me know.
You can target a div with class/id .you can target directly or with reference of parents div class/id as follow.
<div class="parent">
<div class="child"></div>
</div>
direct target
.child{}
with reference to parent div .It will only apply style to class/id that exist in parent with specific id/class
.parent .class{
}
I'm trying to create a HTML widget:
HTML:
<div>
<h1 class="title" data-bind="title">Title</h1>
<div>
<h1 id = "dc1" class="dc">DC1</h1>
</div>
<div>
<h1 id = "dc2" class="dc">DC2</h1>
</div>
<p class="updated-at" data-bind="updatedAtMessage"></p>
</div>
And I need to be able to set the background color of the id="dc1" and id="dc2" elements dynamically in CoffeeScript. I plan to do this by adding a class with a background color setting:
SCSS:
&.up {
background-color: green;
}
&.down {
background-color: red;
}
.dc {
background-color: orange;
font-size: 30px;
float: left;
width: 50%;
}
So far I have managed to set the whole widget background but not the child elements mentioned above:
I have been using:
CoffeeScript:
$(#node).removeClass('up down')
$('#dc1').removeClass('up down')
$('#dc2').removeClass('up down')
$(#node).addClass('down')
$('#dc1').addClass('down')
$('#dc2').addClass('up')
Note ultimately I will add the classes depending on some data rather than hard coding them to 'up' or 'down' in the coffeescript.
But nothing happends.. Am I getting selecting the id="dc#" elements correctly?
If it helps with context I'm doing this for Dashing
Your SCSS doesn't make sense so I'd guess that your missing an error from the SCSS-to-CSS conversion. An & in SCSS is a reference to the parent selector:
& will be replaced with the parent selector as it appears in the CSS
so have &.up at the top level makes no sense and should generate an error. If we fix the SCSS so that .up and .down apply only to .dc:
.dc {
/* ... */
&.up {
background-color: green;
}
&.down {
background-color: red;
}
}
then everything seems to work just fine.
Demo: http://jsfiddle.net/ambiguous/9y9uywm9/
You can use Sassmeister (and other similar online tools) to see what SCSS thinks of your original SCSS.