align equal column without using table - html

I have li like this
<li>0 - 10 Years old</li>
<li>11 - 20 Years old</li>
They have different lengths. I want to center 2 column each row and align them left. But my attempt is not perfect, due to different length they aren't align left equally.
I thought of using table but what's a modern solution? Note that I didn't use any css framework for this.
https://jsfiddle.net/coeh77Lp/

Just update CSS in your fiddle to
https://jsfiddle.net/coeh77Lp/3/
ul {
width: 400px;
column-count: 2;
column-gap: 10px;
}

You can use a fixed width for the li:
https://jsfiddle.net/w25m1a81/1/

You could set the float property of each selected <li> as left or right.
Also remember to specify nth-child(2n-1) property to give a table like alignment.
.li{
float: left;
}
li:nth-child(2n){
float right
}
also display: inline-block can be use:
.li{
display: inline-block;
width: 150px;
height: 75px;
margin: 10px;
}
Also providing fixed width, height and margin for the container will improve the alignment

There are some adjustments we should go through so you understand how to achieve the solution you want:
Avoid inline css styles like on the <ul>
Mixing list markup with a lot of other elements can create chaotic code very fast, lets rename all <li> to <div>.
Next we want to wrap all the numeric vales in a container too, because then we have more control over the layout: e.g. <span class="numerics">51 - 60</span>
Now we build up our flexible grid system. We can use the .customLegend containers for this but I would recommend to add a new class for columns so you can separate your individual styles from those for the layout. https://www.sitepoint.com/understanding-css-grid-systems/
I added some styles for free, you can go though the css. I created a jsfiddle too if you want to try further adjustments on your own: https://jsfiddle.net/coeh77Lp/2/
.customLegend {
float: left;
width: 50%;
max-width: 170px; /* stack up cols if there is enough space */
margin-bottom: 5px;
}
.customLegend .symbol {
background: #333333;
display: inline-block;
width: 10px;
height: 10px;
border-radius: 5px;
margin-right: 3px;
}
.numerics {
text-align: right; /* better readability */
min-width: 50px;
display: inline-block;
padding: 2px 4px 2px 2px;
margin-right: 2px;
border-bottom: 2px solid #ddd;
}
.customLegend .label {
display: inline-block;
margin-right: 20px;
}
<div class="customLegend">
<span class="symbol" style="background: rgb(51, 51, 51);"></span>
<div class="label"><span class="numerics">0 - 10</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: rgb(102, 102, 102);"></span>
<div class="label"><span class="numerics">11 - 20</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: rgb(153, 153, 153);"></span>
<div class="label"><span class="numerics">21 - 30</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: rgb(221, 221, 221);"></span>
<div class="label"><span class="numerics">31 - 40</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: rgb(238, 238, 238);"></span>
<div class="label"><span class="numerics">41 - 50</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: red;"></span>
<div class="label"><span class="numerics">51 - 60</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: blue;"></span>
<div class="label"><span class="numerics">61 - 70</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: pink;"></span>
<div class="label"><span class="numerics">71 - 80</span> Years old</div>
</div>
<div class="customLegend">
<span class="symbol" style="background: green;"></span>
<div class="label"><span class="numerics">81 - 0</span> Years old</div>
</div>

Related

How to use :nth-child for alternate rows [duplicate]

This question already has answers here:
How can I style even and odd elements?
(9 answers)
Closed 3 years ago.
I want to style my accordion with border-top and border-bottom for even number of rows Ex: 2, 4 ,6 etc.
I tried with :nth-child but it is not reflecting my parent div but it is reflecting my child element.
code
<div className="accordion" id="adsdfsdf">
<div className="accordionitem">
<div className="accordion-card">
<div className="accordion-card-header" id="aada">
<h3 className="mb-0 w-100">
<a
className="collapsed"
role="button"
>
<span className="icon-left">
<i className=" a-minus" />
<i className="a-plus" />
</span>
</a>
</h3>
</div>
</div>
</div>
<div className="accordion" id="adsdfsdf">
<div className="accordionitem">
<div className="accordion-card">
<div className="accordion-card-header" id="aada">
<h3 className="mb-0 w-100">
<a
className="collapsed"
role="button"
>
<span className="icon-left">
<i className=" a-minus" />
<i className="a-plus" />
</span>
</a>
</h3>
</div>
</div>
</div>
css
.accordion-card-header {
boder-top: 1px solid red;
border-bottom: 1px solid red;
}
You are almost there. you need to use :nth-child(even) to style even rows and :nth-child(odd) to style odd rows. For the further reference you can go through nth-child() Selector
Here is a small demo
div:nth-child(odd) {
height: 100px;
width: 100px;
background: yellow;
margin: 20px auto;
}
div:nth-child(even) {
height: 100px;
width: 100px;
background: green;
border-top: 5px solid black;
border-bottom: 5px solid red;
margin: 20px auto;
}
<div>odd</div>
<div>even</div>
<div>odd</div>
<div>even</div>

