Get rid from the text indentation [duplicate] - css

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 4 years ago.
How could I get rid from the text indentation in my case?
html:
<div class="mainContainer">
<div class="promptTitle">
Module Name
</div>
<div class="drawRegion">
</div>
<div class="nameTitle">
Module Name
</div>
</div>
css:
.mainContainer {
border: 1px darkgray solid;
border-radius: 10px;
}
.promptTitle {
color: #b8b8b8;
padding-top: 25px;
padding-left: 70px;
}
.drawRegion {
display: inline-block;
width: 50px;
margin-right: 0;
}
.nameTitle {
display: inline-block;
padding-left: 20px;
}
jsfiddle:
https://jsfiddle.net/76uedo40/561/
problem on screenshot:
My problem is that the second line of text Module Name is displayed with an indentation. I would expect to not have the indentation.
That is because the first Module Name indented 70px from left, while the second Module Name indented 50px from left due to the element with class="drawRegion" and 20px due to its own left padding. So, in total both first and second Module Name should indent 70px. And hence both should be placed with the same indentation, but this is not the case.
So, what am I missing here or what am I doing wrong?

Try removing the spacing between the drawRegion & nameTitle inline-block divs.
.mainContainer {
border: 1px darkgray solid;
border-radius: 10px;
}
.promptTitle {
color: #b8b8b8;
padding-top: 25px;
padding-left: 70px;
}
.drawRegion {
display: inline-block;
width: 50px;
margin-right: 0;
}
.nameTitle {
display: inline-block;
padding-left: 20px;
}
<div class="mainContainer">
<div class="promptTitle">Module Name</div>
<div class="drawRegion"></div><div class="nameTitle">Module Name</div>
</div>
Check this answer for a good explanation of white space between inline & inline-block elements.

There's no point in making the nameTitle as inline-block as you display the elements as blocks.
Therefore, keep the same CSS styles for the first and the last element.
.nameTitle {
display: block;
padding-left: 70px;
}

Related

How to remove this gap or merge the borders? Because the lengths are inconsistent

How to remove this gap or merge the borders? Because the lengths are inconsistent
box1 and box2 are 100px, box3 is 200px but their lengths are inconsistent because border...
so how do their length are consistent?
<main>
<div class="shortBox">box1</div>
<div class="shortBox">box2</div>
<div class="longBox">box3</div>
</main>
.shortBox {
width: 100px;
display: inline-block;
}
.longBox {
width: 200px;
}
.shortBox,
.longBox {
text-align: center;
font-size: 20px;
height: 50px;
background-color: #000;
color: #fff;
border: 1px solid #fff;
}
This happens when you have elements that have display: inline or inline-block. Since the browser treats these elements the same way as text, a line-break will be treated as white-space.
Setting the font size to 0 for the wrapper basically eliminates the whitespace, but keep in mind, that this property will be inherited to child elements, so you may have to set the font-size back to >0 for children. Also, this may break layouts that use em as unit, so keep that in mind. By also adding box-sizing: border-box the gaps are gone.
main {
font-size: 0;
}
.shortBox {
width: 100px;
display: inline-block;
}
.longBox {
width: 200px;
}
.shortBox,
.longBox {
box-sizing: border-box;
text-align: center;
font-size: 20px;
height: 50px;
background-color: #000;
color: #fff;
border: 1px solid #fff;
}
<main>
<div class="shortBox">box1</div>
<div class="shortBox">box2</div>
<div class="longBox">box3</div>
</main>
There is also a possible way to use comments to prevent the auto-formatting from adding the white-space / line-break. It does not look too elegant, but it gets the job done. Also, except for the box-sizing: border-box you don't need any additional CSS for this.
.shortBox {
width: 100px;
display: inline-block;
}
.longBox {
width: 200px;
}
.shortBox,
.longBox {
box-sizing: border-box;
text-align: center;
font-size: 20px;
height: 50px;
background-color: #000;
color: #fff;
border: 1px solid #fff;
}
<main>
<div class="shortBox">box1</div><!--
--><div class="shortBox">box2</div><!--
--><div class="longBox">box3</div>
</main>
The third way of solving this issue is to utilize flexbox. You can create layouts like this, without having to worry about gaps because of white-spaces or line-breaks.
watch this magic:
<main>
<div class="shortBox">box1</div><div class="shortBox">box2</div>
<div class="longBox">box3</div>
</main>
Notice that first 2 divs are NOT divided with new line.
Then in CSS add this extra 2px like this:
.longBox {
width: 202px;
}

