I know it is dumb question, but i am struggling with following problem
It is one of my menu buttons. I want div the represents icon (marked red with circle) be on the left side of the button and the text on the right (name (blue) above description (purple)). By the way, i am going to have plenty of those buttons and i want them appear in column (block).
My current problem is that icon div (red) and text div (green dashed) wont place inline.
My HTML is:
<style>
.HomeMenuNavbarButton {
text-decoration: none;
color : black;
border-style:outset;
border-width:4px;
border-radius:15px;
display:block;
padding:4px;
}
.circle {
width: 50px;
height: 50px;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
border-color: black;
border-style: dashed;
display: inline-block;
vertical-align: top;
}
</style>
<div class="container">
<div class="row">
#foreach (var node in Model.Nodes)
{
if (!(node.IsRootNode) && node.Children.Any())
{
<div class="col-md-4">
<button type="button" style="display:inline;" class="btn btn-info" data-toggle="collapse" data-target="#("#relatedNavList" + node.Title) ">#node.Title</button>
<div id="#("relatedNavList" + node.Title)" class="collapse">
#foreach (var child in node.Children)
{
<div class="HomeMenuNavbarButton" style="display:block;">
<div style="background-color:red;display:inline">
<div class="circle">
</div>
</div>
<div style="border-color: green; border-style: dashed; display:inline-block">
<div style="background-color:blue">#(child.Title)</div>
<div style="background-color:purple">#(child.Description)</div>
</div>
</div>
}
</div>
</div>
}
}
</div>
</div>
When you want to display stuff side by side in CSS, the easiest way is to use flexbox. Try to add display : flex; to your HomeMenuNavBar class.
Here is a complete document about flexbox from the Mozilla team.
Using a wrapper defined as a flexbox
.wrapper {
display: flex;
align-items: center;
justify-content: space-between;
width: 150px;
}
.circle {
height: 25px;
width: 25px;
border: medium dashed darkgray;
border-radius: 50%;
}
button {
background: dodgerblue;
color: white;
border-radius: 3px;
border: thin solid lightblue;
padding: 0.5em;
}
<div class="wrapper">
<button>Button</button>
<div class="circle"></div>
<span>Text</span>
</div>
You can do that just with display:inline-block on your button's elements
.elementButton
{
display:inline-block;
}
.circle {
width: 50px;
height: 50px;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
border-radius: 25px;
border-color: black;
border-style: dashed;
display: inline-block;
vertical-align: top;
}
.HomeMenuNavbarButton
{
display:block;
margin:5px;
}
<div class="HomeMenuNavbarButton">
<div class="circle elementButton">
</div>
<div class="elementButton">
<div>Title one</div>
<div>Content</div>
</div>
</div>
<div class="HomeMenuNavbarButton">
<div class="circle elementButton">
</div>
<div class="elementButton">
<div >Title two</div>
<div>Content</div>
</div>
</div>
Related
I just started to FE after a couple of years in BE.
Developing an analytics card with using Angular on FE and .net Core on BE.
Stucked on a point to find out the best practice about to change background-color: property of a class beneath of main class.
<div class="row">
<div class="journey-card-bottom">
<div *ngFor="let bottom of top.breakDown | keyvalue: originalOrder">
<div>
<span>{{bottom.key}}</span>
</div>
<div class="row">
<div class="col-lg-10">
<div class="progress">
<div class="progress-bar" role="progressbar"
[ngStyle]="{'width': bottom.value > 0 ? bottom.value + '%' : '8px'}"></div>
<span class="percentage-value">{{bottom.value}}</span>
</div>
</div>
</div>
</div>
</div>
</div>
Screenshot to the desired outcome
In my CSS;
.journey-card-bottom {
border: 1px solid #DADCDD;
box-sizing: border-box;
padding: 10px;
line-height: 3;
width: 100%;
height: 435px;
}
.progress {
background-color: white !important;
margin-top: 5px;
}
.progress-bar {
border-radius: 0.25rem;
height: 8px;
align-self: center;
background-color: #0B4886;
}
.journey-card-bottom .progress-bar:nth-of-type(1) {
background-color: #68D391;
}
.journey-card-bottom .progress-bar:nth-of-type(2) {
background-color: #FCAF65;
}
It seems :nth-of-type(1) changes the background color but not only for 1st bar, for all of them.
:nth-of-type(2)does not effect at all i guess because there is no direct parent-child relation between each other.
On the other hand i know i can achieve with using [ngStyle] based on the item index in [ngFor] however i'm not sure if it's the best practice or not.
:nth-of-type() applies to sibling elements. Since .progress-bar is the first sibling within .progress and has no other siblings with the class .progress-bar, only the styles declared in .journey-card-bottom .progress-bar:nth-of-type(1) will be applied. Here is a code snippet showing your CSS working by changing the HTML structure:
.journey-card-bottom {
border: 1px solid #DADCDD;
box-sizing: border-box;
padding: 10px;
line-height: 3;
width: 100%;
height: 435px;
}
.progress {
background-color: white !important;
margin-top: 5px;
}
.progress-bar {
border-radius: 0.25rem;
height: 8px;
align-self: center;
background-color: #0B4886;
}
.journey-card-bottom .progress-bar:nth-of-type(1) {
background-color: #68D391;
}
.journey-card-bottom .progress-bar:nth-of-type(2) {
background-color: #FCAF65;
}
<div class="journey-card-bottom">
<div class="progress">
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">90</span>
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">60</span>
</div>
</div>
To solve your issue, I would suggest using :nth-of-type() on the top-level element of the for loop. In the below example, the top-level element has the class .target-class:
.journey-card-bottom {
border: 1px solid #DADCDD;
box-sizing: border-box;
padding: 10px;
line-height: 3;
width: 100%;
height: 435px;
}
.progress {
background-color: white !important;
margin-top: 5px;
}
.progress-bar {
border-radius: 0.25rem;
height: 8px;
align-self: center;
background-color: #0B4886;
}
.target-class:nth-of-type(1) .progress-bar {
background-color: #68D391;
}
.target-class:nth-of-type(2) .progress-bar {
background-color: #FCAF65;
}
<!-- Rendered HTML from the component -->
<div class="row">
<div class="journey-card-bottom">
<div class="target-class">
<div>
<span>Passed</span>
</div>
<div class="row">
<div class="col-lg-10">
<div class="progress">
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">90</span>
</div>
</div>
</div>
</div>
<div class="target-class">
<div>
<span>Referred</span>
</div>
<div class="row">
<div class="col-lg-10">
<div class="progress">
<div class="progress-bar" role="progressbar"></div>
<span class="percentage-value">60</span>
</div>
</div>
</div>
</div>
</div>
</div>
I'm currently attempting to build a basic website using HTML, CSS and Javascript. However there's a specific part of this website that I'm having difficulty building. Here's what the section is meant to look like, with the part on the left being the part that's tripping me up the most. It's a section which is meant to contain four basic squares next to each other; Image 1 (linked earlier) provides a visual.
Here's an image of what I've currently managed to get: All four squares are present, but they're stacked on top of one another instead. I haven't been able to get much closer to it.
Here's the html code behind it:
<div class="top-large-left">
<h3 id="hot">Interaction</h3>
</div>
<div class="small-top-right">
<h3 id="item">Location</h3>
</div>
<div class="large-left-section">
<div>
<section class="left-section">
<div class="btn-group button">
<div class="button1">
<button type="button1">Display X, Y</button>
</div>
<div class="button2">
<button type="button2">Theme</button>
</div>
<div class="button3">
<button type="button3">Modal</button>
</div>
<div class="button4">
<button type="button4">Swap Image</button>
</div>
</section>
</div>
As well as the CSS:
.btn-group button {
background-color: #428bca;
border-radius: 5px;
font-weight: bold;
font-size: 15px;
color: white;
padding: 32px 19px;
cursor: pointer;
display: inline-block;
margin: 2px 2px;
border: 1px;
text-align: center;
line-height: 25px;
}
.button1 {
width: 130px;
}
.button2 {
width: 130px;
}
.button3 {
width: 130px;
}
.button4 {
width: 130px;
}
How would I be able to achieve what is being shown in the first image? Is the css-grid function what I need to use, or something else? Feel free to say if I need to provide any more information, thanks.
Flex is your solution here. Flex makes your life easier.
Run the snippet on full window. (Full page)
.top-large-left {
background-color: #428bca;
padding: 0 1rem;
}
.top-large-left h3 {
margin:0;
}
.wrapper {
display:flex;
flex-direction:row;
}
.large-left-section,
.large-right-section{
flex: 1 1 50%;
border: 10px solid lightgrey;
text-align: center;
margin:5px;
}
.btn-group button {
background-color: #428bca;
border-radius: 5px;
font-weight: bold;
font-size: 15px;
color: white;
padding: 32px 19px;
cursor: pointer;
display: inline-block;
margin: 2px 2px;
border: 1px;
text-align: center;
line-height: 25px;
}
.large-left-section .left-section .btn-group.button{
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
.large-left-section .left-section .btn-group.button .btn {
flex: 0 0 45%;
margin:5px;
}
.large-left-section .left-section .btn-group.button .btn button {
width:100%;
}
<div class="top-large-left">
<h3 id="hot">Interaction</h3>
</div>
<div class="wrapper">
<div class="large-left-section">
<section class="left-section">
<div class="btn-group button">
<div class="btn button1">
<button type="button1">Display X, Y</button>
</div>
<div class="btn button2">
<button type="button2">Theme</button>
</div>
<div class="btn button3">
<button type="button3">Modal</button>
</div>
<div class="btn button4">
<button type="button4">Swap Image</button>
</div>
</div>
</section>
</div>
<div class="large-right-section">
</div>
</div>
I have this layout of my web page, here last div tag <div>{this.props.status}</div> is in left end. I want to set it in center between rock and scissors button.
Expected
<div className="AppTitle">
<b>Score: {this.props.score}</b>
<div>
<RoundedButton text="Rock" clickitem={this.clickitem} />
<RoundedButton text="Paper" clickitem={this.clickitem} />
<RoundedButton text="Scissors" clickitem={this.clickitem} />
</div>
<div>{this.props.status}</div>
</div>
App.css
.AppTitle {
margin: 50px;
}
.Button {
padding: 20px;
margin: 20px;
border: 1px solid blue;
border-radius: 10px;
}
What is the way to do it in HTML ?
Try this for css.
.AppTitle {
margin: 50px;
display:inline-block;
}
.button {
padding: 20px;
margin: 20px;
border: 1px solid blue;
border-radius: 10px;
}
.status{text-align:center;}
<div class="AppTitle">
<b>Score: -1</b>
<div>
<Button class="button">Rock</Button>
<Button class="button">Paper</Button>
<Button class="button">Scissors</Button>
</div>
<div class="status">Computer Won</div>
</div>
EDITED
Here added four button & background this one clear.
.AppTitle {
margin: 50px;
display:inline-block;
background:#b5b5b5;
}
.button {
padding: 20px;
margin: 20px;
border: 1px solid blue;
border-radius: 10px;
}
.status{text-align:center;background:#ccc;}
<div class="AppTitle">
<b>Score: -1</b>
<div>
<Button class="button">Rock</Button>
<Button class="button">Paper</Button>
<Button class="button">Scissors</Button>
<Button class="button">Rock</Button>
</div>
<div class="status">Computer Won</div>
UPDATED
Make parent div to center.
.wrapper{text-align:center;}
.AppTitle {
margin:50px;
display:inline-block;
background:#b5b5b5;
text-align:left;
}
.button {
padding: 20px;
margin: 20px;
border: 1px solid blue;
border-radius: 10px;
}
.status{text-align:center;background:#ccc;}
<div class="wrapper">
<div class="AppTitle">
<b>Score: -1</b>
<div>
<Button class="button">Rock</Button>
<Button class="button">Paper</Button>
<Button class="button">Scissors</Button>
</div>
<div class="status">Computer Won</div>
</div>
</div>
If you have a look at .status, you'll find that it is the same width as the previous <div>. To center the text, you'll need to give it the CSS:
.status {
text-align: center;
}
Also, <RoundedButton> is not a HTML tag. Use <button> instead.
.AppTitle {
margin: 50px;
display: inline-block;
}
.button {
padding: 20px;
margin: 20px;
border: 1px solid blue;
border-radius: 10px;
}
.status {
text-align: center;
}
<div class="AppTitle">
<b>Score: -1</b>
<div>
<button class="button">Rock</button>
<button class="button">Paper</button>
<button class="button">Scissors</button>
</div>
<div class="status">Computer Won</div>
</div>
This could also work #Williams
.mainContainer {
width: 500px;
height: 200px;
border: 2px solid black;
background-color: lightgray;
}
.top {
width: 100%;
height: 50px;
background-color: lightgray;
display: table-cell;
vertical-align: middle;
padding-left: 100%;
}
.outputContainer {
width: 100%;
background-color: lightgray;
height: 20px;
}
#score {
margin-top: 50px;
display: inline;
}
.third {
width: 30%;
height: 70px;
background-color: lightgray;
display: inline-block;
}
button {
padding: 20px;
border: 2px solid blue;
border-radius: 10px;
width: 100px;
}
<div class="mainContainer">
<div class="top">
<span id="score"><b> Score: </b></span>
</div>
<center>
<div class="third">
<button type="button"> Rock </button>
</div>
<div class="third">
<button type="button"> Paper </button>
</div>
<div class="third">
<button type="button"> Scissors </button>
</div>
<div class="outputContainer">
<h2> Computer won! </h2>
</div>
</center>
</div>
In order to keep them aligned in most cases and not just as a fix on a certain display, try putting them in one and using display: block, like so
<div className="AppTitle">
<b>Score: {this.props.score}</b>
<div>
<RoundedButton text="Rock" clickitem={this.clickitem} />
<div style="display:block">
<RoundedButton text="Paper" clickitem={this.clickitem} />
<span>{this.props.status}</span>
</div>
<RoundedButton text="Scissors" clickitem={this.clickitem} />
</div>
I have a HTML structure with given CSS.
Both caption and progress elements should be rendered in same line. caption elements should not have fixed width and progress elements should fill up the rest of the space next to caption based on their inline-set width, which means that every progress element will have a different total pixel-width but should fill up only the given percentage of available space.
HTML structure and CSS rules can be changed in any way.
Is it possible to solve this problem with CSS only?
.table {
padding: 15px;
width: 280px;
border: 1px solid black;
font-family: sans-serif;
font-size: 12px;
}
.caption {
float: left;
}
.progress {
height: 14px;
border: 1px solid white;
border-radius: 4px;
background-color: green;
overflow: hidden;
}
.value {
margin-left: 5px;
}
<div class="table">
<div class="row">
<div class="caption">Short text: </div>
<div class="progress" style="width:11.65%">
<span class="value">11.65</span>
</div>
</div>
<div class="row">
<div class="caption">A bit longer text: </div>
<div class="progress" style="width:100%">
<span class="value">100.00</span>
</div>
</div>
<div class="row">
<div class="caption">X: </div>
<div class="progress" style="width:45.50%">
<span class="value">45.50</span>
</div>
</div>
</div>
Have you considered using Flexbox?
Just add this rule:
.row {
display: flex;
}
If your are concerned about browser support, an alternative would be using display:table. You should change your markup and CSS, like this:
.table {
border: 1px solid black;
font-family: sans-serif;
font-size: 12px;
padding: 15px;
width: 280px;
}
.inner-table {
display: table;
}
.row {
display: table-row;
}
.caption {
display: table-cell;
white-space: nowrap;
width: 1%;
}
.progress {
background-color: green;
border: 1px solid white;
border-radius: 4px;
display: table-cell;
height: 14px;
}
.value {
margin-left: 5px;
display:block;
width:0;
overflow: visible;
}
<div class="table">
<div class="inner-table">
<div class="row">
<div class="caption">Short text: </div>
<div style="width:1.65%" class="progress">
<span class="value">1.65</span>
</div>
<div class="remainder"></div>
</div>
</div>
<div class="inner-table">
<div class="row">
<div class="caption">A bit longer text: </div>
<div style="width:100%" class="progress">
<span class="value">100.00</span>
</div>
<div class="remainder"></div>
</div>
</div>
<div class="inner-table">
<div class="row">
<div class="caption">X: </div>
<div class="progress" style="width:45.50%">
<span class="value">45.50</span>
</div>
<div class="remainder"></div>
</div>
</div>
</div>
Please try this - padding-right: 5px; display:inline; add these properties in progress class and also remove width in progress.
Well, just for the future reference, I was playing a bit with the flexbox thingie and came up with this:
.table {
padding: 15px;
width: 280px;
border: 1px solid black;
font-family: sans-serif;
font-size: 12px;
}
.row {
display: flex;
}
.caption {
margin: 1px 5px 1px 0;
}
.progress {
flex-grow: 1;
margin: auto;
}
.progress-content {
height: 14px;
border-radius: 4px;
background-color: green;
}
.value {
margin-left: 5px;
}
<div class="table">
<div class="row">
<div class="caption">Short text:</div>
<div class="progress">
<div class="progress-content" style="width:11.65%">
<span class="value">11.65</span>
</div>
</div>
</div>
<div class="row">
<div class="caption">A bit longer text:</div>
<div class="progress">
<div class="progress-content" style="width:100%">
<span class="value">100.00</span>
</div>
</div>
</div>
<div class="row">
<div class="caption">X:</div>
<div class="progress">
<div class="progress-content" style="width:45.50%">
<span class="value">45.50</span>
</div>
</div>
</div>
</div>
If I get a solution without flexbox, will accept it as an answer :)
Problem 1: I'm trying to get my div boxes to have the same width regardless from text length I use (I will use max 2 digits), but I can't get it to work.
Problem 2: The target platform is mobile and when the linewraping occurs the "boxes" positions right under the text from the text on the line above (the borders crosses each other).
The reson for using div "groups" is that a javascript is going to change the value of 4 boxes at a time.
<!DOCTYPE html>
<html>
<head>
<style>
.wrap {
white-space: normal !important;
}
.online {
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border: 2px solid #00CC00;
width: 20px;
text-align: center;
padding: 2px;
display: inline;
}
.test {
display: inline;
}
</style>
</head>
<body>
<div id="A1-result" class="test">
<div class="online">0</div>
<div class="online">1</div>
<div class="online">2</div>
<div class="online">3</div>
</div>
<div id="A2-result" class="test">
<div class="online">4</div>
<div class="online">5</div>
<div class="online">6</div>
<div class="online">7</div>
</div>
<div id="A3-result" class="test">
<div class="online">8</div>
<div class="online">9</div>
<div class="online">10</div>
<div class="online">11</div>
</div>
<div id="A4-result" class="test">
<div class="online">12</div>
<div class="online">13</div>
<div class="online">14</div>
<div class="online">15</div>
</div>
</body>
</html>
Change display:inline property to display:inline-block. Read more about the difference between inline and inline-block.
.online {
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border: 2px solid #00CC00;
width: 20px;
text-align: center;
padding: 2px;
display: inline-block;
}
.test {
display: inline-block;
}
DEMO