How do I get a DIV box to fill the webpage and not go to the left?

I have a client's website that I am trying to fix... The booking page should have the address on the left and the contact form on the right and the white box should fill the webpage.
At the moment, the DIV box just aligns to the left and this means that the contact form and address are squashed together. What can I do? Here is the webpage
.box {
background-color: white; /* for visualization purposes */
display: inline-block;
max-width: 100%;
}
.box2 {
display: inline-block;
padding: 20px 20px;
max-width: 100%;
}
<div class="content">
<div class="wrap">
<div class="contact">
<h1>Book an Appointment Online or via Telephone/Email:</h1>
<div class="section group contact1">
<div class="col span_1_of_3">
<div class="company_address">
<h3>Company Information:</h3>
<p>BY APPOINTMENT ONLY</p>
<p>Imani Skin Clinic,</p>
<p>8-10 Sneyd Street</p>
<p>Cobridge</p>
<p>ST6 2NZ</p>
<p>United Kingdom</p>
<p>Phone:+447305585588</p>
<p>Email: <span>info#imaniskinclinic.com</span></p>
<br />
<br />
<div id="share-buttons">
<!-- Twitter -->
<a href="https://twitter.com/imaniskinclinic" target="_blank">
<img src="https://simplesharebuttons.com/images/somacro/twitter.png" alt="Twitter" />
</a>
<!-- Facebook -->
<a href="http://www.facebook.com/imaniskinclinic" target="_blank">
<img src="https://simplesharebuttons.com/images/somacro/facebook.png" alt="Facebook" />
</a>
<!-- Instagram -->
<a href="http://www.instagram.com/imaniskinclinic" target="_blank">
<img src="images/insta.jpg" alt="Instagram" />
</a>
</div>
<br />
<br />
</div>
<div id="contact"><a class="shedul-embed-button-link" style="overflow: visible; cursor: pointer; background: rgb(248,171,190); color: rgb(255, 255, 255); border: 0px; display: inline-block; outline: none; padding: 10px 15px; margin: 0px; font-family: Roboto, sans-serif; font-size: 16px; line-height: 16px; text-decoration: none; border-radius: 3px; -webkit-appearance: none; box-shadow: none;" href="https://www.fresha.com/providers/imani-skin-clinic-ltd-cgfhlxsq">Book Now</a><script>!function(e){var t="shedul-embed-button-loader",d="https:"===e.location.protocol?"https":"http",n=e.getElementsByTagName("head")[0];if(!e.getElementById(t)){var o=e.createElement("script"),p=e.createElement("style");o.id=t,o.src="https://app.shedul.com/embed_button.js".replace(/^\w+/,d),p.type="text/css",p.innerHTML=".shedul-widget-open { position: fixed; overflow:hidden; }",n.appendChild(o),n.appendChild(p)}}(document);</script></div>
</div>
<div class="col span_3_of_3">
<div class="contact-form">
<div id="zbwid-fbedad33"></div>
</div>
</div>
You've to do two things first give contact1 class to 100% width, though it's already there but syntax error. Put !important otherwise it will be overruled
.contact1{ width: 100% !important }
Then div that contains col span_3_of_3 classes, give this div a class with floating point
.your-class-name{ float: right !important }
You are good to go
For the class ".section", make width 100% instead of auto.
Above the div class="company_address", there is one div with class "col span_1_of_3",
For ".span_1_of_3", increase width to 50%.
And for ".col span_3_of_3", increase width to 30%, and set float: right.
You may adjust the widths according to your needs and for responsive design.
Start by fixing your HTML to mark all needed elements - container (or wrapper) and contact box + address box inside it. Then you can float the contact box and address box to the left or right. Also your CSS is targeting 2 classes that do not exist in your HTML.

