aligning right but not breaking the vertical align - html

I'm still having a lot of trouble with this that it's even difficult to describe the problem now. The yellow text area should be right at the edge (righthand side edge) of the pink div and there should be 30px of margin in between this yellow area div and the other area on the left (contains the green and red areas).
The problem is fixed if I add 'float:right;' in 'home-featured-class-3', but this creates a new problem of shifting the yellow text area div to the top.
How can I make the yellow text div float right but also float vertically in the center? (without adjusting the height/width of anything)
HTML & CSS:
.home-featured-class-3{
width: 630px;
height:auto;
margin:0 0 0 30px;
display: inline-block;
vertical-align: middle;
background:#CF0;
}
.home-featured-class-4{
width:298px;
height:auto;
margin:0 0px 0 0;
border: 1px solid #211c20;
display: inline-block;
vertical-align: middle;
}
.home-featured-class-A{
width:960px;
height:auto;
background:#C3C;
vertical-align:middle;
}
.clear {
clear: both;
}
h6{
font-family:arial,verdana,helvetica,sans-serif;
font-size:18px;
color:#201c1f;
text-decoration:none;
text-transform:uppercase;
font-weight:100;
margin:0;
padding:10px;
background:#DB1D1D;
text-align:center;
border-top:1px solid #211c20;
}
h6 a:link{
color:#201c1f;
text-decoration:none;
}
h6 a:visited{
color:#201c1f;
text-decoration:none;
}
h6 a:hover{
color:#201c1f;
text-decoration:underline;
}
#home-featured-classes-wrap{
width:auto;
height:auto;
margin: 30px 0 0 0;
}
.home-featured-class:hover .products {
text-decoration: underline;
}
.home-featured-class-end{
width:298px;
height:auto;
margin:0 0 0 0;
border: 1px solid #211c20;
float:left;
}
.home-featured-class-end:hover .products {
text-decoration: underline;
}
<div id="home-featured-classes-wrap">
<div class="home-featured-class-A">
<div class="home-featured-class-4"><img name="RP-TEXT" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG" width="298" height="148" alt="RP-TEXT" style="background-color: #3366FF" />
<h6 class="products">RP-TEXT</h6>
</div>
<div class="home-featured-class-3">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<div class="clear"></div>
</div>
</div>

This is your problem (described in CSS comments):
.home-featured-class-3{
width: 630px;
height:auto;
margin:0 0 0 30px; /* Here you set the margin to 30px on the left. */
display: inline-block;
vertical-align: middle;
background:#CF0;
margin: 0; /* Here you set it back to 0 again. Simply remove this line. */
}
Also you’ll have to remove the newlines (or comment them out) above <div class="home-featured-class-3">. The HTML engine creates an additional whitespace character because of this newline leaving you only about 27px of space instead of 30px. You’ll have to remove these newlines in order to be able to set a distance of 30px.
This is what your HTML needs to be:
<div id="home-featured-classes-wrap">
<div class="home-featured-class-A">
<div class="home-featured-class-4">
<img name="RP-TEXT" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG" width="298" height="148" alt="RP-TEXT" style="background-color: #3366FF" />
<h6 class="products">RP-TEXT</h6>
</div><!--
--><div class="home-featured-class-3">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<div class="clear"></div>
</div>
</div>
JSFiddle.

Related

Get the desired horizontal margin independently on how the items are in the html

