Homogenizing button heights for responsive displays (CSS) - css

I have two buttons in my template like so:
I'm trying to ensure they remain symmetrical in size (height and width) over smaller screens. Yet, as screen width decreases, this happens:
How do ensure the Foo button is the same height as the Bar Foo Bar button even over smaller screen sizes? Looking for the simplest, purely CSS-based solution.
My current CSS looks like this:
<style>
div.tab {
overflow: hidden;
background-color: white;
text-align:center;
display:inline-block;
width:95%;
max-width:400px;
padding:5px;
}
div.tab button {
background-color: #eeeeee;
float: left;
padding: 0.5em;
border: none;
width:49.5%;
}
div.tab button:hover{
border-bottom: 2px solid #ffa726;
color:#fb8c00;
}
</style>
<div class="tab">
<button>Foo</button>
<button style="float:right;border-bottom: 2px solid #ffa726;color:#fb8c00;background-color:#fff3e0;"><b>Bar Foo Bar</b></button>
</div>
Using display:flex in div.tab results in this:

You can achieve that by using display: flex:
div.tab {
overflow: hidden;
background-color: white;
text-align: center;
display: inline-block;
width: 95%;
max-width: 400px;
padding: 5px;
display: flex; /*here*/
}
div.tab button {
background-color: #eeeeee;
float: left;
padding: 0.5em;
border: none;
width: 49.5%;
}
div.tab button:hover {
border-bottom: 2px solid #ffa726;
color: #fb8c00;
}
<div class="tab">
<button>Foo</button>
<button style="float:right;border-bottom: 2px solid #ffa726;color:#fb8c00;background-color:#fff3e0;"><b>Bar Foo Bar</b></button>
</div>
Giving that you are using links as child elements, the solution is display-table:
div.tab {
overflow: hidden;
background-color: white;
text-align: center;
width: 95%;
max-width: 400px;
padding: 5px;
display: table;
}
div.tab a {
display: table-cell;
width: 1%;
height: 100%;
}
div.tab a button {
padding: 0.5em;
border: none;
vertical-align: middle;
width: 98%;
background-color: #eeeeee;
display: inline-block;
height: 100%;
}
div.tab button:hover {
border-bottom: 2px solid #ffa726;
color: #fb8c00;
}
<div class="tab">
<a href="#/">
<button>Foo</button>
</a>
<a href="#/">
<button style="border-bottom: 2px solid #ffa726;color:#fb8c00;background-color:#fff3e0;"><b>Bar Foo Bar</b></button>
</a>
</div>

Related

CSS text-align and vertical-align confusion

I am trying to create a very simple webpage to learn a bit about CSS as I am awful with it.
I am trying to add a navigation bar to my page. The two elements that are not working as expected are the text-align: center (in .Item) and vertical-align: bottom. If I add or remove these lines nothing happens.
Could anyone tell me why these two parts don't seem to be working as expected? Thanks in advance.
My JSX is as follows:
<React.Fragment>
<div className ={classes.Logo}></div>
<div className = {classes.Bar}>
<div className ={classes.Nav}>
<ul className={classes.Item}>
About
</ul>
<ul className={classes.Item}>
Shop
</ul>
</div>
</div>
</React.Fragment>
My CSS is as follows:
.Logo {
width: 100vw;
background-color: white;
border-bottom: 1px solid black;
height: 15vh;
}
.Bar {
width: 100vw;
background-color: white;
border-bottom: 1px solid #81d8d0;
height: 5vh;
}
.Nav {
width: 50%;
height: 100%;
margin: auto;
border: 1px solid red;
text-align: center;
vertical-align: bottom;
}
.Item {
text-align:center;
margin:10px;
display: inline;
border: 2px solid black;
}
.Logo {
width: 100vw;
background-color: white;
border-bottom: 1px solid black;
height: 15vh;
}
.Bar {
width: 100vw;
background-color: white;
border-bottom: 1px solid #81d8d0;
height: 5vh;
}
.Nav {
width: 100%;
height: 100%;
margin: auto;
border: 1px solid red;
text-align: center;
vertical-align: bottom;
display: flex;
align-items: center;
justify-content: center;
}
.Nav ul{
margin: 0px;
padding: 0px;
}
.Nav li{
display: inline-block;
margin: 0 10px;
padding: 0px;
border: 1px solid red;
text-align: center;
}
<React.Fragment>
<div className ={classes.Logo}></div>
<div className = {classes.Bar}>
<div className ={classes.Nav}>
<ul className={classes.Item}>
<li> About</li>
</ul>
<ul className={classes.Item}>
<li> Shop</li>
</ul>
</div>
</div>
</React.Fragment>
After reading all of your suggestions I was able to do it as follows:
.Logo {
width: 100vw;
background-color: white;
border-bottom: 1px solid black;
height: 15vh;
}
.Bar {
width: 100vw;
background-color: white;
border-bottom: 1px solid #81d8d0;
height: 5vh;
}
.Nav {
width: 50%;
height: 100%;
margin: auto;
border: 1px solid red;
text-align: center;
}
.Item {
position: relative;
text-align: center;
margin: 0px 50px;
display: inline;
border: 2px solid black;
top: calc(100% - 30px);
}
And
<React.Fragment>
<div className ={classes.Logo}></div>
<div className = {classes.Bar}>
<div className ={classes.Nav}>
<div className={classes.Item}>About</div>
<div className={classes.Item}>Shop</div>
</div>
</div>
</React.Fragment>