How to display message in multiple div and not overlap eachpther when the window size changes

I have a container and displaying message .when I am changing window size the text is overlapping each other.
Here is my code.
<div id="msgRowInfo">
<div style="hieight:100%;width:100%">
<div id="msgInfo">
<div id="msgType" >{{msg.msgType}}</div>
<div id="msgTime" >{{msg.time}}</div>
</div>
<div id="msgContent" >{{msg.subject}}</div>
<div id="msgDescription" >{{msg.description}}</div>
</div>
</div>
Here is my css.
#msgRowInfo{
padding-top: 5px;
padding-left: 5px;
height: 100%;
width: 100%;
border-bottom: lightgrey;
border-bottom-style: solid;
border-bottom-width: thin;
display: -ms-inline-flexbox
}
#msgInfo{
width:100%;
padding-left:1%;
}
#msgType{
display: inline-flex;
font-size: 20px;
width: 70%;
}
#msgTime{
width:27%;
display: inline-block;
float: right;
text-align: right;
padding-right: 3%;
}
#msgContent{
padding-left: 1%;
width:100%;
font-size: 20px;
}
when I was resizing msg.msgType and msg.time is overlapping. How to not overlap each other and window size reducing it should come to next line.could somebody help me on this.
#msgRowInfo {
padding: 5px;
border-bottom: lightgrey 1px solid;
font-size: 20px;
}
#msgInfo {
display: flex;
flex-wrap: wrap;
background-color: red;
}
#msgType {
background-color: pink;
/* flex basis sets a minium width of the message type so message time wraps */
flex: 1 1 75%;
}
#msgTime {
background-color: tan;
}
<div id="msgRowInfo">
<div id="msgInfo">
<div id="msgType">{{msg.msgType}}</div>
<div id="msgTime">{{msg.time}}</div>
</div>
<div id="msgContent">{{msg.subject}}</div>
<div id="msgDescription">{{msg.description}}</div>
</div>
I was not really sure here exactly what you are looking for so I made a best guess. I have removed a lot of the css and some html. Sometimes reducing the complexity will help you solve the issue. I have also added some background color so you can see what is going on. Please let me know if you have questions. The application of display flex to the message info area will stop overlap of the Type and Time. Hope this helps.
Of course this is just one way to solve the issue there are many others.

CSS :last-child unexpected behaviour [duplicate]

