Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

good way to create margin to the top for the first element

I have list that I render with semantic-ui and it needs some margin to the top for the first element. I looked in the CSS code and I see margin-top:0!important and I can override it for the first element with margin-top:10px!important; and then the rendering looks good. Is there a better way to achieve it? My code (without the fix) is

<link href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <ul class="nav nav-tabs">
    <li class="nav active"><a href="#A" data-toggle="tab">All</a>
    </li>
    <li class="nav"><a href="#B" data-toggle="tab">Company</a>
    </li>
    <li class="nav"><a href="#C" data-toggle="tab">Private</a>
    </li>
  </ul>
  <!-- Tab panes -->
  <div class="tab-content">
    <div class="tab-pane fade in active" id="A">
      <div class="ui divided items">
        <div class="item">
          <div class="ui left floated">
            7 July.
            <br>3:33
          </div>
          <div class="image">
            <a href="/vi/5022701123010560.html">
              <img src="http://lh3.googleusercontent.com/JZkr-b_aWlYrFG1G-EUywZgucJE3JV1wgz4yQGrx-bGaw_va7dymsaTMXhK5t6ZkUdjWLeHlNaiksVNAMp8I1epB-Q=s150" title="Wordpress development company, website developer" alt="Wordpress development company, website developer">
            </a>
          </div>
          <div class="content">
            <a class="header" href="/vi/5022701123010560.html">Wordpress development company, website developer</a>
            <div class="meta">
              <span class="price"></span>
            </div>
            <div class="description">
              <p>Dit Interactive have experts wordpress ...</p>
            </div>
            <div class="extra">
              <div class="ui label">
                Services
              </div>
              <div class="ui label">
                For sale
              </div>
              <div class="ui label">Central NJ</div>
              <div class="ui label">New Jersey</div>
              <div class="ui right floated primary button">
                Buy now
                <i class="right chevron icon"></i>
              </div>
            </div>
          </div>
        </div>
        <div class="item">
          <div class="ui left floated">
            7 July.
            <br>0:54
          </div>
          <div class="image">
            <a href="/vi/5870511561113600.html">
              <img src="http://lh3.googleusercontent.com/rsfBseoSy-KPg6P703Dknbpd0t2Ug4n2BY8oKkg2XH5dkufstmZXMWSCsHTU4C0yb7bIaMBpAFxILaW6W3lZsiCt=s150" title="Dentist in Westminster" alt="Dentist in Westminster">
            </a>
          </div>
          <div class="content">
            <a class="header" href="/vi/5870511561113600.html">Dentist in Westminster</a>
            <div class="meta">
              <span class="price"></span>
            </div>
            <div class="description">
              <p>Pari J. Moazed, DDS is a family dentist ...</p>
            </div>
            <div class="extra">
              <div class="ui label">
                Services
              </div>
              <div class="ui label">
                For sale
              </div>
              <div class="ui label">Baltimore</div>
              <div class="ui label">Maryland</div>
              <div class="ui right floated primary button">
                Buy now
                <i class="right chevron icon"></i>
              </div>
            </div>
          </div>
        </div>
      </div>

This "solution" works, but I don't like it

<div {% if loop.index0 == 0 %}style="margin-top:10px!important"{% endif %} class="item">

like image 462
Niklas Rosencrantz Avatar asked Jul 09 '16 05:07

Niklas Rosencrantz


People also ask

How do you set the top margin?

Syntax. The margin-top property is specified as the keyword auto , or a <length> , or a <percentage> . Its value can be positive, zero, or negative.

Which property is used to set top margin of an element?

The margin-top property in CSS is used to set the top margin of an element. It sets the margin-area on the top of the element. The default value of the margin-top property is 0.

What is default margin-top?

By default, the left and right margins of a text element are set to 0 , but they all come with a margin-top and margin-bottom .


3 Answers

By the looks of it I would personally just change the margin on the with the simple line:

.container .nav{
  margin-top:10px;
} 

Does this answer your question? (I know it looks too simple to be true)

like image 57
Rob Monhemius Avatar answered Nov 05 '22 00:11

Rob Monhemius


I would suggest adding a custom class to <ul class='nav nav-tabs'>

 <ul class="nav custom-class nav-tabs">

and adding margin-bottom to it

.custom-class{ 
    margin-bottom:20px;
 }

We are adding a custom class to unordered list <ul> so that changes made to it doesn't effect other elements which are using nav class

like image 43
Kan412 Avatar answered Nov 04 '22 22:11

Kan412


On your div.tab-content try adding class ui basic segment

like image 23
Albert Israel Avatar answered Nov 04 '22 22:11

Albert Israel