Submenu with divs

I was wondering if is it possible to create a submenu using divs? All online tutorials use this ul li thing. I don't know how to activate my submenu by hovering over an option. Should I add new class to "director" div? Incuding photos and code pieces.
HTML:
.menu_opcje {
float: left;
min-width: 100px;
text-align: center;
border-right: dotted 2px black;
padding: 10px;
}
.menu_wysuwane {
min-width: 100px;
text-align: center;
border-bottom: dotted 2px black;
padding: 10px;
display: none;
}
.menu_wysuwane:hover {
background-color: white;
}
.menu_opcje:hover,
.sidebar_opcje:hover {
background-color: lightgray;
cursor: pointer;
}
<div id="menu">
<div class="menu_opcje">Strona główna</div>
<div class="menu_opcje">Galeria</div>
<div class="menu_opcje">Reżyserzy
<div>
<div class="menu_wysuwane">Quentin Tarantino</div>
<div class="menu_wysuwane">Bracia Coen</div>
<div class="menu_wysuwane">Wes Anderson</div>
</div>
</div>
</div>
https://i.stack.imgur.com/cldDy.png
https://i.stack.imgur.com/TrvsC.png
It is semantically incorrect, though making it appear on hover, do like this
.menu_opcje:hover div {
display: block;
}
Sample snippet
.menu_opcje {
float: left;
min-width: 100px;
text-align: center;
border-right: dotted 2px black;
padding: 10px;
}
.menu_wysuwane {
min-width: 100px;
text-align: center;
border-bottom: dotted 2px black;
padding: 10px;
display: none;
}
.menu_wysuwane:hover {
background-color: white;
}
.menu_opcje:hover,
.sidebar_opcje:hover {
background-color: lightgray;
cursor: pointer;
}
.menu_opcje:hover div {
display: block;
}
<div id="menu">
<div class="menu_opcje">Strona główna</div>
<div class="menu_opcje">Galeria</div>
<div class="menu_opcje">Reżyserzy
<div>
<div class="menu_wysuwane">Quentin Tarantino</div>
<div class="menu_wysuwane">Bracia Coen</div>
<div class="menu_wysuwane">Wes Anderson</div>
</div>
</div>
</div>

How do I to get a ul list od divs to display inline?

I've got a ul that I want to be inline horizontally. See what it currently looks like here. I need the pink, orange & blue boxes to display inline. Can anybody help?
Here's the HTML:
<div id="header-li">
<ul class="header-i">
<li>
<div class="quick-i1"></div>
</li>
<li>
<div class="quick-i2"></div
</li>
<li>
<div class="quick-i3"></div>
</li>
</ul>
</div>
And here's the CSS code:
#header-li {
display: inline-block;
height: 60px;
width: 500px;
border: 1px solid #000000;
margin: 10px;
padding: 0;
position: relative;
vertical-align: middle;
}
.quick-i {
height:70px;
width: 166px;
border: 1px solid #000000;
display: inline-block;
vertical-align: middle;
position: relative;
margin: 0 0 0 0;
padding: 0px;
}
ul.header-i {
display: inline-block;
list-style-type: none !important;
padding: 0;
list-style-type: none;
}
.quick-i1 {
height: 50px;
width: 100px;
border: 2px solid orange;
position: relative;
margin-top: 4px;
display: inline-block;
}
.quick-i2 {
height: 50px;
width: 100px;
border: 2px solid yellow;
position: relative;
margin-top: 4px;
display: inline-block;
}
.quick-i3 {
height: 50px;
width: 231px;
border: 2px solid blue;
position: relative;
margin-top: 4px;
display: inline-block;
}
You need to set the li to be inline too:
.header-i li
{
display:inline-block;
}