Need help to make the pictures stand next to each column on the left

I've tried for hours to make the 1 picture stand next to a column (and the next one too, to the 2nd column) but I just can't get it to work right.. Can anyone help me with what I'm doing wrong?
http://jsfiddle.net/xp419wgc/
.column2 {
float: left;
width: 25%;
padding: 10px;
height: 100px;
}
.row2:after {
content: "";
display: table;
clear: both;
}
.persons {
font-family: dosis;
margin: 0 auto;
width: 1000px;
height: 200px;
background: rgba(255, 200, 255, 0.8);
color: rgb(0, 0, 0);
font-size: 14px;
}
<div class="persons"><br>
<div class="row2">
<div class="column2">
<h2>Jane Doe</h2><hr align="left" width="80%" noshade><p1>OFFICE</p1>
<p>
<p>Mail: something#something.com
<br>Phone: 123
</p>
<br><br>
</div>
<img src="http://www.infoprobe.com.au/site/images/drblankfem.gif" height="10%" width="10%">
<img src="http://www.infoprobe.com.au/site/images/drblankfem.gif" height="10%" width="10%">
<div class="column2">
<h2>Jane Doe</h2><hr align="left" width="80%" noshade><p1>OFFICE</p1>
<p>
<p>Mail: something#something.com
<br>Phone: 123
</p>
</div></div>
I believe your columns are floating, but your images are not. Meaning your columns will float together and your images will be displayed after.
I would suggest adding float: left to your images as well
Use css grid to avoid those problem.
u can try it by making classes for those image like this
.class {
display: grid;
//and then grid your images where u want to };
that would be. Useful !

No matter what I try, this image refuses to align to the center

See page (front.html)
Codepen
What the page should look like (Ignore the div highlighting, its structure is not being used)
No matter what or how I try, the "Read More" image (line 61) refuses to center horizontally AND responsively. As in, it's responding to pixel measurements, but not % measurements.
I've looked at around 15 articles by now, and I can't afford to spend any more time fruitlessly. Does anyone have a solution to the fact that the Read More image refuses to center? It should be responsive too. The only reason I can think of as to why it's not centering is because of bootstrap, but I doubt that.
The image is currently in a link tag inside a div that class="read-more". The image seems to ignore the margin-left and margin-right properties entirely.
.read-more img{
display:inline-block;
padding-left:auto;
margin-right:auto;
height:10%;
width:20%;
}
An image should not be centered using the approach you are using. Simply add:
text-align:center;
To the block level container element's CSS rule (not the image's CSS rule).
Text alignment is an inherited CSS property and you use it by applying it to the parent BLOCK LEVEL element (container) of the element that needs alignment. In your case, since you have the image inside of a div, the CSS rule should be applied to the div.
A width of 100% for the container and text-align:center should do:
.read-more img {
height: 10%;
width: 20%;
}
.read-more {
width: 100%;
text-align: center;
}
Updated codepen: http://codepen.io/anon/pen/EKmmMZ
You can apply text-align: center to read-more div to make image to center. Make Sure that the link and image must not have float property used.
Here is the code you exactly need.
Updated codepen: http://codepen.io/anuragscsit/pen/YqVVmv
body {
background-image: url("graphics/Website_background_2,_100_dpi.jpg");
}
body a {
color: rgb(241, 90, 34);
}
body a:hover {
color: rgb(208, 78, 29);
}
body a:visited {
color: rgb(144, 14, 0);
}
.row {
overflow: hidden;
}
[class*="xs-"] {
margin-bottom: -99999px;
padding-bottom: 99999px;
background-color: rgba(255, 255, 255, 0.8);
padding-top: 40px;
}
.row1-imgs img {
height: 60%;
width: 100%;
/*box-shadow: inset 5px 5px 7px rgb(0,256,0);/*the line that breaks .border-blue and .border-orange shadows*/
}
.read-more{text-align:center;}
.read-more img {
display: inline-block;
padding-left: auto;
margin-right: auto;
height: 10%;
width: 20%;
}
.read-more div {
background-color: green;
margin-left: 20px;
}
.row1 p {
text-align: justify;
margin-top: 20px;
padding-left: 15px;
padding-right: 15px;
}
.row2 {
text-align: center;
}
#row3 img {
height: 60%;
width: 100%;
}
[class*="title-"] {
text-shadow: 4px 4px 5px rgb(63, 63, 63);
font-weight: bold;
color: white;
font-family: Serif;
letter-spacing: 2px;
font-size: 130%;
text-align: center;
}
.title-blue,
.blue-border,
.title-orange,
.orange-border {
box-shadow: 5px 5px 7px rgb(117, 117, 117);
}
.title-blue {
background-color: rgb(0, 102, 179);
}
.title-orange {
background-color: rgb(208, 78, 29);
}
.blue-border {
border: 4px solid rgb(0, 102, 179);
}
.orange-border {
border: 4px solid rgb(208, 78, 29);
}
#post1 {
width: 85%;
margin-left: auto;
margin-right: auto;
}
#post1 p {
text-align: justify;
}
#post2 {
width: 50%;
margin-left: auto;
margin-right: auto;
}
.event {
padding-top: 3%;
}
.event p {
font-size: 110%;
}
.eventitle {
font-size: 120%;
font-weight: bold;
}
#post1 .eventitle {
color: rgb(0, 102, 179);
}
#post2 .eventitle {
color: rgb(208, 78, 29);
}
* {
/*border: 1px dotted green;*/
}
/*line 13-21 taken from http://stackoverflow.com/questions/19695784/how-can-i-make-bootstrap-columns-all-the-same-height
*/
<html lang="en">
<head>
<link rel="stylesheet" href="front.css" />
<meta name="" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="assets/css/bootstrap-responsive.css" rel="stylesheet">
<link rel="icon" href="graphics/Liger head for website masthead.ico" />
<title>Ligerbots</title>
</head>
<body>
<header>
</header>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display...Ross you decide whether this is important or not -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://sonexdjco.com/" target="_blank">
<img id="brand-image" src="img/bg9.png" alt="Check us out!">
</a>
</div>
<!-- Collect the nav links-->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="https://www.google.com/maps/dir//MONROE+Restaurant,+450+Massachusetts+Avenue,+Cambridge,+MA+02139/#42.3751756,-71.1304011,10.44z/data=!4m9!4m8!1m0!1m5!1m1!1s0x89e37754659a60b7:0xdf11b00d94f15ff9!2m2!1d-71.1012446!2d42.36351!3e0?hl=en-US"
target="_blank">Get Directions!<span class="sr-only">(current)</span></a></li>
<li><a href="https://sonexdjco.yapsody.com/event/index/34100/spring-fever" target=_blank>Buy Tickets!</a></li>
<li>Overview</li>
<li>Links</li>
<li>Map</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div style="background-color:rgba(255,255,255,0.8)" class="col-xs-5 col-xs-offset-1">
<div>
<div class="row1">
<div class="title-orange">
LIGERBUILD BLOG
</div>
<span class="row1-imgs"><img class="orange-border" src="graphics/row1col1.gif"/></span>
<p>Work has already begun on the chassis for the 2016 Stronghold robot. Five working groups are preparing the team to hit the ground running on January 9. We have students working on mechanical, electrical, programming and several fixing the road
kill. . . .</p>
</div>
<div>
</div>
</div>
</div>
<div class="col-xs-5">
<div class="row1">
<div class="title-blue">
LIGERBUISNESS BLOG
</div>
<span class="row1-imgs"><img class="blue-border" src="graphics/row1col2.jpg"/></span>
<p>FRC alumnus Ian from Dash Electric visited with his awesome electric longboard in December and told us how he started his company. Students got to ride his board and ask him lots of questions. <a>Read and see more. . .</a></p>
</div>
</div>
</div>
</div>
<div class="read-more">
<img src="graphics/Read_more_button_outlines.gif" />
</div>
<div class="row">
<div style="background-color:rgba(255,255,255,0.8);" class="col-xs-5 col-xs-offset-1">
<div class="row2">
<div class="title-blue">
ANNOUNCMENTS
</div>
<div style="background-color:rgba(255,255,255,0.8)" class="blue-border">
<div id="post1">
<div class="event">
<span class="eventitle">Team Dinners Needed During Build</span>
<p>Please sign up to make team dinners during build season. We eat together as a team on Friday nights at 6:00. Several families can do this together. Please see the signup here.
</div>
<div class="event">
<span class="eventitle">Carpool Drivers Needed</span>
<p>Please sign up to drive carpools from North to South and back, Mondays through Saturdays during build season. Please see details on our carpool page, here.</p>
</div>
<div class="event">
<span class="eventitle">STIMMS Signup Required</span>
<p>All Students must sign up on STIMMS or theey will not be able to attend competitions. Please see details here.</p>
</div>
<div class="event">
<span class="eventitle">No Team Meeting 12/24</span>
<p>There will be no team meeting 12/24 due to Christmas. Team meetings will resume on 1/4/16.</p>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-5">
<div class="row2">
<div class="title-orange">
UPCOMING EVENTS
</div>
<div style="background-color:rgba(255,255,255,0.8)" class="orange-border">
<div id="post2">
<div class="event">
<span class="eventitle">Visit the Waban Cub Scouts</span>
<p>January 13, 2016, 7-8 p.m.<br/> Waban Library Center</p>
</div>
<div class="event">
<span class="eventitle">Visit to Danger Awesome!</span>
<p>January 23, 2016, 4-6 p.m.<br/> 215 Ranham St. Melrose, MA</p>
</div>
<div class="event">
<span class="eventitle">Whole Foods Fundraiser</span>
<p>Feb. 1-28 10 a.m.-10 p.m.<br/> Whole Foods, Newton Four Corners</p>
</div>
<div class="event">
<span class="eventitle">FRC Competition at WPI</span>
<p>March 11-12, 2016, 9 a.m.-5 p.m.<br/> Worcester Polytechnic Institute<br/> Link to FIRST Livestream here</p>
</div>
<br/>
<br/>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-10 col-xs-offset-1">
<div id="row3">
<div class="blue-border">
<img src="graphics/row3col1.jpg" />
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</html>
You need to alter the css line 42 to this
.read-more {
text-align: center;
}
Please use "margin" property to bring it center.It will align the image in order of -Top,Right,Bottom and Left.
.read-more img {
display: inline-block;
float:center;
padding-left: auto;
margin: 0 0 0 40%;
height: 10%;
width: 20%;
}
try this perhaps
.read-more {
margin: 0 20% 0 20%;
}
or any value of percentage that you'd like