This question already has answers here:
Can I combine :nth-child() or :nth-of-type() with an arbitrary selector?
(8 answers)
Closed 7 years ago.
Hi I am trying to use the last-child operator to hide the last div which applies a border. My issue is that the las div still has the border on the bottom
Below is the HTML for my Test
<div class="car-search">
<!--other divs removed for example-->
<div class="border-bottom"></div>
</div>
<div class="car-search">
<!--other divs removed for example-->
<div class="border-bottom"></div>
</div>
The CSS
.car-search .border-bottom{
border-bottom: 1px solid $lighterGrey;
padding-top: 15px;
margin-bottom: 15px;
width: 770px;
margin-left: 15px;
}
.car-search:last-child .border-bottom{
display: none;
}
I have no idea why the border is being displayed on the last .car-search
Current Output:
.car-search .border-bottom {
border-bottom: 1px solid #000;
padding-top: 15px;
margin-bottom: 15px;
width: calc(100% - 30px);
margin-left: 15px;
}
.car-search:last-child .border-bottom {
display: none;
}
Attempts
I have also tried using the !important tag with no success
I have tried :last-of-type with no success
Unfortunately there is no last-of-class selector inside of CSS. You'll either need to remove the .border-bottom element from your last .car-search element, or fall back to Javascript / jQuery to remove the element from the DOM.
For example, you could run the following jQuery code to remove the last .car-search element's .border-bottom:
$('.car-search').last().children('.border-bottom').remove();
jsFiddle Demo
Alternatively, if you wish to use pure CSS for this, you could wrap your .car-search elements inside of a container <div> and use the :last-of-type selector.
For example, your new structure might look like:
<div class="car-search-wrapper">
<div class="car-search">
<!--other divs removed for example-->
<div class="border-bottom"></div>
</div>
<div class="car-search">
<!--other divs removed for example-->
<div class="border-bottom"></div>
</div>
</div>
Then you may use:
.car-search:last-of-type .border-bottom {
display: none;
}
jsFiddle Demo
As said above there is no :last-of-class selector for now so the only way to do it is javascript. With jQuery you can run the following code:
jQuery('div.car-search:last .border-bottom').css({display:'none'});
Moreover with scss you can write
.car-search {
.border-bottom {
border-bottom: 1px solid $lighterGrey;
padding-top: 15px;
margin-bottom: 15px;
width: calc(100% - 30px);
margin-left: 15px;
}
&:last-of-type {
.border-bottom {
display: none;
}
}
}
Which is a bit less of scss lines.
In compiled CSS:
.car-search .border-bottom {
border-bottom: 1px solid $lighterGrey;
padding-top: 15px;
margin-bottom: 15px;
width: calc(100% - 30px);
margin-left: 15px;
}
.car-search:last-of-type .border-bottom {
display: none;
}

Displaying 1 text box and 3 images on the same row

Was wondering if i can display 1 text box and 3 images on the same row? All the images are the same size. If possible aswell i'd ideally like a some text underneath each image aswell?
heres the code:
<div class="row">
<div class="side-bar">
<h3> Recent Work </h3>
<p>Here's some of my latest work, covering web design, branding and identity.</p>
View the Portfolio →
</div>
<div class="recent-wrap">
<img src="img/body-metrix.png">
<img src="img/body-metrix-logo.png">
<img src="img/market.png">
</div>
</div>
.row {
display: inline;
float: left;
}
.side-bar {
padding: 10px;
background-color: #f3f3f3;
height: 200px;
width: 250px;
}
.side-bar h3 {
font-weight: bold;
font-size: 19px;
margin-bottom: 5px;
}
.side-bar p {
font-size: 14px;
}
.side-bar a {
font-size: 13px;
}
.recent-wrap img {
max-width: 225px;
min-height: 125px;
border-style: solid;
border-width: 1px;
border-color: #000000;
margin-right: 20px;
margin-bottom: 20px;
}
Ive searched the internet but no luck as yet.
thanks in advance.
There are a number of ways to do this, one example is to float the two child elements:
.side-bar, .recent-wrap {
float: left;
}
This will only work if there is enough room on the parent element for the .side-bar and .recent-wrap to sit next to each other.
Example: http://jsbin.com/poxox/1/edit
CSS:
.row {
width: 250px
}
http://jsfiddle.net/3DCSd/
Here Is a working Fiddle
.row {
display: inline-block; /* changed to inline-block, you don't need
inline and float */
}
.recent-wrap a { /*changed to a , since your images are wrapped in <a> */
max-width: 225px;
min-height: 125px;
border-style: solid;
border-width: 1px;
border-color: #000000;
margin-right: 20px;
margin-bottom: 20px;
}
The rest of the CSS stayed the same
and HTML I just added the text box
<div class="row">
<div class="side-bar">
<h3> Recent Work </h3>
<p>Here's some of my latest work, covering web design, branding and identity.</p>
View the Portfolio →
</div>
<div class="recent-wrap">
<input type="text" id="ss" />
<img src="img/body-metrix.png"/>
<img src="img/body-metrix-logo.png"/>
<img src="img/market.png"/>
</div>
</div>
Try this:
.side-bar {
padding: 10px;
background-color: #f3f3f3;
height: 200px;
width: 250px;
float: left; /* added */
}
.recent-wrap {
margin-left: 270px; /* added (padding + width) of side-bar */
}
Working Fiddle
This approach let the second container stay in line with the first container even if the window size is small.
Here is the sample with textboxes below image: example