Align div vertically in the middle [duplicate]

This question already has answers here:
Vertically centering a div inside another div [duplicate]
(24 answers)
Closed 7 years ago.
I'm trying to align some DIVs and failing to succeed.
<div class="row">
<div class="name"><h3>Some long name in here</h3></div>
<div class="info">
<div class="delete">X</div>
<div class="price">1000.00</div>
</div>
</div>
This is what I did so far https://jsfiddle.net/uvo2xdxk/
How can I make the .info div to be vertically aligned inside the row?
You can achieve this by display: table-cell;
Remove float from .name and .info and assign display: table-cell; vertical-align: middle; to them :)
.row {
display: table;
width: 450px;
background-color: yellow;
border: 1px solid blue;
}
.name {
background-color: red;
display: table-cell;
vertical-align: middle;
}
.delete {
background-color: green;
display: inline;
margin-right: 25px;
}
.price {
background-color: blue;
display: inline;
margin-right: 5px;
}
.info {
display: table-cell;
width: 150px;
vertical-align: middle;
background-color: ccc;
border: 1px solid green;
text-align: right;
}
<div class="row">
<div class="name">
<h3>Some long name in here</h3>
</div>
<div class="info">
<div class="delete">X</div>
<div class="price">1000.00</div>
</div>
</div>
https://jsfiddle.net/uvo2xdxk/5/
try this one
.row {
width: 450px;
background-color: yellow;
border: 1px solid blue;
display:table;
}
.row {
width: 450px;
background-color: yellow;
border: 1px solid blue;
display:table;
}
assign row display:table; property and its child display:table-cell; and vertical-align:middle; and also remove the float:right; from child
Add to your .info:
.info{
//...
position: absolute;
top: 50%;
transform: translate(0, -50%)
}
And your .row should set:
position: relative;
I had updated your jsfiddle
I have modified your css please check here
.name {
background-color: red;
display: inline;
float: left;
}
.delete {
background-color: green;
display: inline;
margin-right: 25px;
}
.price {
background-color: blue;
display: inline;
margin-right: 5px;
}
.row {
width: 450px;
background-color: yellow;
border: 1px solid blue;
height: auto;
vertical-align: middle;
overflow:hidden;
position:relative;
}
.info {
float: right;
display: inline-block;
background-color: ccc;
border: 1px solid green;
vertical-align: middle;
position:absolute;
right:0;
transform:translateY(-50%) ;
top:50%;
}
Please check if it works for you.
You can check with the below link.
https://jsfiddle.net/uvo2xdxk/7/
.name {
background-color: red;
display: inline;
float: left;
}
.delete {
background-color: green;
display: inline;
margin-right: 0px;
}
.price {
background-color: blue;
display: inline;
margin-right: 5px;
}
.row {
width: 450px;
background-color: yellow;
border: 1px solid blue;
display:table;
}
.info {
height:57px;
display: table-cell;
vertical-align:middle;
background-color: ccc;
border: 1px solid green;
top: 25%;
}

Fluid icon relative to parent