I am trying to apply a CSS rule that fits the next scenarios independently on the layout inside the button.
scenario 1: text
scenario 2: text + icon
scenario 3: icon + text
This is the desired behavior:
For now, I am applying padding to the button, so it works for scenario 1 and then I tried to add a margin to the icon image. However, it is added to the padding and its side becomes bigger than the other.
You can see the issue in the following image.
Can this be achieved with the only CSS?
code
<button class="pzl-button pzl-button-base primary">BUTTON</button>
<button class="pzl-icon-button pzl-button-base primary">BUTTON<img class="pzl-icon-button" src="assets/icon/chevron.svg"></button>
<button class="pzl-icon-button pzl-button-base primary"><img class="pzl-icon-button" src="assets/icon/chevron.svg">BUTTON</button>
css
.pzl-button-base {
margin: 8px;
background: none;
text-decoration: none;
border: 1px solid transparent;
display: inline-block;
padding: 3.5px 16px;
font-family: "Rubik", sans-serif;
font-size: 1rem;
line-height: 1.5;
}
.pzl-button-base.primary{
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.16);
background: #E9B56F;
color: #FAFAFA;
}
.pzl-button-base.primary img {
filter: invert(99%) sepia(35%) saturate(0%) hue-rotate(173deg) brightness(113%) contrast(96%);
height: 1.5em;
}
.button-chevron-inverted {
transform: rotateZ(180deg);
}
.pzl-button-base img {
padding: 0 6px;
}
This is the CSS box model, which might help you to visualise the issue you are having:
Any margin you add to the icon image will come on the 'outside' of the padding property.
I am not 100% sure what you are asking, but if you are trying to add a margin between each of the 3 buttons, then you need to apply the margin property to the buttons, not to the icon images.
does this helps ?
.textbox {
position:relative;
display:inline-block;
width: 8rem;
height: 2rem;
border: 2px solid orange;
margin-left:1rem;
background:orange;
}
.text {
position:relative;
width:100%;
display:inline-block;
text-align:center;
color:white;
margin-top:7px;
}
.leftarrow {
position:relative;
display:inline-block;
float:right;
margin-right:1rem;
}
.rightarrow {
position:relative;
display:inline-block;
float:left;
margin-left:1rem;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" integrity="sha512-HK5fgLBL+xu6dm/Ii3z4xhlSUyZgTT9tuc/hSrtw6uzJOvgRr2a9jyxxT1ely+B+xFAmJKVSTbpM/CuL7qxO8w==" crossorigin="anonymous" />
<div class="textbox"><div class="text">BUTTON</div></div>
<div class="textbox"><div class="text"><i class="fas fa-arrow-right leftarrow"></i>BUTTON</div></div>
<div class="textbox"><div class="text"><i class="fas fa-arrow-left rightarrow"></i>BUTTON</div></div>

Aligning list to get 100% width on every row

I have the following html and css code:
.catering-cities {
text-align: left;
margin-left: 0 !important;
}
.catering-cities li {
display: block;
float: left;
}
.catering-cities a {
display: block;
background-color: #d6d6d6;
color: #212121;
padding: 15px 10px;
margin: 0 2px 2px 0;
font-size: 11px;
text-transform: uppercase;
}
<ul class="catering-cities clearfix margin_bottom_20">
<li>Augustów</li>
<li>Bartoszyce</li>
<li>Bełchatów</li>
<li>Biała Podlaska</li>
<li>Białystok</li>
<li>Bielsk Podlaski</li>
<li>Brzeg</li>
<li>Bydgoszcz</li>
<li>Chełm</li>
<li>Chrzanów</li>
<li>Ciechanów</li>
<li>Częstochowa</li>
<li>Elbląg</li>
<li>Ełk</li>
<li>Gdańsk</li>
<li>Gdynia</li>
<li>Gliwice</li>
<li>Głogów</li>
<li>Kalisz</li>
<li>Katowice</li>
<li>Kędzierzyn Koźle</li>
<li>Kielce</li>
<li>Kluczbork</li>
<li>Kołobrzeg</li>
<li>Konin</li>
<li>Koszalin</li>
<li>Kraków</li>
<li>Legnica</li>
<li>Lubin</li>
<li>Lublin</li>
</ul>
What I want to achieve is for the ul to fill 100% of the width, the li elements taking a dynamic size, with the same margin inbetween. Something similar to text-align:justify but for ul li elements.
Is this possible to do by changing padding for every element?
You can use flexbox for this together with flex-grow:1 on the li. See snippet below
.catering-cities{
text-align:left;
margin-left:0 !important;
display:flex;
flex-wrap:wrap;
padding-left:0!important;
}
.catering-cities li{
display:block;
flex-grow:1;
}
.catering-cities a{
display:block;
background-color:#d6d6d6;
color:#212121;
padding:15px 10px;
margin:0 2px 2px 0;
font-size:11px;
text-transform:uppercase;
}
<ul class="catering-cities clearfix margin_bottom_20">
<li>Augustów</li>
<li>Bartoszyce</li>
<li>Bełchatów</li>
<li>Biała Podlaska</li>
<li>Białystok</li>
<li>Bielsk Podlaski</li>
<li>Brzeg</li>
<li>Bydgoszcz</li>
<li>Chełm</li>
<li>Chrzanów</li>
<li>Ciechanów</li>
<li>Częstochowa</li>
<li>Elbląg</li>
<li>Ełk</li>
<li>Gdańsk</li>
<li>Gdynia</li>
<li>Gliwice</li>
<li>Głogów</li>
<li>Kalisz</li>
<li>Katowice</li>
<li>Kędzierzyn Koźle</li>
<li>Kielce</li>
<li>Kluczbork</li>
<li>Kołobrzeg</li>
<li>Konin</li>
<li>Koszalin</li>
<li>Kraków</li>
<li>Legnica</li>
<li>Lubin</li>
<li>Lublin</li>
</ul>

Can't remove padding on an image

I'm trying to make a simple 3-cell div that will show a list of ratings for cigars. I want the left cell to be a square image of the cigar, the middle to be the name, and the right to be the rating. The code works fine until I add the image - it then seems to add an 8px border on the bottom of the image, revealing the cell's background color. Using Wordpress (if that helps). Any help is appreciated!
This is the page: http://cigardojo.com/best-cigars/
HTML
<div class="ratingWrapTopRated">
<div class="cigarImage"><img src="http://cigardojo.com/wp-content/uploads/2014/08/cigar-test.jpg" alt="test" width="90" height="90" class="alignnone size-full wp-image-14045" /></div>
<div class="cigarName">Opus XXX Power Ranger</div>
<div class="numericalScoreTopCigars"></div>
</div>
CSS
.ratingWrapTopRated {
background:#fff;
width:600px !important;
height: 90px !important;
margin: 0 auto;
display:table;
font-family:Helvetica, Arial, sans-serif;
margin-bottom: 10px;
}
.cigarImage {
background:#fff; color:#fff;
display:table-cell;
width: 90px;
}
.cigarName {
background:#ff5100; color:#fff; text-align:center;
display:table-cell;
vertical-align:middle;
text-transform: uppercase;
}
.numericalScoreTopCigars {
background:#000; color:#fff; text-align:center;
width:25%;
display:table-cell;
vertical-align:middle;
font-weight:bold;
border-left: 4px solid; border-color: #fff;
}
Add line-height: 0; to .cigarImage and you will get rid of it. Many people will tell you to use display: block; and that will work but that is not the real problem. The problem is that img tags are inline and you get that space because you get the image plus the line-height it is in that container, and that creates the space you see below your image. The correct solution to that is to add what I just told you.
So edit your class like this:
.cigarImage {
background:#fff; color:#fff;
display:table-cell;
line-height: 0; /* Here is the solution */
width: 90px;
}
And you will get that working right :)
This is because images are inline (that is, they're treated like they're on a line of text) by default, and the bottom of them is aligned to the "baseline" of the line of text, not the absolute bottom. Below the image you get the space from the rest of the line below the baseline. If you just set the image to display: block; it should get rid of it (then it won't be considered part of a line of text, and will instead be its own block).
Just add a padding right of 5px or so on the .cigarImage class. You should also increase your image height or decrees the height of the info bar next to your images as they dont line up.
In your class ratingWrapTopRated class set line-height to 0:
.ratingWrapTopRated {
background:#fff;
width:600px !important;
height: 90px !important;
margin: 0;
display:table;
font-family:Helvetica, Arial, sans-serif;
padding-bottom: -8px;
margin-bottom: 10px;
line-height: 0; /*here*/
}

Align Divs at Top and create space between Divs

How do I align my three divs to be at the top?
- See how Google Mail and Google Maps dropdown since they have less content? I'd like them to be aligned at the top no matter how little text is below them
Also, I have three divs at 33.3333%.
- If I wanted to put more space inbetween the divs (say like 5px, how would I do that?
Here's my Jsfiddle: http://jsfiddle.net/huskydawgs/Z7dZR/
Here's my code:
<div id="wrapper-threecol">
<div id="threecol_row">
<div class="threecol_cell1">
<p class="summary-headline">Google Mail</p>
<p class="summary-description">Gmail's inbox helps you stay organized by sorting your mail by type. Plus, you cannot work correctly.</p>
</div>
<div class="threecol_cell2">
<p class="summary-headline">Google</p>
<p class="summary-description">Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.</p>
</div>
<div class="threecol_cell3">
<p class="summary-headline">Google Maps</p>
<p class="summary-description">Find local businesses, view maps and get driving directions in Google Maps.</p>
</div>
</div>
</div>
Here's my CSS:
#wrapper-threecol {
position:relative;
width:100%;
border: none;
margin: 20px 0 0 0;
}
#threecol_row {
height:100%;
white-space:nowrap;
}
.threecol_cell1, .threecol_cell2, .threecol_cell3 {
height:100%;
width:33.3333%;
display:inline-block;
white-space:normal;
}
.summary-headline {
color: #232323;
font-family: 'SegoeRegular', Helvetica, Arial, sans-serif;
font-size: 20px;
line-height: 24px;
margin:0;
text-align: center;
}
.summary-description {
color: #232323;
font-family: 'SegoeRegular', Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 23px;
margin: 0;
text-align: center;
}
I put 5% spacing
http://jsfiddle.net/Z7dZR/1/
.threecol_cell1, .threecol_cell2, .threecol_cell3 {
height:100%;
width:30%;
display:inline-block;
white-space:normal;
vertical-align: top;
margin-left: 5%;
}
.threecol_cell1{
margin-left: 0;
}
You need to vertically align the inline-block elements to the top vertical-align: top;
For spacing, I made your blocks width 30%, which means you have 10% left of the 100%. So I set 5% to margin left for each block then set the first block margin-left to 0 so you have a perfect 100%. Since you have width in %, it would be wise to set the margin in % as well
.threecol_cell1, .threecol_cell2, .threecol_cell3 {
vertical-align: top;
}
that should do it.