Trying to place DIV's side by side, but its not working [duplicate]

This question already has answers here:
How to arrange many <div> elements side by side with no wrap [duplicate]
(3 answers)
Closed 8 years ago.
Here is my code:
<div class="large-6 columns">
<div id='box1'>
<div id='text1'>
Name
</div>
<div id='text3'>
LastName
</div>
</div>
</div>
CSS looks like this:
#box1 {
float: left;
height: 125px;
margin-top: 30px;
margin-bottom: 30px;
clear: none;
width: 125px;
border-top-left-radius: 95px;
border-top-right-radius: 95px;
border-bottom-right-radius: 95px;
border-bottom-left-radius: 95px;
background-color: rgb(232, 68, 58);
position:relative;
overflow:visible;
}
#text1 {
float: left;
font-size: 1em;
color: rgb(255, 255, 255);
width: 28%;
height: auto;
text-align: right;
font-weight: 400;
line-height: 1em;
word-wrap: break-word;
margin-left: 69.6%;
margin-top: 53px;
clear: none;
min-height: 0px;
min-width: 0.5em;
font-family: snippet;
overflow:auto;
}
#text3 {
float: left;
font-size: 1em;
color: rgb(0, 0, 0);
width: 72%;
height: auto;
text-align: right;
font-weight: 400;
line-height: 1em;
margin-left: 125px;
margin-top: 0px;
clear: none;
min-height: 0px;
min-width: 0.5em;
font-family: snippet;
position:relative;
overflow:visible;
}
Now this is not giving me the required result.
The Text-3 should actually appear next to the text-1. But somehow its wrapping down to the next tine.
btw. I am using this inside a Zurb Foundation code. Writing my custom class on top of the existing CSS styles.
EDIT:
Although I solved the problem, just for the clarity of some of you, Text-1 is inside the circle and is right aligned to the edge of the circle. Text-3 is outside the circle and is left aligned to the edge of the circle. Such that the two text, are next to each other, one inside the circle and one outside.
Is there a reason you are adding the margin-left to each div? Cleaned it up a little and it seems to work.
#text1 {
min-width: 0.5em;
width: 28%;
color: white;
}
#text3 {
min-width: 0.5em;
width: 72%;
color: black;
}
.inner-box {
float: left;
margin-top: 53px;
text-align: right;
font-weight: 400;
font-size: 1em;
line-height: 1em;
}
http://jsfiddle.net/ferne97/8FzN5/1/
Also think about creating a re-usable class for all that code that is getting repeated in each inner div.
http://jsfiddle.net/tahdhaze09/7FM82/
CSS:
#box1
{
width:980px;
float:left;
}
#text1{
width:450px;
float:left;
background-color:#45e64c;
}
#text3{
width:400px;
float:left;
background-color:#edc321;
}
HTML:
<div class="large-6 columns">
<div id='box1'>
<div id='text1'>
Name
</div>
<div id='text3'>
LastName
</div>
</div>
</div>
Text boxes, side by side. I left out the other CSS for simplicity.
Here's how to do this with Foundation's native architecture:
<div class="large-6 columns">
<p>Some content</p>
</div>
<div class="large-6 columns">
<p>Some more content</p>
</div>
This will give you two containers, side-by-side, spanning the full width of 960px.
I tried out the code on W3C school's
try it editor.
Your question does not really describe what you were expecting to see. Of course the "Name" and "Last name" beside each other. But within the circle? to left of it ?
I would recommend trying out the css on W3C's try it editor and playing around with the margins (margin-top, margin-left) and widths. Suggest starting by removing the margins and widths completely from the above css and then adding them one at a time. Of course check the try it editor for the changes due to each of the margin / width additions.

Resources