Nothing I can find or have tried is working so I hope someone can tell me where I am going wrong. I have a table-like HTML structure with div rows containing only span cells. These in turn can contain either a single span or two rows of spans. Unfortunately, for some reason I've been wrestling with on and off for weeks, the single span cells do not align with the double-row cells.
The minimal HTML is:
<div id="box">
<div id="rowA" class="row">
<span class="container">
<span class="top">A</span>
<span class="bottom">B</span>
</span>
<span class="container">
<span class="single">C</span>
</span>
</div>
<div id="rowB" class="row">
<span class="container">
<span class="top">D</span>
<span class="bottom">E</span>
</span>
<span class="container">
<span class="single">F</span>
</span>
</div>
</div>
with CSS,
body {
font-size: 16px;
}
div#box {
width: 716px;
height: 255px;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}
div.row {
width: 712px;
height: 47px;
padding: 1px;
padding-left: 4px;
margin-left: auto;
margin-right: auto;}
span.container {
display: inline-block;
width: 40px;
height: 40px;
margin-top: 2px;
padding: 1px;
border: 1px solid black;
border-radius: 4px;}
span.top, span.bottom {
display: inline-block;
width: 100%;
height: 50%;
line-height: 20px;
vertical-align: middle;
}
span.single {
display: inline-block;
width: 100%;
height: 100%;
line-height: 40px;
vertical-align: middle;
text-align: center;
}
The double row cells (e.g. <span class="container"><span class="top">D</span><span class="bottom">E</span></span>) display correctly, the single row cells are shifted downwards for some reason. I know that I can use positioning to correct for the problem but I'd like to understand where I am going wrong. It's tested on Chrome and Firefox and alas their inspectors leave me none the wiser.
All contributions very gratefully received!
body {
font-size: 16px;
}
div#box {
width: 716px;
height: 255px;
margin: 10px auto;
}
div.row {
width: 712px;
height: 47px;
padding: 1px;
padding-left: 4px;
margin-left: auto;
margin-right: auto;
}
span.container {
vertical-align:top; /* ADD JUST THIS LINE */
display: inline-block;
width: 40px;
height: 40px;
margin-top: 2px;
padding: 1px;
border: 1px solid black;
border-radius: 4px;
}
span.top, span.bottom {
display: inline-block;
width: 100%;
height: 50%;
line-height: 20px;
vertical-align: middle;
}
span.single {
display: inline-block;
width: 100%;
height: 100%;
line-height: 40px;
vertical-align: middle;
text-align: center;
}
Related
I need the image to be sticked to left and occupy entire corner without taking spacing in top and bottom.Below is the CSS used for the chip and for the image inside chip.
.imgDiv{
display: inline-block;
padding: 0 25px;
height: 50px;
font-size: 16px;
line-height: 50px;
width: fit-content;
border-radius: 25px;
background-color: #f1f1f1;
}
.img {
float: left;
margin: 0 10px 0 -25px;
height: 50px;
width: 50px;
border-radius: 50%;
}
You can do it easily and purely with CSS flexbox:
.UserPill {
display: inline-flex;
align-items: center;
border-radius: 6em;
padding-right: 0.5em;
background-color: #f1f1f1;
font: 16px/1.6 sans-serif;
gap: 10px;
}
.UserPill-img {
height: 2.4em;
width: 2.4em;
object-fit: cover;
border-radius: 50%;
}
.UserPill-remove {
border: 0;
cursor: pointer;
background: transparent;
}
<div class="UserPill">
<img class="UserPill-img" src="https://picsum.photos/id/237/100/100">
<span class="UserPill-name">Chris Morris</span>
<button class="UserPill-remove" type="button" arial-label="Remove">✖</button>
</div>
<div class="UserPill">
<img class="UserPill-img" src="https://i.stack.imgur.com/qCWYU.jpg?s=328&g=1">
<span class="UserPill-name">Roko</span>
<button class="UserPill-remove" type="button" arial-label="Remove">✖</button>
</div>
<div class="UserPill">
<img class="UserPill-img" src="https://lh6.googleusercontent.com/-IdYKeLCNsyQ/AAAAAAAAAAI/AAAAAAAAAAA/AMZuucmgTYg8zk2oLDC9ZC0NM8sFu23r3g/s96-c/photo.jpg?sz=328">
<span class="UserPill-name">Anto Clinton</span>
<button class="UserPill-remove" type="button" arial-label="Remove">✖</button>
</div>
<div class="UserPill">
<img class="UserPill-img" src="https://i.stack.imgur.com/MGiQc.jpg?s=128&g=1">
<span class="UserPill-name">Amirreza Amini</span>
<button class="UserPill-remove" type="button" arial-label="Remove">✖</button>
</div>
I could get what you mean a bit. I think you want something like this. I don't know why you applied padding to .imgDiv, I deleted that. I think you applied it because of the width, use width instead.
.imgDiv {
display: inline-block;
/* EDITED HERE (USE WIDTH INSTEAD)
padding: 0 25px;*/
height: 50px;
font-size: 16px;
line-height: 50px;
/* RIGHT DOWN BELOW */
width: 200px;
border-radius: 25px;
background-color: #f1f1f1;
}
.img {
float: left;
/* EDITED HERE (DELETED)
margin: 0 10px 0 -25px; */
height: 50px;
width: 50px;
border-radius: 50%;
}
<div class='imgDiv'>
<img src='https://picsum.photos/200/300' class='img'>
<span>Chris Moris</span>
<span>✕</span>
</div>
I'm trying to align circles in the center on mobile. Here is what I've used on https://www.wmhi.com.au/elite-edge-leadership-resilience/
.circle {
width: 240px;
height: 240px;
border-radius: 50%;
font-size: 24px;
color: #fff;
line-height: 30px;
text-align: center;
background: #ea4335;
vertical-align: top;
display: inline-block;
}
.circle:hover {
background-color:#79c852;
color:white;
}
I need to keep the texts as laid there now (inline-block). The circles are appearing left aligned on mobile phones. Any help would be highly appreciated.
Thanks in advance :)
Kindly change your CSS from
.circle {
width: 240px;
height: 240px;
border-radius: 50%;
font-size: 24px;
color: #fff;
line-height: 30px;
text-align: center;
background: #ea4335;
vertical-align: top;
display: inline-block;
}
to this
.circle {
width: 240px;
height: 240px;
border-radius: 50%;
font-size: 24px;
color: #fff;
line-height: 30px;
text-align: center;
background: #ea4335;
vertical-align: top;
display: block;
padding-top: 10px;
margin: auto;
}
And it will work perfectly fine. I just made these elements block give them an auto margin and give some top padding to the text.
try following code for good design some change for good design please add one div for all content vertically center when you add one line code or more than large content set vertically center also your circle center in mobile.
.circle {
width: 240px;
height: 240px;
border-radius: 50%;
font-size: 24px;
color: #fff;
line-height: 30px;
text-align: center;
background: #ea4335;
vertical-align: top;
display: table;
margin: 0 auto;
}
.vertical-center {
display: table-cell;
vertical-align: middle;
}
.circle h2 {
margin-top: 0;
margin-bottom: 15px;
}
.circle p {
margin: 0;
}
.circle:hover {
background-color:#79c852;
color:white;
}
<div class="wpb_wrapper">
<div class="circle">
<div class="vertical-center">
<h2 class="w-h2">
<span style="color: #ffffff;">Step 3</span>
</h2>
<p>Run the popular Elite Edge training</p>
</div>
</div>
</div>
add the div before the circle class. like this and it will resolve the problem
<style>
.divCenter{margin:0 auto;text-align:center;}
</style>
<div style="margin:0 auto;text-align:center;">
<div class="circle">
<h2><span style="color: #ffffff;">Step 1</span></h2>
<p>Tell us your team’s resilience and leadership goals</p>
</div>
I am trying to achieve similiar effect to this:
The header and its subheader are both vertically aligned to the image.
I've written following code:
http://jsfiddle.net/u4zxn4eb/
It works but is it the best way to achieve this?
<div class="wrapper">
<h1>
<img src="https://s3.amazonaws.com/uifaces/faces/twitter/sachagreif/128.jpg" alt="">
<div class="vertical_align">
Your company's name
<p>Description</p>
</div>
</h1>
</div>
CSS:
body {
background: lightgrey;
}
.wrapper {
background: grey;
width: 100%;
}
h1 {
font-size: 18px;
margin: 0;
position: relative;
top: 35px;
}
.vertical_align {
display: inline-block;
vertical-align: middle;
}
img {
display: inline-block;
vertical-align: middle;
margin-right: 10px;
}
p {
margin: 0;
}
EDIT
As #chrisbedoya suggested I shouldn't put div inside h1 tag.
Deleted.
Instead of using h1 tag to position the whole, it's better to apply these rules separately:
.vertical_align a,
.vertical_align p {
position: relative;
top: 40px;
}
Well, define "best". If your method is standards compliant and works in all browsers then use it. If you're interested, here's how I'd do it:
<style>
#header {
height: 100px;
margin: 0px;
padding: 0px;
width: 500px;
}
#rectangle {
background-color: #f0f0f0;
height: 80px;
margin: 0px;
padding: 0px;
position: absolute;
left: 0px;
top: 0px;
width: 500px;
z-index: 1;
}
#square {
background-color: #ff0000;
height: 80px;
margin: 0px;
padding: 0px;
position: absolute;
left: 20px;
top: 20px;
width: 80px;
z-index: 2;
}
#text {
/* background-color: #00ff00; */
margin: 0px;
padding: 0px;
position: absolute;
left: 120px;
top: 41px;
width: 360px;
z-index: 2;
}
h1 {
font-family: Arial;
font-size: 20px;
line-height: 20px;
margin: 0px;
padding: 0px;
}
p {
font-family: Arial;
font-size: 12px;
line-height: 12px;
margin: 5px 0px 0px 0px;
padding: 0px;
}
</style>
<div id="header">
<div id="rectangle"></div>
<div id="square"></div>
<div id="text">
<h1>Company Name</h1>
<p>Company Tagline</p>
</div>
</div>
Well, this question is way too subjective and better suited for CodeReview. But I thought I'd give you my input.
First, let's clean up the HTML. Get some HTML5 in there as well.
<div class="wrapper">
<header>
<a href="#" class="logo-link">
<img src="https://s3.amazonaws.com/uifaces/faces/twitter/sachagreif/128.jpg" alt="">
</a>
<div class="vertical_align">
<h1>Your company's name</h1>
<h2>Description</h2>
</div>
</header>
</div>
Then make the CSS nice and tidy. We don't need much:
.logo-link {
display: inline-block;
position: relative;
top: 24px;
margin: 0 24px;
}
.logo-link img {
display: block;
}
.vertical_align {
display: inline-block;
vertical-align: top;
}
Here's an example.
I would use a position: relative property to align the image slightly below the header like you have in your image there.
HTML:
<div id="main" class="rounded-corners">
<div id="benefits">
<img src="/benefits-heading.png" style="padding: 30px;" />
<div id="corporateside">
<h1>Corporate Benefits</h1>
<p>blah</p>
</div>
<div style="clear: both;"></div>
<div id="employeeside">
<h1>Employee Benefits</h1>
<p>blah</p>
</div>
<div style="clear: both;"></div>
</div>
</div>
CSS:
#corporateside { width: 420px; height: 100%; position: absolute; left: 0; padding: 20px; height: 100%; display: block; }
#corporateside h1 { font-size: 24px; font-weight: 500; }
#corporateside h2 { color: #cc0000; font-size: 18px; font-weight: bold; text-transform: uppercase; padding-top: 10px; }
#corporateside p { padding: 0px; margin-top: -10px; }
#employeeside { width: 420px; position: absolute; right: 0; padding: 20px; height: 100%; display: block; }
#employeeside h1 { font-size: 24px; font-weight: 500; }
#employeeside h2 { color: #cc0000; font-size: 18px; font-weight: bold; text-transform: uppercase; padding-top: 10px; }
#employeeside p { padding: 0px; margin-top: -10px; }
#benefits { position: relative; height: auto; }
#main { width: 940px; height: auto; background-color: #ffffff; margin: 0 auto; padding: 0; background: #ffffff; border: 2px solid #ffc40d; -moz-border-radius: 20px; -webkit-border-radius: 20px; -khtml-border-radius: 20px; border-radius: 20px; }
I have fixed this issue by removing the position: absolute; from each div. Also I removed the <div style="clear: both;"></div> between the two divs. Thanks for your help!
It's because your divs are set with position: absolute;. This removes the div from the document flow and so the containing element behaves as if the divs are not present for its layout.
I'm not sure exactly what you're going for, but if you want to adjust the position of the two divs, try position relative or examine their margins and padding. A CSS reset can be very helpful as a general tool for making consistent layouts, especially across browsers.
Here's a jsfiddle of my suggestion, showing the divs side by side and the container behaving as desired.
http://jsfiddle.net/wCnLZ/
I couldn't set inline elements background like this:
My code is this:
#divMansetKategoriHaberleriContainer
{
background-color: Transparent;
margin-top: 4px;
font-size: 12px;
}
.divKategoriHaberItem
{
float: left;
background-color: White;
width: 324px;
height: 126px;
margin: 0;
padding: 0;
}
.divKategoriHaberItemImage
{
float: left;
width: 80px;
height: 80px;
border: 1px solid red;
margin: 2px;
}
.imgKategoriHaberResim_Cevre
{
width: 95%;
height: 95%;
}
.divKategoriHaberItemBaslikIcerik
{
}
.spHaberBaslik_Cevre
{
background-color: Green;
display: inline;
font-weight: bold;
padding: 5px;
height: 20px;
}
.spHaberIcerik_Cevre
{
display: block;
}
.divKategoriHaberDevami_Cevre
{
background-image: url('../images/HaberinDevami_Cevre.png');
background-repeat: no-repeat;
background-position: right;
height: 13px;
}
<div class="divKategoriHaberItem">
<div class="divKategoriHaberItemImage">
<img src='' alt='DÜNYANIN MEKANİK Dengesi Bozuldu' class="imgKategoriHaberResim_Cevre" />
</div>
<div class="divKategoriHaberItemBaslikIcerik">
<span class="spHaberBaslik_Cevre">
<a href='CevreHaber.aspx?id=2128'>DÜNYANIN MEKANİK Dengesi Bozul</a>
</span>
<span class="spHaberIcerik_Cevre">Demokratik Kongo Cumhuriyeti'n</span>
</div>
<div class="divKategoriHaberDevami_Cevre"></div>
</div>
PS: Sorry for i couldn't write with sentences :(
If i understand the question correctly, you will need to add a line-height that equals the total height of your inline element ...
in your case that would be 30px (20px for the height + 10px for the padding 5px top and 5px bottom..)
.spHaberBaslik_Cevre
{
background-color: Green;
display: inline;
font-weight: bold;
padding: 5px;
height: 20px;
line-height:30px; /*height + padding-top +padding-bottom*/
}