Create two divisions in a section - html

I want to create a two box of white background in which one box consists of user login and other box with professional login.
I dont know the policy of section and div's, I tried alot but I am not getting it right
EDIT:I want to make the design responsive
html code:
<section class=wrapper-box>
<div class="001">
<!--<i class="material-icons md-48 md-light">person_outline</i>-->
</div>
<div class="002">
</div>
</section>
I want to make something like this :
How do I create two such filled boxes?

A class name should not start with a digit. A quick test shows that those names are actually problematic: while the divs themselves don't suffer, styles applied to them via .001 and .002 are not rendered.
So the solution is to give them class names starting with a letter.
Example:
.C001 {
border: 2px solid #BBB;
display: inline-block;
margin: 1em;
width:100px; height:100px;
}
.002 {
border: 2px solid #BBB;
display: inline-block;
margin: 1em;
width:100px; height:100px;
}
<section class=wrapper-box>
<div class="C001">
<!--<i class="material-icons md-48 md-light">person_outline</i>-->
one
</div>
<div class="002">
two
</div>
</section>
As you can see, only the div where I put a C in front of the class actually gets the styles.
Edit:
The W3C page on CSS selectors says,
In CSS1, a class name could start with a digit (".55ft"), unless it was a dimension (".55in"). In CSS2, such classes are parsed as unknown dimensions (to allow for future additions of new units). To make ".55ft" a valid class, CSS2 requires the first digit to be escaped (".\35 5ft")
so apparently, other than changing the class names, the other solution is to write the css selector like this: \30 01
In addition, another quick and dirty test shows that you can also write [class~='001'] for a selector.
I can't really recommend those methods though. Too hacky. Best stick with starting with a letter.

Related

Is it better to use a div or style content elements when dividing a section on the page? [duplicate]