CSS overflow not obeying padding

I have a set of HTML elements that I need to style, which I can't change the structure of in any way (yeah, I know).
The HTML has a div that contains two nested spans. The div has padding and the overflow is hidden. The width of the div is set programatically and applied as an inline style.
I would like the text contained within the inner span to be clipped, but still retain the right hand padding as specified on the containing div.
After some research, it appears that the standard approach to this is to use a second nested div but, as I mentioned, I can't change the structure of the HTML.
Currently I have:
<!-- This is what I have to work with (I can't change the structure of this HTML!) -->
<div class="c1" style="width: 100px;">
<span class="c1-inner">
<span class="c1-inner-2">
122333444455555666666777777788888888999999999
</span>
</span>
</div>
<!-- This is how I want the HTML above to display -->
<div class="c2" style="width: 100px;">
<div class="c2-inner">
122333444455555666666777777788888888999999999
</div>
</div>
Styled by the following CSS:
.c1 {
border: 1px solid red;
border-radius: 4px;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
overflow: hidden;
}
.c1-inner {
// No relevant styles here yet
}
.c1-inner-2 {
// No relevant styles here yet
}
.c2 {
border: 1px solid red;
border-radius: 4px;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
}
.c2-inner {
overflow: hidden;
}
A jsFiddle is available here
I need to style the top "button" so that it looks like the second one only using CSS. I have reached the limits of my CSS skills and any help would be very much appreciated.
A simple fix. Most important bit: you can make a span have a display value of block rather than inline, which is its default.
Here's the relevant CSS you need and a working example:
.c1 {
border: 1px solid red;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
}
.c1-inner {
overflow: hidden;
display: block;
}
.c2 {
border: 1px solid red;
background-color: #c0c0c0;
padding: 0 13px 0 13px;
}
.c2-inner {
overflow: hidden;
}
We want this<br>
<!-- This is what i Have to work with -->
<div class="c1" style="width: 100px;">
<span class="c1-inner">
<span class="c1-inner-2">
122333444455555666666777777788888888999999999
</span>
</span>
</div>
<!-- This displays how i want the html above to display -->
<br>
to look like this<br>
<div class="c2" style="width: 100px;">
<div class="c2-inner">
122333444455555666666777777788888888999999999
</div>
</div>
<br>
but cannot change the structure of the html!