Display:inline-block is not running properly [duplicate] - html

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 17 days ago.
I want to arrange three pink boxes in 1 row.
However, applying display:inline-block creates a space on top.
What's the problem?
---------------HTML----------------
<div class="hello">
<h1>이건 첫째</h1>
</div>
<div class="hello">
<h2>이건 둘째</h2>
<input type="text">
</div>
<div class="helloCss">
<h2>이건 셋째</h2>
<ul>
<li>Hello</li>
<li>Css</li>
<li>World!</li>
</ul>
</div>
<div class="helloJava">
<h2>이건 넷째</h2>
<ol>
<li>Hello</li>
<li>Java</li>
<li>World!</li>
</ol>
</div>
---------------SCSS----------------
$g:rgb(115, 115, 115);
#mixin box($color:pink){
color:$g;
background-color:$color;
width:200px;
height:300px;
border:2px solid $g;
}
.hello{
display:inline-block;
input{
margin:{
left:10px;
top:10px;
}
}
#include box();
h1{
background-color:rgb(238, 206, 219);
}
&Java{
#include box();
background-color:rgb(175, 202, 255);
}
}
.helloCss{
#extend .hello;
}
margin 0, padding 0, wrap in one div, change h1 and h2 to span
Even if I raise the mouse from the developer tool, the area does not appear.

Because the elements are classed as inline the browser vertically aligns the text baseline to adjacent elements by default. If you draw a line under the bottom row of text you'll see they're all positioned next to each other.
More info from MDN here
The easiest way to fix this is the add vertical-align: top or similar to your css as follows:
.hello,
.helloCss {
display: inline-block;
vertical-align: top; /* added this */
color: #737373;
background-color: pink;
width: 200px;
height: 300px;
border: 2px solid #737373;
}
.hello input,
.helloCss input {
margin-left: 10px;
margin-top: 10px;
}
.hello h1,
.helloCss h1 {
background-color: #eecedb;
}
.helloJava {
color: #737373;
background-color: pink;
width: 200px;
height: 300px;
border: 2px solid #737373;
background-color: #afcaff;
}
<div class="hello">
<h1>이건 첫째</h1>
</div>
<div class="hello">
<h2>이건 둘째</h2>
<input type="text">
</div>
<div class="helloCss">
<h2>이건 셋째</h2>
<ul>
<li>Hello</li>
<li>Css</li>
<li>World!</li>
</ul>
</div>
<div class="helloJava">
<h2>이건 넷째</h2>
<ol>
<li>Hello</li>
<li>Java</li>
<li>World!</li>
</ol>
</div>

As Timothy mentioned, it could be the default behavior of inline-block. However, if making a slight change to your HTML is an option, creating a parent div with flex is much easier for aligning divs.
html
<div class="flex">
<div class="hello">
<h1>이건 첫째</h1>
</div>
<div class="hello">
<h2>이건 둘째</h2>
<input type="text">
</div>
<div class="helloCss">
<h2>이건 셋째</h2>
<ul>
<li>Hello</li>
<li>Css</li>
<li>World!</li>
</ul>
</div>
</div>
<div class="helloJava">
<h2>이건 넷째</h2>
<ol>
<li>Hello</li>
<li>Java</li>
<li>World!</li>
</ol>
</div>
CSCC
$g: rgb(115, 115, 115);
#mixin box($color: pink) {
color: $g;
background-color: $color;
width: 200px;
height: 300px;
border: 2px solid $g;
}
.flex {
display: flex;
gap: 5px;
}
.hello {
input {
margin: {
left: 10px;
top: 10px;
}
}
#include box();
h1 {
background-color: rgb(238, 206, 219);
}
&Java {
#include box();
background-color: rgb(175, 202, 255);
}
}
.helloCss {
#extend .hello;
}

Related

How to align buttons inside cards with different content