This question already has answers here:
Are empty divs bad?
(6 answers)
Closed 3 years ago.
We were in a code review and were looking at the following mark up that essentially had a border to split up some content above with the title below:
<div class="divider"></div>
<h3>Title</h3>
We were told that this is super bad practice and that instead you should style the h3 element with a border top to avoid divitis. Is this true? I understand not wanting to fill your markup with tons and tons of divs, however, in this instance I don't see much of a problem. Also, in this instance, to get the same design there was more lines of css needed on the h3 than the original divider class. So although you save markup, you are not saving styles. Another option is to wrap the h3 in the div so there is no empty markup. In the end I feel as though it is just preference?
Thoughts?
Depending on your page layout. In general, an blank element does not cause divitis:
<div class="divider"></div>
<h3>Title</h3>
so that in many front-end frameworks these types of elements are embedded by system by default.
finally, It depends on the structure of your page and the purpose of the pages and software.
This can be seen from different angles:
If your design is such that you use dividers in addition to the titles elsewhere, it is best to use the following structure, as this will keep your hand open:
<hr class="divider">
<h3>Title</h3>
But if these dividers are limited to titles only and not used elsewhere, you can use a structure like this:
<h3 class="border-top"></h3>
<h5 class="border-bottom"></h5>
and
.border-top {
border-top: 1px solid black;
}
.border-bottom {
border-bottom: 1px solid black;
}
Using something like this is a Bad Practice and I strongly believe in that.
HTML already has a built-in horizontal divider called <hr/> (short for "horizontal rule"). Bootstrap styles it like this:
hr {
margin-top: 1rem;
margin-bottom: 1rem;
border: 0;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
You Can customize it and use it wherever you want according to your needs.
This really depends on if you are using a CSS framework / library and if you will be working with a team. You need to write understandable and predictable code that the rest of the team will be able to pick up and work on. If <div class="divider"></div> is the standard way per the framework then I would continue to use that.
I also would not consider this "divitis" as that usually refers to a large number of nested <div> elements. Such as
<div class="foo">
<div class="bar">
<div class="baz">
etc...
EDIT: As others have mentioned, which I should have included, is that in cases other than where a framework and / or team are involved, it is generally considered bad practice to not use the spec element. In this case <hr />

Creating a styled button representation (not an actual button) with css

I have an application that has a lot of buttons in the window. In writing the HTML documentation pages for this, I've been successful in creating a bordered, sorta-shadowed CSS <span> with text within that represent the buttons that just have legends on them.
This allows me to show "momentary" buttons like these...
...that just have a legend on them in such a way that it's reasonably obvious what I'm describing by simply putting...
<span id="button">LAP</span>
...in line with the associated description (and my custom documentation system makes it even easier by letting me invoke the style inline with [s button LAP]. Fun. :) Here's the style I built for that:
span#button
{
font-family: Courier;
font-weight: bold;
white-space: pre;
border: 1px solid #000000;
background: #ddddee;
padding-left: 2px;
padding-right: 2px;
color: #000000;
}
Here's screen clip of part of the documentation that uses that technique:
Also within the application, I have buttons that have "LED" indicators on them. A typical one might display a green LED when on, and a dark LED when off. Screen clip from the application (with a dark style sheet, so the buttons are dark) showing some of these:
I already have nice little .jpg images that show all the "LED" colors I use, conversely, an embedded CCSS box filled with the right color would be fine too.
What I would like to do, and am having no luck at all doing, is create a <span> within the text that looks as least somewhat like one of those buttons -- without going to specific images for each button, or in other words, using CSS. Since the only things that vary are the LEDs and the text, I want to can the LEDs and feed in the text. Something like...
<span id="greenbutton">Run</span>
In order to do that, I need the LED to appear above the text, and size the text small enough to land underneath it, and center them both within a bordered box as the text-only version above does. I would like an output like this (button built in an image processor)...
press to start
...from this:
press <span id="greenbutton">RUN</span> to start
It seems like it ought to be easy enough; and I can add quite a bit of complexity within my documentation system if required to make it all work -- multiple nested spans, divs, images, test, whatever it takes -- but I keep running into these two showstoppers:
<span> wants things to come one after another horizontally
<div> either causes line breaks or floats left or right
I can't seem to get a <div> to just land in the text where I put it in the first place, although I've been able to make them look just like I want them to because they understand vertical alignment and positioning withing their own context.
I was also thinking of some actual images of buttons with the text removed from them in each LED state, used as background to a span, where the text is overlaid on that background, thereby looking like a specific button. I've not tried this, as I can't seem to find how to make a span have a background and <div>... a <div> won't stay where I want it (not left or right, but right there, or else refrain from breaking the lines if it's not floated.
I'm not opposed to putting a table inline, either. If I knew how...
I hope I'm missing something. In which case, help! Or is this impossible, and the only solution is to screen-cap the many, many buttons in each of their various states (some actually display multiple LED colors for various settings, worse yet) and then drop the images in where I want them? Because although I could do that, it's awfully clumsy and effort intensive. :(
Introducing the pseudo element "before"! Ta-da!
<p>Green button</p>
<span class="myButton greenbutton">RUN</span>
<p>Red button</p>
<span class="myButton redbutton">RUN</span>
<p>Click this purple button <span class="myButton purplebutton">RUN</span> here.</p>
<style>
span.myButton {
display:inline-block;
border-top: 2px solid #eee;
border-left: 2px solid #eee;
border-right: 2px solid #000;
border-bottom: 2px solid #000;
padding:1px 2px 0;
background: #dde;
width:20px;
height:auto;
font-size:10px;
font-family:monospace;
text-align:center;
}
span.myButton:before {
display:block;
margin:2px auto 0;
width: 16px;
height: 5px;
border: 1px solid #000;
content: "";
}
span.greenbutton:before {background:#99FF00;}
span.redbutton:before {background:#FF0043;}
span.purplebutton:before {background:#A200C1;}
</style>
Updated answer: I changed the display on the span to inline-block, so it will go inside a paragraph. I missed that requirement on my previous answer.
I added a class to each span, so that all spans in your document won't be affected, just the ones with that class.
Technically, if you are going to have more than one green button, you shouldn't use an ID for it. ID's are supposed to be unique and therefore only used once in a document. So I've also converted that to a class.
in CSS, the period denotes a class, as opposed to the # sign denoting an id. Ergo: span.myButton targets the span with class "myButton". span.greenbutton targets a span with the class greenbutton. You can have more than one class on an element.
I took the background-color property out of the span:before style, and put it in a class specific style -> span.greenbutton:before. Basically, the classes for the span.myButton and the pseudo element span.myButton:before are the same for all these buttons. But for each color, put an additional class on the span, and create a style with that class for it, using the background color you want. Hope that's clear. Fiddle updated too.
https://jsfiddle.net/maguijo/05zwwjy6/

extending <a> elements to extend gradient nav bar to end of page

I'm creating a site with a horizontal navbar in which the buttons are designed as elements, making them easy to differentiate, and they individually light up when you a:hover over them. Here's a link: http://allpropestmanagement.net/commercial2.html
Obviously not a finished product.
My current problem involves that big purple field on the far right of the navbar, the one that's not a button. That too is an element, but with hover disabled and a whole load of nonbreaking spaces to pad it. That's the problem. I would like that purple field to extend all the way to the right end (with a tiny margin, like it does on the left side). The trouble with nbsp, as you can imagine, is that there's a finite number of them, and they don't scale. So if the navbar is the perfect length on my computer with, say, 16 nbsps, on someone else's machine it won't reach all the way and on yet another person's it will reach too far.
The html looks like this:
<div id="navmenu">
<form>
Home
Commercial
Meet The Pro
Contact
<a id="farright" style="border-top-right-radius:25px;">
<i> "We'll get the job done right!"
</i></a>
</form>
</div>
I feel odd saying this, but the css is kind of bulky and I'm having trouble formatting this post. Perhaps I'll add it in a few minutes once this post is visible, but the css file is "smithmicropurple.css".
Anyway, I would like a way to stretch that element so it always fits correctly, or if not, some other method that achieves the same effect. I have already tried setting widths individually for each element and that doesn't appear to work.
I like to do these types of things to "help" others (rarely, if I'm lucky), but also to help me learn more about html/css.
So I've given it the old college try with this FIDDLE.
HTML
<div class='holderdiv'>
<a href='#'>One</a>
<a href='#'>Two</a>
<a href='#'>Three</a>
<a href='#'>Four</a>
<a href='#'>We'll Get the Job Done Right!</a>
</div>
I won't post the CSS because it's pretty long. It's in the fiddle.
Please don't consider this a "real" answer. Perhaps just something to think about.
Semantically, I am not sure why the parent is a form element, i'd suggest changing that to a HTML5 <nav> element. (assuming you're using HTML5, of course)
The approach taken here is to set the child elements to display:table-cell, and give the targeted element, #farright a width of 100% to fill the remaining space. Also, text-align:center will effectively center all the child elements. No need for %nbsp;
#navmenu {
font-size: 14pt;
margin: 5px 0 0 5px;
}
#navmenu form {
width: 940px;
}
#navmenu form > a {
display: table-cell;
white-space: nowrap;
text-align:center;
}
#navmenu #farright {
width:100%;
}

Any way to access the first element after each wrap in a flexbox?

I have a dynamic form of sorts that I'm laying out with a css flexbox. I'm using flex because I don't know until runtime how many or what type/width the components are in the form. I'd prefer for the first "column" to have left-aligned labels and every subsequent column to have right-aligned ones, but I can't really think of any way to do this. Any suggestions?
Basic example of this form (with everything right-aligned). Be sure to pull the divider left to make the rendered output as large as possible to see what the form looks like with more than just one column: http://jsfiddle.net/27Gfd/
//basic markup for one form component (called a row). See JS fiddle for more
<div class="container">
<div class="row"> //I might stack next to another "row" because I have fixed width based on component type
<div class="miniflex"> //I'm another flex container to layout label/input
<div class="label">Label 1</div>
<div class="input">
<input type="text" />
</div>
</div>
</div>
at the moment no, you can't
example pseudo code (just an idea, it doesn't work!)
.flexContainer::first-flex-line > div {}
.flexContainer::last-flex-line > div {}
.flexContainer::nth-flex-line(odd) {}
.flexContainer::nth-flex-line(3n+1) {}
this doesn't exist yet for a precise reason
.flexContainer::nth-flex-line(3n+1) > div {width:100%}
changing the size of the flex-items may affect the container's wrapping. so that's a circular loop. not a nice thing! :P
if you can think of a solution and you want it implemented you could ask to the CSSWG using the newsgroup, or even on chrome's and firefox's bug trackers
Change the css:
.ex3 .label{
text-align: right;
/* ... */
}
to:
.ex3 .label{
text-align: left;
/* ... */
}
Or, if you're not certain that the first column is a label, use:
.miniflex div:first-child {
text-align: left !important;
}
(You should probably avoid using !important but I can't offer a precise alternative without knowing the logic behind the markup.)
Or if you might have labels in places other than the first column
.ex3 .label:first-child {
text-align: left;
}

How to represent "A" class if "B" class is present

I am wondering if there is a way to represent class A if class B is present. In my case I want "container_inner2" to have a padding of 0px if "promo_move" is there.
I know there are combinators to represent class B if A is present, but I can't figure out if want I need is possible.
Here's the HTML and the current CSS -
HTML
<div class="container_inner">
<div class="container_inner2 clearfix">
<div class="promo_move">
Some content....
</div>
</div>
</div>
CURRENT CSS
.container_inner .container_inner2 {
padding: 30px;
}
Again, I would like container_inner and container_inner2 to have 0 padding if promo_move is there.
If this isn't possible with css, any other solutions are welcome. (This is on a Wordpress site. All pages can have the 30px padding except one.)
Thank you for your time.
Your description is very misleading. You mean that you want to style the .container_inner and .container_inner2 elements if they both have a .promo_move descendant.
That is not possible with CSS. Since this is on a WordPress site, you can use jQuery's .has() function to filter the elements before you decide whether to apply the padding, like so:
$('.container_inner, .container_inner2').has('.promo_move').css('padding', 0);