In my fiddle, There are two buttons with icons. Currently I am using fixed width and heightfor these icons, how can I use percentage relative to the parent size of these icons? Example: 80%?
Fixed width and height of my icons:
.gc_footer_nix_icon_img, .gc_footer_use_icon_img {
width: 25px;
height: 25px;
}
HTML:
<div class='gc_container'>
<div class='gc_gift'>
<div class='gc_gift_inner'>
<div class='gc_amount'>$100 Amount</div>
<div class='gc_subtitle'>Test subtitle</div>
<div class='gc_hr'></div>
<div class='gc_terms'>Test terms</div>
<div class='gc_footer'>
<div class='gc_footer_expiry'>Test Date</div>
<div class='gc_footer_use_nix'>
<div class='gc_footer_use'>
<div class='gc_footer_button_wrapper'>
<div class='gc_footer_use_txt'>Use</div>
<div class='gc_footer_use_icon'>
<img class='gc_footer_use_icon_img' src='https://imagizer.imageshack.us/v2/849x565q90/833/uua2.jpg' />
</div>
</div>
</div>
<div class='gc_footer_nix'>
<div class='gc_footer_button_wrapper'>
<div class='gc_footer_nix_txt'>Nix</div>
<div class='gc_footer_nix_icon'>
<img class='gc_footer_nix_icon_img' src='https://imagizer.imageshack.us/v2/849x565q90/833/uua2.jpg' />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.gc_gift {
margin-top:1.5%;
margin-left:auto;
margin-right:auto;
margin-bottom:1.5%;
height: auto;
width: 97%;
position:relative;
overflow: scroll;
webkit-overflow-scrolling: touch;
border:1px solid #D1D1D1;
}
.gc_gift_inner {
font-size:1em;
text-align: left;
background-color: #ffffff;
border:0px solid #D1D1D1;
display:table;
margin-top:2.5%;
margin-left:auto;
margin-right:auto;
margin-bottom:2.5%;
height: auto;
width: 95%;
position:relative;
overflow: scroll;
webkit-overflow-scrolling: touch;
}
.gc_amount {
color: red;
font-size:2em;
}
.gc_subtitle {
font-weight: bold;
font-size: 1em;
color: #707070;
}
.gc_hr {
width: 100%;
position: relative;
margin: auto;
border-color: #D1D1D1;
border-style: solid;
border-width: 1px 0 0 0;
}
.gc_terms {
font-size: 0.8em;
color: #707070;
}
.gc_footer {
width: 95%;
display: table;
position: relative;
}
.gc_footer_expiry {
display: table-cell;
vertical-align: bottom;
font-size: 0.8em;
font-weight: bold;
width: 40%;
color: #707070;
border: 0px solid yellow;
}
.gc_footer_use_nix {
display: table-cell;
vertical-align: middle;
width: 60%;
border:0px solid green;
margin: auto;
text-align: right;
}
.gc_footer_use {
display: inline-block;
vertical-align: middle;
background-color: #3F6EB6;
border-radius: 1px;
padding: 2%;
position: relative;
border:0px solid red;
margin-right: 5%;
}
.gc_footer_use_txt {
text-align: right;
display: table-cell;
vertical-align: middle;
color: white;
font-size: 1em;
font-weight: bold;
}
.gc_footer_use_icon {
text-align: right;
display: table-cell;
vertical-align: middle;
}
.gc_footer_nix {
display: inline-block;
vertical-align: middle;
background-color: #D61920;
border-radius: 1px;
color: white;
font-size: 1em;
border: 0x solid green;
padding: 2%;
margin-right: 5%;
}
.gc_footer_nix_txt {
text-align: center;
display: table-cell;
vertical-align: middle;
position: relative;
border: 0px solid blue;
width: 50%;
font-weight: bold;
}
.gc_footer_nix_icon {
text-align: center;
display: table-cell;
vertical-align: middle;
position: relative;
border: 0px solid yellow;
width: 50%;
}
.gc_footer_button_wrapper {
display: table;
width: 100%;
position: relative;
border: 0px solid blue;
}
.gc_container {
background-color:#ffffff;
height: auto;
width: 90%;
display:table;
margin-top:3%;
margin-bottom:3%;
margin-left:auto;
margin-right:auto;
position:relative;
border:1px solid #D1D1D1;
}
.gc_amount, .gc_subtitle, .gc_terms, .gc_footer {
border: 0px solid green;
display:table;
width:100%;
padding-top:0.3em;
padding-bottom:0.3em;
}
.gc_footer_nix_icon_img, .gc_footer_use_icon_img {
width: 25px;
height: 25px;;
}
You need to set width to gc_footer_nix and gc_footer_use , and then you'll be able to set the width on the images . Fiddle: http://jsfiddle.net/TgW2D/7/

Resources