I am still learning CSS and HTML. So please excuse me if this is a silly question.
Please see my code below. I need help with aligning the blue buttons on both the cards. It should be on the bottom of the cards (aligned similarly) regardless of content size.
Please advise.
.row {
display: flex;
/* equal height of the children */
}
.col1 {
flex: 1;
/* additionally, equal width */
border: 1px solid #dadada;
margin: 0 40px 0 0;
padding: 0 0 10px 0;
}
.col2 {
flex: 1;
/* additionally, equal width */
border: 1px solid #dadada;
padding: 0 0 10px 0;
}
.card-header {
background: rgba(242, 242, 242, 1);
text-align: left;
font-size: 12px;
font-weight: 600;
padding: 31px 10px 31px 15px;
}
.card-header-bg {
height: 7px;
}
.card-container {
padding: 2px 14px;
}
.blue-button,
a.blue-button {
background-color: #026fc2;
border-radius: 99rem;
box-shadow: inset 0 0 0 1px #454545;
color: #fff;
text-decoration: none;
font-weight: 600;
padding: 0.5rem 1rem;
text-align: center;
display: inline-block;
}
<div class="row">
<div class="col1">
<div class="card-header-bg" style=" background-color: rgba(255, 181, 119, 1);"></div>
<div class="card-header">Header</div>
<div class="card-container">
<p>Test Example</p>
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
<p>Minor updates.</p>
<ul>
<li>test</li>
<li>Test</li>
</ul>
<p>Go Here</p>
</div>
</div>
<div class="col2">
<div class="card-header-bg" style=" background-color: #7ECEFD;"></div>
<div class="card-header">Header</div>
<div class="card-container">
<p>test123/p>
<ul>
<li>abc</li>
<li>def</li>
<li>ghi</li>
</ul>
<p>test test test.</p>
<ul>
<li>Learn about testing</li>
</ul>
<p>Second Test</p>
</div>
</div>
</div>
Not a silly question. They seem unaligned because there are more li's on the left side. Buttons are positioned statically by default, so if there is more content, it will be pushed down. You'll notice if you add more li's on the right side, the button will be pushed down and seem aligned. You may find nesting the buttons in their own divs will give you more control.
However, you can easily resolve this with your current structure by adding <br> or the line-break element on the button that is positioned higher. See below.
.row {
display: flex;
/* equal height of the children */
}
.col1 {
flex: 1;
/* additionally, equal width */
border: 1px solid #dadada;
margin: 0 40px 0 0;
padding: 0 0 10px 0;
}
.col2 {
flex: 1;
/* additionally, equal width */
border: 1px solid #dadada;
padding: 0 0 10px 0;
}
.card-header {
background: rgba(242, 242, 242, 1);
text-align: left;
font-size: 12px;
font-weight: 600;
padding: 31px 10px 31px 15px;
}
.card-header-bg {
height: 7px;
}
.card-container {
padding: 2px 14px;
display: flex;
flex-direction: column;
justify-content: center;
}
.blue-button,
a.blue-button {
background-color: #026fc2;
border-radius: 99rem;
box-shadow: inset 0 0 0 1px #454545;
color: #fff;
text-decoration: none;
font-weight: 600;
padding: 0.5rem 1rem;
text-align: center;
display: inline-block;
}
.btn-primary {
display: flex;
justify-content: flex-end;
align-items: center;
padding: 10px;
}
.card-container>div {
height: 210px;
}
<div class="row">
<div class="col1">
<div class="card-header-bg" style=" background-color: rgba(255, 181, 119, 1);"></div>
<div class="card-header">Header</div>
<div class="card-container">
<div>
<p>Test Example</p>
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
<p>Minor updates.</p>
<ul>
<li>test</li>
<li>Test</li>
</ul>
</div>
</div>
<div class="btn-primary">
Go Here
</div>
</div>
<div class="col2">
<div class="card-header-bg" style=" background-color: #7ECEFD;"></div>
<div class="card-header">Header</div>
<div class="card-container">
<div>
<p>test123</p>
<ul>
<li>abc</li>
<li>def</li>
<li>ghi</li>
</ul>
<p>test test test.</p>
<ul>
<li>Learn about testing</li>
</ul>
</div>
</div>
<div class="btn-primary">
Second Test
</div>
</div>
Largest rendered height at default ~ makes height for both divs.