first div makes all of the other divs move out of place

My first image is throwing off everything. Go to my website and see what I mean. The three images on the right should be in the middle of the page and the text should be under the picture. What am i doing wrong?
<div id="img"><img src="images/15442_193554864778_3851953_n.jpg" width="245" height="306" alt="Me"/></div>
<div id="Lefttext"><p>Hello there. My name is Michael Pelvay and I am a Web specialist. A Web Specialist is between a Web Master and a Web Developer. A Web specialtist possesses the skills and knowledge to develop and implement dynamic Web sites, develop content-rich intranets and secure Web communications and web sites. </p></div>
<div id="portfolio"><img src="images/Portfolio.png" width="876" height="148" alt="portfolio" /></div>
<div id="resume"><img src="images/Resume.png" width="750" height="148" alt="Resume" /></div>
<div id="aboutme"><img src="images/About Me.png" width="624" height="148" alt="About Me" /></div>
html, body{
width:auto;
height:auto;
margin:0;
background-color:#121212;
}
#container{
margin:100px 50px 100px 300px;
min-width:500px;
max-width:1300px;
height:652px;
background-color:#26353c;
clear:both;
}
#img{
float:left;
width:245px;
margin:60px 0 0 60px;
}
#Lefttext{
color: #B5D5FB;
position:relative;
float: left;
width: 424px;
top:380px;
left:80px;
}
#portfolio{
float:right;
margin:100px -70px 0 0;
clear:right;
}
#resume{
float:right;
margin:15px -70px 0 0;
clear:right;
}
#aboutme{
float:right;
margin:15px -70px 0 0;
clear:right;
}
#name {
color:#FFF;
float:left;
margin:50px 0px 0px 320px;
}
#nav {
font-size:20px;
float:right;
margin:64px 250px 0px 0px;
}
#nav li{
display:inline;
margin-right:75px;
}
#nav a:link{
color:#C1CECC;
text-decoration:none;
}
#nav a:visited{
color:#C1CECC;
text-decoration:none;
}
#links{
font-size:24px;
}
#links a:link{
color:#C1CECC;
text-decoration:none;
}
You could give your #Lefttext a left: -245px, it wil put your text under the image
I tried this out in Chrome Dev tools, seems to work like you want:
#img{
float:left;
width:245px;
margin:60px 0 0 60px;
position: absolute;
}
Adding position: absolute; to the #img div takes it out of the flow of the document so everything else goes where you want.
If someone would like to explain why they gave a downvote to an answer that works and explains why it works, please feel free to add a comment below. :D
Mike - your challenge is a few different things:
If you float left, you need to clear: left anything you want to show below it.
If you have position relative, you should not specify top. top (as is left, right, bottom) are the appropriate properties for something positioned absolute or fixed.
Here's some suggested edits:
#Lefttext {
color: #B5D5FB;
float: left;
clear: left;
position: relative;
width: 424px;
margin-left: 80px;
}