im using the BEM naming convention within a small project and having some slight difficulty in deciding between element and modifier names.
I'm currently working on a hero/splash section of the website. see image below.
Heres my current code -
<div class="hero hero__project">
<div class="grid">
<h1 class="hero__project__title">Final Year Project</h1>
<div class="hero__project__meta">
<p>Published<span>23 Oct 2014</span></p>
<p>Applictions <span>Unity3d, Photoshop, 3ds max</span></p>
</div>
<p class="hero__project__summary">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in </p>
</div>
</div>
My question is - Do you understand what the piece of markup is doing? and is it in line with them BEM methodology. Thanks
As far as I understand BEM, I would say your naming does not make sense. Your Block (or module) would be your .hero. Your Elements would be your main components of your block (i.e. project-title, project-meta, etc). If you needed a modifier on your block for a different state, you could add one in addition to your block (e.g. class=".hero .hero--isHidden)
<div class="hero">
<div class="grid">
<h1 class="hero__project-title"></h1>
<div class="hero__project-meta"></div>
<p class="hero__project-summary"></p>
</div>
</div>
For more in-depth info checkout http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/
To answer your question regarding the other names, I guess I would modify my answer slightly. Again, only using the --project modifier to style the other elements if they are indeed different than a hero on another page.
<div class="hero hero--project">
<div class="grid">
<h1 class="hero__title"></h1>
<div class="hero__meta"></div>
<p class="hero__summary"></p>
</div>
</div>
I'm new to BEM and trying to wrap my head around it all. I read one of the rules for BEM was no nested selectors. So based off the 2nd answer, let's say we style the hero title to be black but style project hero titles to be red. Would the CSS look like this?
.hero__title { color: #000; }
.hero--project .hero__title { color: #cc0000; }
Related
I'm new on programing and I'm studying HTML and CSS.
But today I have a issue that I can't figure how to solve:
I'm trying to add a background to a footer and it work pretty nice. But when I add "columns class" in some 'divs' it jusp stop works.
I'm adding two JS, first one whitout columns' class and a seccond one whit columns' class.
I know I'm doing something wrong, but I can't figure what.
First Code whit background working perfectly
Seccond Code whit background does't work
And I'm puting here my HTML code:
<footer>
<div class="footer">
<div class="container">
<div class="six columns">
<h3>Nossa História</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="three columns">
<h3>Contato</h3>
<ul>
<li>- 38 99999-9999</li>
<li>- contato#bikcraft.com</li>
<li>- Salinas - MG</li>
</ul>
</div>
<div class="three columns">
<h3>Redes Sociais</h3>
<ul>
<li><img src="img/facebook-icone.svg" alt="Ícone Facebook"></li>
<li><img src="img/instagram-icone.svg" alt="Ícone Instagram"></li>
<li><img src="img/youtube-icone.svg" alt="Ícone Youtube"></li>
</ul>
</div>
</div>
</div>
</footer>
And my CSS code:
.footer {
color: #fefefd;
background: #191f28;
}
This question already has an answer here:
Media query in responsive email template
(1 answer)
Closed 3 years ago.
I'm setting up an email which contains in the body a picture and some text. On normal computer screens the image is to the left and the the associated text to the right (using inline-block).
This looks like so:
(https://www.flickr.com/photos/183424995#N08/48518551371/in/dateposted-public/)
When the screen size is changed ie. for an i-phone, I'm aiming to get the text to move underneath the image and rather than just having a width of half the screen (as it's inline-block), to take up the whole width of the screen underneath.
What I'm trying to get:
https://www.flickr.com/photos/183424995#N08/48518549646/in/dateposted-public/
What is actually happening:
https://www.flickr.com/photos/183424995#N08/48518724692/in/dateposted-public/
I've created a "main" div containing the image div, and a div containing the text, both inline-block. The "main" div has a width set to 100% and the text div has a min and a max div so it can move from next to the image to under the image depending on screen width.
I've tried rejigging the max width of the text div to be wider, but then the text never remains to the side of the image. And I'm trying to avoid floating anything.
I can't use bootstrap or flexbox as it's an email so am limited to fairly basic CSS.
The JSFiddle is https://jsfiddle.net/cfn76vqz/ to show what kind of responsiveness I have so far. And the general HTML structure is as below.
<div id="main">
<div id="left">
<div >
<img src="https://via.placeholder.com/300x200/0000FF/FFFFF" />
</div>
</div>
<div id="right">
<div >
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</span>
</div>
</div>
</div>
TLDR: I'm stumped on how to make the text div essentially be 100% of the width if underneath the image but also 50% if there's space to have it to the side of the image. As far as I understand it's always going to be limited to 50% as it's part of an inline-block section.
Because you set width with this why it's not fully of width
max-width: 50%;
So... How we can do
We need to use FLEX display
like this
#main {
/*---HERE---*/
display: flex;
flex-wrap: wrap;
/*----------*/
background: yellow;
width: 100%;
}
#left {
background: orange;
}
#right {
/*---HERE---*/
flex-basis: 0;
flex-grow: 1;
min-width: 50%;
/*----------*/
background: green;
vertical-align: top;
}
<!-- YOUR OLD CODE -->
<div id="main">
<div id="left">
<div>
<img src="https://via.placeholder.com/300x200/0000FF/FFFFF" />
</div>
</div>
<div id="right">
<div>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</span>
</div>
</div>
</div>
if you want to learn about flex ...more here
you can use viewport units like width: 100vw and height: 100vh for make it responsive depending upon height and width of display.click here
I am a newbie in terms of web design.
I have centered an image, put a button below it, and when I click this button, some text appears below the image. When I click the button again, the text goes up, and so we see the initial view: only the image and the button (similar to the effect here https://www.w3schools.com/bootstrap4/bootstrap_collapse.asp) .
<div class="container">
<h2>Simple Collapsible</h2>
<p>Click on the button to toggle between showing and hiding content.</p>
<button type="button" class="btn btn-primary" data-toggle="collapse" data-target="#demo">Simple collapsible</button>
<div id="demo" class="collapse">
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
Now, I don't want to make this text appear under the image, I want the image to move left and the text to appear on where the image was before when clicking that button, even a little bit more on the right, but still on the same line.
Can someone please help me doing this? Thank you!
Bootstrap doesn't have a pre-fab method to do what you want, and you cannot tweak the collapse method to do it.
However, what you want to do can be easily done within the Bootstrap grid system - just not with pre-fab Bootstrap tools.
Here's how that might look:
$('.btn').click(function(){
$('.imgDiv').animate({
width: '0px'
},1000, function(){
$('img').css('width','0px');
});
$('.txtDiv').animate({
width: '90vw',
marginLeft: '10vw'
},1000, function(){
$(this).removeClass('hidden');
});
});
.full-width {width:100vw;}
.imgDiv{min-height:110px;}
/* max-height required so zero-width does not auto-expand height */
.hidden{width:0px;max-height:100px;overflow:hidden;}
<div class="container">
<div class="row flex-nowrap">
<div class="imgDiv text-center full-width">
<img src="http://placekitten.com/100/100" />
</div><!-- .imgDiv -->
<div class="txtDiv hidden">
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div><!-- .txtDiv -->
</div><!-- .row -->
<div class="row d-flex justify-content-center">
<button type="button" class="btn btn-primary">Show Text</button>
</div><!-- .row -->
</div><!-- .container -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
Because Bootstrap4 is built on flexbox (in fact, the entire Bootstrap grid was redesigned around flexbox in Bootstrap4) it is important to know some Bootstrap flexbox classes.
There is a reason why Bootstrap re-did their entire platform from Bootstrap3 to Bootstrap4, primarily to change from using floats to flexbox.
Flexbox requires two things:
A parent container (e.g. DIV, section, aside, p, etc)
One or more child elements (e.g. div, p, img, etc)
You turn flexbox on on the parent: display:flex;
Then, there are various switches. Some are set on the parent (as in the case of justify-content) but others might be set on the items (as with flex-grow:1)
YouTube tutorial - fast-paced and best-of-breed
Here is a great cheatsheet for Flexbox.
Watch the tutorial and in 40 mins from now your problem will be solved -- and you'll know flexbox.
P.S. I have no connection to the video or its presenter - I was fortunate to discover it, and now pass it along.
I'm using HTML5's Summary/Details tags to hide/show extra text on a documentation page. The extra text is lengthy and the open/close nature of the summary tag is that you have to click on the summary line to make it both open and close the details block. This means that after scrolling down through the length of the long text you must scroll back up to the summary tag in order to click to close it.
I would like to be able to click on the bottom of the details segment to close it. Using CSS, I am able to add a 'close' triangle at the bottom of the detail segment. What can be done (preferably in CSS) to cause a click on the triangle to close the detail block?
details[open]:after {
content:'▲';
}
Below is a CSS only solution, just use ::after on <summary> and absolute positioning.
details.test {
position: relative;
padding: 5px 0;
}
details.test[open]>summary::after {
display: inline-block;
content: "close";
position: absolute;
right: 0;
bottom: 0;
}
<details class="test">
<summary>Example</summary>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</p>
</details>
I don't think it can be done using CSS. But you can use javascript:
<!DOCTYPE html>
<html>
<body>
<script>
function closeDetails() {
document.getElementById("details").removeAttribute("open");
window.location = "#details";
}
</script>
<details id="details">
<summary>Show Details</summary>
<p>yadda yadda</p>
<button onclick="closeDetails()">Close Details</button>
</details>
</body>
</html>
Since there were no other answers I’ll mark Sartoris’ as the correct one.
In case anyone else wants to use to it, I took the liberty of embellishing it a bit so that it would work with more than one ‘details’ element on a page and be a bit more generic. In this way the same function and close button definition can be used for all ‘details’ blocks as long as each has a unique ID.
<!DOCTYPE html>
<html>
<body>
<script>
function closeDetail(detailsElement) {
detailsElement.removeAttribute("open");
window.location = '#' + detailsElement.id;
}
</script>
<details id="details">
<summary>Show Details</summary>
<p>yadda yadda</p>
<button onclick="closeDetail(this.parentElement)">▲</button>
</details>
</body>
</html>
.rounded-box(#border; #radius; #bg-color: transparent; #padding: 5px 10px) {
border:1px solid #border;
.border-top-radius(#radius);
.border-bottom-radius(#radius);
.border-left-radius(#radius);
.border-right-radius(#radius);
background-color: #bg-color;
padding: #padding;
}
I have a mixin creating a rounded corner box, in the screenshot below, you can see that it does not have any spacing between each div, which has .make-column(4) applied to each.
*I do include the bootstrap.less into my main less file and run lessc to compile and this is in the screen shot you see is over 990px wide. Any help is appreciated.
#rounded-box-radius: 10px;
#rounded-box-border: #ccc;
#rounded-box-height:230px;
#box-bg-color: #eee;
.article {
.make-column(4);
}
.promo {
.make-column(4);
.visible-lg;
.rounded-box(#rounded-box-border, #rounded-box-radius);
height: #rounded-box-height;
} // promo end
HTML
<div class="promo">
Promo
</div>
<div class="article">
<h3>Blog Entry 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor.</p>
<div class="date">March 23, 2013</div>
<div class="read-more">Read more</div>
</div>
<div class="promo">
Promo
</div>
I think bootstrap 3 uses padding for column separation instead of margins. Your border wraps around the entire element, including the padding. You may need supply your own margin rules for column separation instead of padding to get bordered boxes with separation between them.
#jtlowe is right in https://stackoverflow.com/a/18127896/1596547 about the padding. But applying margin rules on your columns will break the grid (due to margins adds up with the width).
Use an extra container, just like here: need spacing between divs using twitter bootstrap v3 (duplicate??)
html
<div class="promo">
<div class="rounded-box">Promo</div>
</div>
less
.rounded-box(#border; #radius; #bg-color: transparent; #margin: 5px 10px) {
border:1px solid #border;
.border-top-radius(#radius);
.border-bottom-radius(#radius);
.border-left-radius(#radius);
.border-right-radius(#radius);
background-color: #bg-color;
margin: #margin;
height:#rounded-box-height;
}
NOTE apply the height (#rounded-box-height) here and replace the padding with margin