Unable to align div to right side Flexbox [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 1 year ago.
I'm having a bit of trouble trying to get my interface working
<div class="tier" id="t1">
<div class='title'>
<h3>Tier 1</h3>
<h3 class="price">$5</h3>
</div>
<div class='description'>
<ul>
<li>Soundboard Access</li>
<li>In-Game and Discord tag</li>
<li>VIP and Donator channel access</li>
</ul>
</div>
</div>
<div class="tier" id="t2">
<div class='title'>
<h3>Tier 2</h3>
<h3 class="price">$8</h3>
</div>
<div class='description'>
<ul>
<li><span>All Previous Perks</span></li>
<li>Create a poll once per week</li>
<li>Choose SCP of the Day once per week</li>
</ul>
</div>
</div>
.tier {
border: 1px solid #007eff;
padding: 10px;
margin: 5px;
border-radius: 10px;
display: flex;
}
.title {
margin-top: -10px;
text-align: center;
}
.price {
font-family: monospace;
font-size: 40px;
margin-top: -10px;
margin-bottom: -3px;
padding: 5px;
border-top: 1px solid black;
}
.description {
margin: 3px;
text-align: end;
align-self: flex-end;
}
This is so far what I have, and for the most part it works, but I am struggling to get .description to align to the right.
I read the mozilla docs and I am supposed to be able to use align-self to move it to the end of the div, but that doesn't work. (does absolutely nothing)
Here is what it looks like right now:
Here is somewhat how I'd like it to look:
Any help is appreciated
Apply justify-content:space-between to .tier.
As per MDN:
The items are evenly distributed within the alignment container along the main axis. The spacing between each pair of adjacent items is the same. The first item is flush with the main-start edge, and the last item is flush with the main-end edge.
.tier {
border: 1px solid #007eff;
padding: 10px;
margin: 5px;
border-radius: 10px;
display: flex;
justify-content: space-between;
}
.title {
margin-top: -10px;
text-align: center;
}
.price {
font-family: monospace;
font-size: 40px;
margin-top: -10px;
margin-bottom: -3px;
padding: 5px;
border-top: 1px solid black;
}
.description {
margin: 3px;
text-align: end;
align-self: flex-end;
}
<div class="tier" id="t1">
<div class='title'>
<h3>Tier 1</h3>
<h3 class="price">$5</h3>
</div>
<div class='description'>
<ul>
<li>Soundboard Access</li>
<li>In-Game and Discord tag</li>
<li>VIP and Donator channel access</li>
</ul>
</div>
</div>
<div class="tier" id="t2">
<div class='title'>
<h3>Tier 2</h3>
<h3 class="price">$8</h3>
</div>
<div class='description'>
<ul>
<li><span>All Previous Perks</span></li>
<li>Create a poll once per week</li>
<li>Choose SCP of the Day once per week</li>
</ul>
</div>
</div>

My normal text moves when I use the hover property in CSS

I'm creating a sort draft 'Contact Us' page and I thought I'd play around with the hover property in CSS. See my code below.
.hoverinfo {
position: static;
color: #000000;
cursor: pointer;
}
.hoverinfo p {
display: none;
color: #000000;
border: 4px;
}
.hoverinfo:hover p {
background-color: #C4C4C4;
margin: 20px;
border: 1px solid black;
display: inline-block;
}
<p>Test</p>
<div id="contact" class="info">
<ul>
<li>
<div id="phone" class="hoverinfo">Telephone
<p>Number</p>
</div>
</li>
<li>
<div id="twitter" class="hoverinfo">Twitter
<p>Twitter URL</p>
</div>
</li>
</ul>
</div>
My issue at the moment is when I hover over 'Telephone' or 'Twitter', the actual text itself moves. I had a look around and people are usually saying it's because of padding, but I don't have any! This only started because I wanted to move the actual text that pops up farther to the right hand side because it was way too close to the other text when it popped up.
You can use the following solution using display:inline; on the visible / hovered <p> item:
.hoverinfo {
position: static;
color: #000000;
cursor: pointer;
}
.hoverinfo p {
display: none;
color: #000000;
}
.hoverinfo:hover p {
background-color: #C4C4C4;
border: 1px solid black;
margin:20px;
display: inline;
}
<p>Test</p>
<div id="contact" class="info">
<ul>
<li>
<div id="phone" class="hoverinfo">Telephone
<p>Number</p>
</div>
</li>
<li>
<div id="twitter" class="hoverinfo">Twitter
<p>Twitter URL</p>
</div>
</li>
</ul>
</div>
You need to just add position absolute to p Tag on hover.
.hoverinfo {
position: static;
color: #000000;
cursor: pointer;
}
.hoverinfo p {
display: none;
color: #000000;
border: 4px;
}
.hoverinfo:hover p {
background-color: #C4C4C4;
border: 1px solid black;
display: inline-block;
position: absolute;
margin-top: 0px;
}
<p>Test</p>
<div id="contact" class="info">
<ul>
<li>
<div id="phone" class="hoverinfo">Telephone
<p>Number</p>
</div>
</li>
<li>
<div id="twitter" class="hoverinfo">Twitter
<p>Twitter URL</p>
</div>
</li>
</ul>
</div>

Tabbed Navigation

I am attempting to recreate a simple tabbed navigation. My issue seems to be that I cannot position the tabs themselves without dragging the content along with it and currently, when I switch between the tabs, the content continues to shift over the left to keep with it's parent tab.
Would someone be able to help me straighten this?
HTML:
<header>
<ul class="tabs">
<li class="tabs-page">
<input type="radio" name="tab" id="personalInformation" checked />
<label for="personalInformation">Personal Information</label>
<div class="content">
<p>Content for Personal Information will go here!</p>
<p>And some more content will go here!</p>
</div>
</li>
</ul>
<li class="tabs-page">
<input type="radio" name="tab" id="teachingQualifications"/>
<label for="teachingQualifications">Teaching Qualifications</label>
<div class="content">
<p>Content for Teaching Qualifications will go here!</p>
<p>And some more content will go here!</p>
</div>
</li>
</ul>
<li class="tabs-page">
<input type="radio" name="tab" id="expensesInformation"/>
<label for="expensesInformation">Personal Expenses</label>
<div class="content">
<p>And some more content will go here!</p>
</div>
</li>
</ul>
</header>
css:
body
{
margin-left: 0;
margin-top: 0;
}
#formStyle10
{
height: 600px;
width: 500px;
background-color: white;
box-shadow: rgb(128, 128, 128) 2px 2px 2px, -2px -2px 2px rgb(128, 128, 128);
border-radius: 10px;
margin: 30px auto;
}
header
{
height: 65px;
width: 500px;
background-color: white;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border: 1px solid;
}
input[name="tab"]
{
display:none;
}
input[name="tab"] ~ .content
{
display:none;
}
input[name="tab"]:checked ~ .content
{
display: block;
}
input[name="tab"]:checked ~ label
{
background: #ccc;
}
.tabs-page
{
list-style: none;
}
.tabs-page > label
{
padding: 5px;
border-top-left-radius: 5px;
height: 35px;
border-top-right-radius: 5px;
border: 1px solid #2795EE;
width: 90px;
text-align: center;
float: left;
list-style: none;
}
.content
{
position: absolute;
top: 200px;
left: 200px;
}
Use
class with name clearfix
.clearfix{
clear:both;
}
place class with div at the middle of content and nav bar
if you have code share here, i will fix it.

Clear absolute floated elements

I try to make a hover effect. When user hovers one div it goes in position absolute and changes it's height. Here is the code:
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
.child {
position: relative;
z-index: 2;
width: 100%;
min-height: 48px;
}
.child:hover {
position: absolute;
z-index: 3;
border: 1px solid #c0c0c0;
}
.child .sub-child { display: none; }
.child:hover .sub-child { display: block; }
<div class="container">
<div class="row">
<div class="col-xs-4 col-md-4">
<div class="child">
First
<ul class="sub-child">
<li>First</li>
<li>Second</li>
</ul>
</div>
</div>
<div class="col-xs-4 col-md-4">
<div class="child">Second</div>
</div>
<div class="col-xs-4 col-md-4">
<div class="child">
Third
<ul class="sub-child">
<li>First</li>
<li>Second</li>
<li>Third</li>
<li>Fourth</li>
<li>Fifth</li>
</ul>
</div>
</div>
<div class="col-xs-4 col-md-4">
<div class="child">Fourth</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">Some text here</div>
</div>
</div>
The problem is that when hover goes to the last element from the row or to the last element from the list then content overlaps. How can I fix this?
I'm not sure if you're taking the right approach here, but I made some adjustments, including adding a parent div to the first row to add some margin so they don't overlap:
http://codepen.io/anon/pen/QbVewL
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css';
.menu{
margin-bottom: 20px;
}
.child {
position: relative;
z-index: 2;
width: 100%;
height: 48px;
border: 1px solid transparent;
box-sizing: border-box;
}
.child:hover {
position: absolute;
z-index: 3;
border: 1px solid #c0c0c0;
height: 62px;
background-color: #fff;
}